Reputation: 323
I'm trying to find the tickSize for a specific symbol (which is bound to change), so I coded it this way, but doesn't work:
data = client.futures_exchange_info()
tick_size = 0.0
the_symbol = "BTCUSDT"
info = data['symbols']
for f in range(len(info)):
if info[f]['symbol'] == the_symbol:
correct_symbol = info[f]['symbol']
item = correct_symbol['filters']
if item['filterType'] == 'PRICE_FILTER':
tick_size = float(item['tickSize'])
print(tick_size)
Error:
item = correct_symbol['filters']
TypeError: string indices must be integers
What's the proper way to do this?
Upvotes: 1
Views: 1589
Reputation: 9379
Based on this:
https://api.binance.com/api/v3/exchangeInfo?symbol=BTCUSDT
... which gives this:
{"timezone":"UTC","serverTime":1645666341842,"rateLimits":[{"rateLimitType":"REQUEST_WEIGHT","interval":"MINUTE","intervalNum":1,"limit":1200},{"rateLimitType":"ORDERS","interval":"SECOND","intervalNum":10,"limit":50},{"rateLimitType":"ORDERS","interval":"DAY","intervalNum":1,"limit":160000},{"rateLimitType":"RAW_REQUESTS","interval":"MINUTE","intervalNum":5,"limit":6100}],"exchangeFilters":[],"symbols":[{"symbol":"BTCUSDT","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,"isSpotTradingAllowed":true,"isMarginTradingAllowed":true,"filters":[{"filterType":"PRICE_FILTER","minPrice":"0.01000000","maxPrice":"1000000.00000000","tickSize":"0.01000000"},{"filterType":"PERCENT_PRICE","multiplierUp":"5","multiplierDown":"0.2","avgPriceMins":5},{"filterType":"LOT_SIZE","minQty":"0.00001000","maxQty":"9000.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":"178.05293892","stepSize":"0.00000000"},{"filterType":"MAX_NUM_ORDERS","maxNumOrders":200},{"filterType":"MAX_NUM_ALGO_ORDERS","maxNumAlgoOrders":5}],"permissions":["SPOT","MARGIN"]}]}
... this code should work:
tick_size = 0.0
the_symbol = "BTCUSDT"
found = False
info = data['symbols']
for s in range(len(info)):
if info[s]['symbol'] == the_symbol:
filters = info[s]['filters']
for f in range(len(filters)):
if filters[f]['filterType'] == 'PRICE_FILTER':
tick_size = float(filters[f]['tickSize'])
found = True
break
break
if found:
print(tick_size)
else:
print(f"tick_size not found for {the_symbol}")
Upvotes: 3