Search code examples
pythonbinancebinance-api-client

Find tickSize Binance


I'm trying to find tickSize using this method but it returns an error.

Data:

{'symbol': 'FIROUSDT', 'status': 'TRADING', 'baseAsset': 'FIRO', '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': False, 'isSpotTradingAllowed': True, 'isMarginTradingAllowed': False, 'filters': [{'filterType': 'PRICE_FILTER', 'minPrice': '0.00100000', 'maxPrice': '10000.00000000', 'tickSize': '0.00100000'}, {'filterType': 'PERCENT_PRICE', 'multiplierUp': '5', 'multiplierDown': '0.2', 'avgPriceMins': 5}, {'filterType': 'LOT_SIZE', 'minQty': '0.10000000', 'maxQty': '90000.00000000', 'stepSize': '0.10000000'}, {'filterType': 'MIN_NOTIONAL', 'minNotional': '10.00000000', 'applyToMarket': True, 'avgPriceMins': 5}, {'filterType': 'ICEBERG_PARTS', 'limit': 10}, {'filterType': 'MARKET_LOT_SIZE', 'minQty': '0.00000000', 'maxQty': '26259.97721527', 'stepSize': '0.00000000'}, {'filterType': 'MAX_NUM_ORDERS', 'maxNumOrders': 200}, {'filterType': 'MAX_NUM_ALGO_ORDERS', 'maxNumAlgoOrders': 5}], 'permissions': ['SPOT']}

Code:

data = client.get_symbol_info('FIROUSDT')
print(data['filters']['filterType']['PRICE_FILTER']['tickSize'])

Error:

print(data['filters']['filterType']['PRICE_FILTER']['tickSize'])
TypeError: list indices must be integers or slices, not str

What's the mistake here?


Solution

  • data["filters"] returns a List, not a Dictionary, so to access the "PRICE_FILTER" we need to use the index of this filter.

    [
      {
        "filterType": "PRICE_FILTER",
        "minPrice": "0.00100000",
        "maxPrice": "10000.00000000",
        "tickSize": "0.00100000"
      },
      {
        "filterType": "PERCENT_PRICE",
        "multiplierUp": "5",
        "multiplierDown": "0.2",
        "avgPriceMins": 5
      },
      {
        "filterType": "LOT_SIZE",
        "minQty": "0.10000000",
        "maxQty": "90000.00000000",
        "stepSize": "0.10000000"
      },
      {
        "filterType": "MIN_NOTIONAL",
        "minNotional": "10.00000000",
        "applyToMarket": true,
        "avgPriceMins": 5
      },
      {
        "filterType": "ICEBERG_PARTS",
        "limit": 10
      },
      {
        "filterType": "MARKET_LOT_SIZE",
        "minQty": "0.00000000",
        "maxQty": "26259.97721527",
        "stepSize": "0.00000000"
      },
      {
        "filterType": "MAX_NUM_ORDERS",
        "maxNumOrders": 200
      },
      {
        "filterType": "MAX_NUM_ALGO_ORDERS",
        "maxNumAlgoOrders": 5
      }
    ]
    

    The first filter has a filterType of "PRICE_FILTER" so our index is 0 because Python uses 0-based indexing, so to get this filter we use

    data["filters"][0]
    

    This returns the following dictionary

    {
      "filterType": "PRICE_FILTER",
      "minPrice": "0.00100000",
      "maxPrice": "10000.00000000",
      "tickSize": "0.00100000"
    }
    

    So to print the tickSize you can run

    print(data['filters'][0]['tickSize'])