From c0be50e24eb7ee8d232c2ee63e7f2e622574da7e Mon Sep 17 00:00:00 2001 From: sercanpekel <38354913+sercanpekel@users.noreply.github.com> Date: Tue, 8 Feb 2022 23:32:39 +0300 Subject: [PATCH 01/15] Update binance.R --- R/binance.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/binance.R b/R/binance.R index b7c2a41..7d8408e 100644 --- a/R/binance.R +++ b/R/binance.R @@ -1,7 +1,7 @@ BINANCE <- list( BASE = list( SPOT = 'https://api.binance.com', - USDM = 'https://fapi.binance.com' + USDM = 'https://dapi.binance.com' ), SPOT = list( TIMEINFORCE = c('GTC', 'IOC', 'FOK'), From 0ca4a9c28834a886806172b2cf77558076d17204 Mon Sep 17 00:00:00 2001 From: sercanpekel <38354913+sercanpekel@users.noreply.github.com> Date: Tue, 15 Feb 2022 15:01:35 +0300 Subject: [PATCH 02/15] Update usdm.R --- R/usdm.R | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/R/usdm.R b/R/usdm.R index 3c9a217..8af1f24 100644 --- a/R/usdm.R +++ b/R/usdm.R @@ -10,7 +10,7 @@ usdm_query <- function(endpoint, ...) { #' @export #' @return "OK" string on success usdm_v1_ping <- function() { - res <- usdm_query("/fapi/v1/ping") + res <- usdm_query("/dapi/v1/ping") if (is.list(res) & length(res) == 0) { res <- "OK" } @@ -21,7 +21,7 @@ usdm_v1_ping <- function() { #' @export #' @return \code{POSIXct} usdm_v1_time <- function() { - res <- usdm_query("/fapi/v1/time")$serverTime + res <- usdm_query("/dapi/v1/time")$serverTime res <- as_timestamp(res / 1e3) res } @@ -31,7 +31,7 @@ usdm_v1_time <- function() { #' @export #' @importFrom jsonlite fromJSON usdm_v1_exchange_info <- function() { - res <- usdm_query("/fapi/v1/exchangeInfo", content_as = "text") + res <- usdm_query("/dapi/v1/exchangeInfo", content_as = "text") res <- fromJSON(res) res$serverTime <- as_timestamp(res$serverTime / 1e3) res$rateLimits <- as.data.table(res$rateLimits) @@ -76,7 +76,7 @@ usdm_v1_premium_index <- function(symbol) { params$symbol <- symbol } - res <- usdm_query("/fapi/v1/premiumIndex", params = params) + res <- usdm_query("/dapi/v1/premiumIndex", params = params) if (missing(symbol)) { res <- rbindlist(res) @@ -123,7 +123,7 @@ usdm_v1_new_order <- function(symbol, ) order <- usdm_query( - "/fapi/v1/order", + "/dapi/v1/order", method = "POST", params = params, sign = TRUE @@ -148,7 +148,7 @@ usdm_v1_open_orders <- function(symbol) { } order <- usdm_query( - "/fapi/v1/openOrders", + "/dapi/v1/openOrders", params = params, sign = TRUE ) @@ -169,7 +169,7 @@ usdm_v2_position_risks <- function(symbol) { rbindlist( usdm_query( - "/fapi/v2/positionRisk", + "/dapi/v2/positionRisk", params = params, sign = TRUE ) @@ -198,7 +198,7 @@ convert_position_risks <- function(positions) { #' @return list #' @export usdm_v2_account <- function() { - account <- usdm_query("/fapi/v2/account", sign = TRUE) + account <- usdm_query("/dapi/v2/account", sign = TRUE) account$assets <- rbindlist(account$assets) account$positions <- rbindlist(account$positions) account @@ -216,7 +216,7 @@ usdm_v1_change_initial_leverage <- function(symbol, leverage) { ) usdm_query( - "/fapi/v1/leverage", + "/dapi/v1/leverage", method = "POST", params = params, sign = TRUE @@ -236,7 +236,7 @@ usdm_v1_change_margin_type <- function(symbol, ) usdm_query( - "/fapi/v1/marginType", + "/dapi/v1/marginType", method = "POST", params = params, sign = TRUE @@ -255,7 +255,7 @@ usdm_v1_cancel_order_by_id <- function(symbol, order_id) { ) order <- usdm_query( - "/fapi/v1/order", + "/dapi/v1/order", method = "DELETE", params = params, sign = TRUE @@ -276,7 +276,7 @@ usdm_v1_cancel_order_by_client_order_id <- function(symbol, client_order_id) { ) order <- usdm_query( - "/fapi/v1/order", + "/dapi/v1/order", method = "DELETE", params = params, sign = TRUE From 28a5d12ca2a646124c98a222e1b5061c1d75fe50 Mon Sep 17 00:00:00 2001 From: sercanpekel <38354913+sercanpekel@users.noreply.github.com> Date: Wed, 16 Feb 2022 10:53:51 +0300 Subject: [PATCH 03/15] Update binance.R --- R/binance.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/binance.R b/R/binance.R index 7d8408e..19adeed 100644 --- a/R/binance.R +++ b/R/binance.R @@ -15,7 +15,7 @@ BINANCE <- list( "MAX_NUM_ORDERS", "MAX_NUM_ALGO_ORDERS", "MIN_NOTIONAL", "PERCENT_PRICE"), TIMEINFORCE = c('GTC', 'IOC', 'FOK', 'GTX'), - POSITION_SIDE = c('LONG', 'SHORT'), + POSITION_SIDE = c('BOTH', 'LONG', 'SHORT'), TYPE = c('LIMIT', 'MARKET', 'STOP', 'STOP_MARKET', 'TAKE_PROFIT', 'TAKE_PROFIT_MARKET', From e2ee91a7387c84722ed600dbe6573af526e58746 Mon Sep 17 00:00:00 2001 From: Sercan Pekel <38354913+sercanpekel@users.noreply.github.com> Date: Sun, 15 May 2022 14:10:50 +0300 Subject: [PATCH 04/15] Update binance.R --- R/binance.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/binance.R b/R/binance.R index 19adeed..54e957c 100644 --- a/R/binance.R +++ b/R/binance.R @@ -798,14 +798,14 @@ binance_new_order <- function(symbol, side, type, time_in_force, quantity, price quantity <= filters[filterType == 'LOT_SIZE', maxQty]) # work around the limitation of %% (e.g. 200.1 %% 0.1 = 0.1 !!) quot <- (quantity - filters[filterType == 'LOT_SIZE', minQty]) / filters[filterType == 'LOT_SIZE', stepSize] - stopifnot(abs(quot - round(quot)) < 1e-10) + stopifnot(abs(quot - round(quot)) < 1) if (type == 'MARKET') { stopifnot(quantity >= filters[filterType == 'MARKET_LOT_SIZE', minQty], quantity <= filters[filterType == 'MARKET_LOT_SIZE', maxQty]) # work around the limitation of %% (e.g. 200.1 %% 0.1 = 0.1 !!) quot <- (quantity - filters[filterType == 'MARKET_LOT_SIZE', minQty]) / filters[filterType == 'MARKET_LOT_SIZE', stepSize] - stopifnot(abs(quot - round(quot)) < 1e-10) + stopifnot(abs(quot - round(quot)) < 1) if (isTRUE(filters[filterType == 'MIN_NOTIONAL', applyToMarket])) { if (filters[filterType == 'MIN_NOTIONAL', avgPriceMins] == 0) { From 2fca580cc676fdbf9128a4474826ed01cf97fcb7 Mon Sep 17 00:00:00 2001 From: Sercan Pekel <38354913+sercanpekel@users.noreply.github.com> Date: Fri, 4 Nov 2022 23:47:52 +0300 Subject: [PATCH 05/15] Update usdm.R --- R/usdm.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/R/usdm.R b/R/usdm.R index 8af1f24..0443f09 100644 --- a/R/usdm.R +++ b/R/usdm.R @@ -176,6 +176,22 @@ usdm_v2_position_risks <- function(symbol) { ) } +# Trade list (sp) +usdm_v1_trades <- function(symbol) { + params <- list() + + if (!missing(symbol)) { + params$symbol <- symbol + } + + rbindlist( + usdm_query( + "/dapi/v1/userTrades", + sign = TRUE + ) + ) +} + #' Convert columns of positions into numeric. #' @param positions data.table #' @return data.table From d706b56b56cf5e23c10e25e77e0cb6d4f74fff5e Mon Sep 17 00:00:00 2001 From: Sercan Pekel <38354913+sercanpekel@users.noreply.github.com> Date: Fri, 4 Nov 2022 23:56:07 +0300 Subject: [PATCH 06/15] Update usdm.R --- R/usdm.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/usdm.R b/R/usdm.R index 0443f09..7367b4c 100644 --- a/R/usdm.R +++ b/R/usdm.R @@ -176,7 +176,8 @@ usdm_v2_position_risks <- function(symbol) { ) } -# Trade list (sp) +#' Trade list (sp) +#' @export usdm_v1_trades <- function(symbol) { params <- list() From 5e21b86c4e7122dc497196735faa260f784fd46b Mon Sep 17 00:00:00 2001 From: Sercan Pekel <38354913+sercanpekel@users.noreply.github.com> Date: Sat, 5 Nov 2022 00:01:54 +0300 Subject: [PATCH 07/15] Update usdm.R --- R/usdm.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/usdm.R b/R/usdm.R index 7367b4c..bdafd99 100644 --- a/R/usdm.R +++ b/R/usdm.R @@ -177,6 +177,7 @@ usdm_v2_position_risks <- function(symbol) { } #' Trade list (sp) +#' @return data.table #' @export usdm_v1_trades <- function(symbol) { params <- list() From a48b0faa2c5e14a06dc1a7669617ee7846681b6a Mon Sep 17 00:00:00 2001 From: Sercan Pekel <38354913+sercanpekel@users.noreply.github.com> Date: Sun, 6 Nov 2022 09:04:07 +0300 Subject: [PATCH 08/15] Update NAMESPACE --- NAMESPACE | 1 + 1 file changed, 1 insertion(+) diff --git a/NAMESPACE b/NAMESPACE index 0effde8..a10ad87 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -61,6 +61,7 @@ export(usdm_v1_premium_index) export(usdm_v1_time) export(usdm_v2_account) export(usdm_v2_position_risks) +export(usdm_v1_trades) importFrom(assertive,assert_is_numeric) importFrom(data.table,"%chin%") importFrom(data.table,":=") From 4f2cde5a114ac243e2bd7518c6dd27888ff54931 Mon Sep 17 00:00:00 2001 From: Sercan Pekel <38354913+sercanpekel@users.noreply.github.com> Date: Sun, 21 May 2023 20:15:43 +0300 Subject: [PATCH 09/15] Update binance.R --- R/binance.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/binance.R b/R/binance.R index 54e957c..4f592f5 100644 --- a/R/binance.R +++ b/R/binance.R @@ -830,16 +830,16 @@ binance_new_order <- function(symbol, side, type, time_in_force, quantity, price stopifnot(abs(quot - round(quot)) < 1e-10) } - if (filters[filterType == 'PERCENT_PRICE', avgPriceMins] == 0) { +if (filters[filterType == 'MIN_NOTIONAL', avgPriceMins] == 0) { ref_price <- binance_ticker_price(symbol)$price } else { ref_price <- binance_avg_price(symbol) - stopifnot(ref_price$mins == filters[filterType == 'PERCENT_PRICE', avgPriceMins]) +stopifnot(ref_price$mins == filters[filterType == 'MIN_NOTIONAL', avgPriceMins]) ref_price <- ref_price$price } stopifnot( - price >= ref_price * filters[filterType == 'PERCENT_PRICE', multiplierDown], - price <= ref_price * filters[filterType == 'PERCENT_PRICE', multiplierUp] + price >= ref_price * filters[filterType == 'PERCENT_PRICE_BY_SIDE', 'askMultiplierDown'], + price <= ref_price * filters[filterType == 'PERCENT_PRICE_BY_SIDE', 'askMultiplierUp'] ) stopifnot(price * quantity >= filters[filterType == 'MIN_NOTIONAL', minNotional]) From 4e59e2b2b22e7005c6a51bc56b2a25a22285da45 Mon Sep 17 00:00:00 2001 From: Sercan Pekel <38354913+sercanpekel@users.noreply.github.com> Date: Sun, 21 May 2023 20:42:47 +0300 Subject: [PATCH 10/15] Update binance.R --- R/binance.R | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/R/binance.R b/R/binance.R index 4f592f5..9e25500 100644 --- a/R/binance.R +++ b/R/binance.R @@ -807,15 +807,15 @@ binance_new_order <- function(symbol, side, type, time_in_force, quantity, price quot <- (quantity - filters[filterType == 'MARKET_LOT_SIZE', minQty]) / filters[filterType == 'MARKET_LOT_SIZE', stepSize] stopifnot(abs(quot - round(quot)) < 1) - if (isTRUE(filters[filterType == 'MIN_NOTIONAL', applyToMarket])) { - if (filters[filterType == 'MIN_NOTIONAL', avgPriceMins] == 0) { + if (isTRUE(filters[filterType == 'NOTIONAL', applyToMarket])) { + if (filters[filterType == 'NOTIONAL', avgPriceMins] == 0) { ref_price <- binance_ticker_price(symbol)$price } else { ref_price <- binance_avg_price(symbol) - stopifnot(ref_price$mins == filters[filterType == 'MIN_NOTIONAL', avgPriceMins]) + stopifnot(ref_price$mins == filters[filterType == 'NOTIONAL', avgPriceMins]) ref_price <- ref_price$price } - stopifnot(ref_price * quantity >= filters[filterType == 'MIN_NOTIONAL', minNotional]) + stopifnot(ref_price * quantity >= filters[filterType == 'NOTIONAL', minNotional]) } } @@ -830,11 +830,11 @@ binance_new_order <- function(symbol, side, type, time_in_force, quantity, price stopifnot(abs(quot - round(quot)) < 1e-10) } -if (filters[filterType == 'MIN_NOTIONAL', avgPriceMins] == 0) { +if (filters[filterType == 'NOTIONAL', avgPriceMins] == 0) { ref_price <- binance_ticker_price(symbol)$price } else { ref_price <- binance_avg_price(symbol) -stopifnot(ref_price$mins == filters[filterType == 'MIN_NOTIONAL', avgPriceMins]) +stopifnot(ref_price$mins == filters[filterType == 'NOTIONAL', avgPriceMins]) ref_price <- ref_price$price } stopifnot( @@ -842,7 +842,7 @@ stopifnot(ref_price$mins == filters[filterType == 'MIN_NOTIONAL', avgPriceMins]) price <= ref_price * filters[filterType == 'PERCENT_PRICE_BY_SIDE', 'askMultiplierUp'] ) - stopifnot(price * quantity >= filters[filterType == 'MIN_NOTIONAL', minNotional]) + stopifnot(price * quantity >= filters[filterType == 'NOTIONAL', minNotional]) params$price = price } From b082a2828b7a4d99a57c8bbd0b0cdb7e2263f5f3 Mon Sep 17 00:00:00 2001 From: Sercan Pekel <38354913+sercanpekel@users.noreply.github.com> Date: Wed, 23 Oct 2024 19:28:34 +0100 Subject: [PATCH 11/15] Update usdm.R --- R/usdm.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/usdm.R b/R/usdm.R index bdafd99..b6c2c04 100644 --- a/R/usdm.R +++ b/R/usdm.R @@ -10,7 +10,7 @@ usdm_query <- function(endpoint, ...) { #' @export #' @return "OK" string on success usdm_v1_ping <- function() { - res <- usdm_query("/dapi/v1/ping") + res <- usdm_query("/papi/v1/ping") if (is.list(res) & length(res) == 0) { res <- "OK" } @@ -31,7 +31,7 @@ usdm_v1_time <- function() { #' @export #' @importFrom jsonlite fromJSON usdm_v1_exchange_info <- function() { - res <- usdm_query("/dapi/v1/exchangeInfo", content_as = "text") + res <- usdm_query("/papi/v1/exchangeInfo", content_as = "text") res <- fromJSON(res) res$serverTime <- as_timestamp(res$serverTime / 1e3) res$rateLimits <- as.data.table(res$rateLimits) @@ -122,8 +122,8 @@ usdm_v1_new_order <- function(symbol, ... ) - order <- usdm_query( - "/dapi/v1/order", + order <- usdm_query( + "/papi/v1/cm/order", method = "POST", params = params, sign = TRUE @@ -148,7 +148,7 @@ usdm_v1_open_orders <- function(symbol) { } order <- usdm_query( - "/dapi/v1/openOrders", + "/papi/v1/cm/openOrders", params = params, sign = TRUE ) @@ -188,7 +188,7 @@ usdm_v1_trades <- function(symbol) { rbindlist( usdm_query( - "/dapi/v1/userTrades", + "/papi/v1/cm/userTrades", sign = TRUE ) ) From c14ea175bb9878bba64a5f7cdbad91333d4667eb Mon Sep 17 00:00:00 2001 From: Sercan Pekel <38354913+sercanpekel@users.noreply.github.com> Date: Wed, 23 Oct 2024 19:40:54 +0100 Subject: [PATCH 12/15] Update binance.R --- R/binance.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/binance.R b/R/binance.R index 9e25500..e7e3ff1 100644 --- a/R/binance.R +++ b/R/binance.R @@ -1,7 +1,7 @@ BINANCE <- list( BASE = list( SPOT = 'https://api.binance.com', - USDM = 'https://dapi.binance.com' + USDM = 'https://papi.binance.com' ), SPOT = list( TIMEINFORCE = c('GTC', 'IOC', 'FOK'), From 773e7be77dfb659342618c4b17074d5e9134cd37 Mon Sep 17 00:00:00 2001 From: Sercan Pekel <38354913+sercanpekel@users.noreply.github.com> Date: Wed, 1 Oct 2025 14:39:32 +0100 Subject: [PATCH 13/15] Update usdm.R Added UM order function Added UM open orders function. --- R/usdm.R | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/R/usdm.R b/R/usdm.R index b6c2c04..3c34587 100644 --- a/R/usdm.R +++ b/R/usdm.R @@ -97,7 +97,7 @@ usdm_v1_premium_index <- function(symbol) { res[, time := as_timestamp(time)] } -#' Open new order on the Binance USDM account +#' Open new order on the Binance Coin-m account #' #' This function serves as a low level entry for order classes. #' Do not use it directly. @@ -132,7 +132,42 @@ usdm_v1_new_order <- function(symbol, as.data.table(order) } -#' Get all open orders of a symbol on USDM. +#' Open new order on the Binance USDM account +#' +#' This function serves as a low level entry for order classes. +#' Do not use it directly. +#' +#' @param symbol string +#' @param side enum +#' @param position_side enum +#' @param type enum +#' @param ... list +#' @return data.table +#' @export +usdm_um_new_order <- function(symbol, + side = BINANCE$SIDE, + position_side = BINANCE$USDM$POSITION_SIDE, + type = BINANCE$USDM$TYPE, + ...) { + params <- list( + symbol = symbol, + side = match.arg(side), + positionSide = match.arg(position_side), + type = match.arg(type), + ... + ) + + order <- usdm_query( + "/papi/v1/um/order", + method = "POST", + params = params, + sign = TRUE + ) + + as.data.table(order) +} + +#' Get all open orders of a symbol on Coin-M. #' #' Get all open orders on a symbol. Careful when accessing this with no symbol. #' Weight: 1 for a single symbol; 40 when the symbol parameter is omitted. @@ -156,6 +191,31 @@ usdm_v1_open_orders <- function(symbol) { rbindlist(order) } +#' Get all open orders of a symbol on USDM. +#' +#' Get all open orders on a symbol. Careful when accessing this with no symbol. +#' Weight: 1 for a single symbol; 40 when the symbol parameter is omitted. +#' +#' @param symbol optional string +#' @return data.table +#' @export +usdm_um_open_orders <- function(symbol) { + params <- list() + + if (!missing(symbol)) { + params$symbol <- symbol + } + + order <- usdm_query( + "/papi/v1/um/openOrders", + params = params, + sign = TRUE + ) + + rbindlist(order) +} + + #' Get positions of a symbol or all symbols on USDM. #' @param symbol optional string #' @return data.table From a9b67b58ee99101dc80dcd547aadb1676d46f028 Mon Sep 17 00:00:00 2001 From: Sercan Pekel <38354913+sercanpekel@users.noreply.github.com> Date: Wed, 1 Oct 2025 14:41:12 +0100 Subject: [PATCH 14/15] Update usdm.R Added UM trades function. --- R/usdm.R | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/R/usdm.R b/R/usdm.R index 3c34587..1ee9631 100644 --- a/R/usdm.R +++ b/R/usdm.R @@ -254,6 +254,24 @@ usdm_v1_trades <- function(symbol) { ) } +#' Trade list USDM (sp) +#' @return data.table +#' @export +usdm_um_trades <- function(symbol) { + params <- list() + + if (!missing(symbol)) { + params$symbol <- symbol + } + + rbindlist( + usdm_query( + "/papi/v1/um/userTrades", + sign = TRUE + ) + ) +} + #' Convert columns of positions into numeric. #' @param positions data.table #' @return data.table From edafd4881f757a2ac8f28da3b495d073ba938cc4 Mon Sep 17 00:00:00 2001 From: Sercan Pekel <38354913+sercanpekel@users.noreply.github.com> Date: Wed, 8 Oct 2025 14:37:07 +0100 Subject: [PATCH 15/15] Update NAMESPACE Added the usdm_um new functions. --- NAMESPACE | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index a10ad87..9610de3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -62,6 +62,9 @@ export(usdm_v1_time) export(usdm_v2_account) export(usdm_v2_position_risks) export(usdm_v1_trades) +export(usdm_um_trades) +export(usdm_um_new_order) +export(usdm_um_open_orders) importFrom(assertive,assert_is_numeric) importFrom(data.table,"%chin%") importFrom(data.table,":=")