查找交易品种期货的刻度大小 Binance

Find Tick Size for a symbol Futures Binance

我试图找到特定交易品种的 tickSize(它肯定会改变),所以我用这种方式编码,但不起作用:

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)

错误:

item = correct_symbol['filters']
TypeError: string indices must be integers

执行此操作的正确方法是什么?

基于此:

https://api.binance.com/api/v3/exchangeInfo?symbol=BTCUSDT

... 这给出了这个:

{"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"]}]}

...此代码应该有效:

        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}")