Skip to content

Commit

Permalink
fix for step_size
Browse files Browse the repository at this point in the history
the bot is returning the wrong step_size value.
some background, in 0.0.177 -> 178 the step_size function started
failing as binance returned the step_size in a different element of the
filters array. As a change in 178, the step_size was calculated by
merging all the dictionaries available in the filters array. However
there are some filters that also contain a key named stepSize. This
resulted in the stepSize being overwritten by another later key with
that same name and the function returned that value instead.

We now check if the dictionary in the array is the correct filter that
we want to check and retrieve the stepSize from that filter.
  • Loading branch information
Azulinho committed Dec 31, 2022
1 parent 4ce2323 commit 97b075d
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,10 +973,10 @@ def get_step_size(self, symbol: str) -> str:
logging.error(error_msg)
return str(-1)

result: dict = {}
for d in info["filters"]:
result.update(d)
step_size = result["stepSize"]
if "filterType" in d.keys():
if d["filterType"] == "LOT_SIZE":
step_size = d["stepSize"]

if self.mode == "backtesting" and not exists(f_path):
with open(f_path, "w") as f:
Expand Down
78 changes: 77 additions & 1 deletion tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,83 @@ def test_get_step_size(self, bot):
"get_symbol_info",
return_value={
"symbol": "BTCUSDT",
"filters": [{}, {}, {"stepSize": "0.00001000"}],
"status": "TRADING",
"baseAsset": "BTC",
"baseAssetPrecision": 8,
"quoteAsset": "USDT",
"quotePrecision": 8,
"quoteAssetPrecision": 8,
"baseCommissionPrecision": 8,
"quoteCommissionPrecision": 8,
"orderTypes": [
"LIMIT",
"LIMIT_MAKER",
"MARKET",
"STOP_LOSS_LIMIT",
"TAKE_PROFIT_LIMIT",
],
"icebergAllowed": "true",
"ocoAllowed": "true",
"quoteOrderQtyMarketAllowed": "true",
"allowTrailingStop": "true",
"cancelReplaceAllowed": "true",
"isSpotTradingAllowed": "true",
"isMarginTradingAllowed": "true",
"filters": [
{
"filterType": "PRICE_FILTER",
"minPrice": "0.10000000",
"maxPrice": "100000.00000000",
"tickSize": "0.10000000",
},
{
"filterType": "LOT_SIZE",
"minQty": "0.00100000",
"maxQty": "900000.00000000",
"stepSize": "0.00001000",
},
{
"filterType": "MIN_NOTIONAL",
"minNotional": "10.00000000",
"applyToMarket": "true",
"avgPriceMins": 5,
},
{"filterType": "ICEBERG_PARTS", "limit": 10},
{
"filterType": "MARKET_LOT_SIZE",
"minQty": "0.00000000",
"maxQty": "15943.07122777",
"stepSize": "0.00000000",
},
{
"filterType": "TRAILING_DELTA",
"minTrailingAboveDelta": 10,
"maxTrailingAboveDelta": 2000,
"minTrailingBelowDelta": 10,
"maxTrailingBelowDelta": 2000,
},
{
"filterType": "PERCENT_PRICE_BY_SIDE",
"bidMultiplierUp": "5",
"bidMultiplierDown": "0.2",
"askMultiplierUp": "5",
"askMultiplierDown": "0.2",
"avgPriceMins": 5,
},
{"filterType": "MAX_NUM_ORDERS", "maxNumOrders": 200},
{
"filterType": "MAX_NUM_ALGO_ORDERS",
"maxNumAlgoOrders": 5,
},
],
"permissions": [
"SPOT",
"MARGIN",
"TRD_GRP_004",
"TRD_GRP_005",
],
"defaultSelfTradePreventionMode": "NONE",
"allowedSelfTradePreventionModes": ["NONE"],
},
) as _:
result = bot.get_step_size("BTCUSDT")
Expand Down

0 comments on commit 97b075d

Please sign in to comment.