From 23c3673eb41a2431c8287de5b3ab606cc4ca7d0e Mon Sep 17 00:00:00 2001 From: Stan Yip Date: Mon, 12 Dec 2022 10:13:44 +0800 Subject: [PATCH 1/6] Update binance.R MARKET order amendment --- R/binance.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/binance.R b/R/binance.R index 4325bf0..583b9a2 100644 --- a/R/binance.R +++ b/R/binance.R @@ -763,7 +763,7 @@ binance_new_order <- function(symbol, side, type, time_in_force, quantity, price 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] + quot <- (quantity - filters[filterType == 'LOT_SIZE', minQty]) / filters[filterType == 'LOT_SIZE', stepSize] stopifnot(abs(quot - round(quot)) < 1e-10) if (isTRUE(filters[filterType == 'MIN_NOTIONAL', applyToMarket])) { From 64d75dd95385f3741939e01cac4add093424f777 Mon Sep 17 00:00:00 2001 From: Stan Yip Date: Tue, 21 Mar 2023 03:38:46 +0800 Subject: [PATCH 2/6] 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 583b9a2..951464e 100644 --- a/R/binance.R +++ b/R/binance.R @@ -789,16 +789,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 b4bee9d44d80d2a761c7aba4451c969fc45b005d Mon Sep 17 00:00:00 2001 From: Stan Yip Date: Thu, 23 Mar 2023 10:25:12 +0800 Subject: [PATCH 3/6] Update binance.R add "abs(quot) * .Machine$double.eps" which is approximate to the actual floating point rounding error after some arithmetic operations. (not 1e-10) --- R/binance.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/R/binance.R b/R/binance.R index 951464e..e6eadfe 100644 --- a/R/binance.R +++ b/R/binance.R @@ -757,14 +757,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)) < abs(quot) * .Machine$double.eps) 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 == 'LOT_SIZE', minQty]) / filters[filterType == 'LOT_SIZE', stepSize] - stopifnot(abs(quot - round(quot)) < 1e-10) + stopifnot(abs(quot - round(quot)) < abs(quot) * .Machine$double.eps) # it should be bounded by (|a|+|b|)/2*MachineEpsilon, but approximated by abs(quot)*MachineEpsilon if (isTRUE(filters[filterType == 'MIN_NOTIONAL', applyToMarket])) { if (filters[filterType == 'MIN_NOTIONAL', avgPriceMins] == 0) { @@ -786,7 +786,7 @@ binance_new_order <- function(symbol, side, type, time_in_force, quantity, price if (filters[filterType == 'PRICE_FILTER', tickSize] > 0) { # work around the limitation of %% (e.g. 200.1 %% 0.1 = 0.1 !!) quot <- (price - filters[filterType == 'PRICE_FILTER', minPrice]) / filters[filterType == 'PRICE_FILTER', tickSize] - stopifnot(abs(quot - round(quot)) < 1e-10) + stopifnot(abs(quot - round(quot)) < abs(quot) * .Machine$double.eps) } if (filters[filterType == 'MIN_NOTIONAL', avgPriceMins] == 0) { @@ -814,7 +814,7 @@ binance_new_order <- function(symbol, side, type, time_in_force, quantity, price if (filters[filterType == 'PRICE_FILTER', tickSize] > 0) { # work around the limitation of %% (e.g. 200.1 %% 0.1 = 0.1 !!) quot <- (stop_price - filters[filterType == 'PRICE_FILTER', minPrice]) / filters[filterType == 'PRICE_FILTER', tickSize] - stopifnot(abs(quot - round(quot)) < 1e-10) + stopifnot(abs(quot - round(quot)) < abs(quot) * .Machine$double.eps) } params$stopPrice = stop_price } @@ -827,7 +827,7 @@ binance_new_order <- function(symbol, side, type, time_in_force, quantity, price iceberg_qty <= filters[filterType == 'LOT_SIZE', maxQty]) # work around the limitation of %% (e.g. 200.1 %% 0.1 = 0.1 !!) quot <- (iceberg_qty - filters[filterType == 'LOT_SIZE', minQty]) / filters[filterType == 'LOT_SIZE', stepSize] - stopifnot(abs(quot - round(quot)) < 1e-10) + stopifnot(abs(quot - round(quot)) < abs(quot) * .Machine$double.eps) } params$icebergQty = iceberg_qty } From 9d9095837c7d10f8d5fdf07bc5ae676f5e3b9287 Mon Sep 17 00:00:00 2001 From: Stan Yip Date: Mon, 31 Jul 2023 09:13:52 +0800 Subject: [PATCH 4/6] Update binance.R applyToMarket -> applyMinToMarket --- R/binance.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/binance.R b/R/binance.R index e6eadfe..bd78174 100644 --- a/R/binance.R +++ b/R/binance.R @@ -553,7 +553,7 @@ binance_filters <- function(symbol) { symb <- symbol filters <- as.data.table(binance_exchange_info()$symbols[symbol == symb, filters][[1]]) - for (v in setdiff(names(filters), c('filterType', 'avgPriceMins', 'applyToMarket', 'limit', 'maxNumAlgoOrders'))) { + for (v in setdiff(names(filters), c('filterType', 'avgPriceMins', 'applyMinToMarket', 'limit', 'maxNumAlgoOrders'))) { filters[, (v) := as.numeric(get(v))] } @@ -720,7 +720,7 @@ binance_mytrades <- function(symbol, limit, from_id, start_time, end_time) { binance_new_order <- function(symbol, side, type, time_in_force, quantity, price, stop_price, iceberg_qty, test = TRUE) { # silence "no visible global function/variable definition" R CMD check - filterType <- minQty <- maxQty <- stepSize <- applyToMarket <- avgPriceMins <- limit <- NULL + filterType <- minQty <- maxQty <- stepSize <- applyMinToMarket <- avgPriceMins <- limit <- NULL minNotional <- minPrice <- maxPrice <- tickSize <- multiplierDown <- multiplierUp <- NULL side <- match.arg(side) @@ -766,7 +766,7 @@ binance_new_order <- function(symbol, side, type, time_in_force, quantity, price quot <- (quantity - filters[filterType == 'LOT_SIZE', minQty]) / filters[filterType == 'LOT_SIZE', stepSize] stopifnot(abs(quot - round(quot)) < abs(quot) * .Machine$double.eps) # it should be bounded by (|a|+|b|)/2*MachineEpsilon, but approximated by abs(quot)*MachineEpsilon - if (isTRUE(filters[filterType == 'MIN_NOTIONAL', applyToMarket])) { + if (isTRUE(filters[filterType == 'MIN_NOTIONAL', applyMinToMarket])) { if (filters[filterType == 'MIN_NOTIONAL', avgPriceMins] == 0) { ref_price <- binance_ticker_price(symbol)$price } else { From 53427d79b202aa2428e95e1852e34c4d572b83b6 Mon Sep 17 00:00:00 2001 From: Stan Yip Date: Mon, 31 Jul 2023 09:50:47 +0800 Subject: [PATCH 5/6] Update DESCRIPTION just an update on version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 07bf9bf..bbe7634 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: binancer Type: Package Title: API Client to 'Binance' -Version: 1.2.0 -Date: 2021-11-26 +Version: 1.2.1 +Date: 2023-07-31 Authors@R: c( person('Gergely', 'Daróczi', email = 'daroczig@rapporter.net', role = c('aut', 'cre')), person('David', 'Andel', email = 'andel@bli.uzh.ch', role = 'aut')) From 7faa6eb9c4484863ba242ac5e104712f11c02bf7 Mon Sep 17 00:00:00 2001 From: Stan Yip Date: Tue, 19 Sep 2023 01:09:37 +0800 Subject: [PATCH 6/6] Update binance.R update limit order --- R/binance.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/binance.R b/R/binance.R index bd78174..0582981 100644 --- a/R/binance.R +++ b/R/binance.R @@ -789,11 +789,11 @@ binance_new_order <- function(symbol, side, type, time_in_force, quantity, price stopifnot(abs(quot - round(quot)) < abs(quot) * .Machine$double.eps) } - 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( @@ -801,7 +801,7 @@ binance_new_order <- function(symbol, side, type, time_in_force, quantity, price 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 }