Search code examples
pythonlistdictionarybinance-api-client

Trying to access a value pair which is in a dictionary inside a list of dictionaries and that list is inside a dictionary


I have a function gathering some binance API data

from binance.client import Client
client = Client(apikey, apisecret)

d = client.get_symbol_info(symbol)

print(d)

Output:

{'symbol': 'VGXUSDT', 'status': 'TRADING', 'filters': [{'filterType': 'PRICE_FILTER', 'minPrice': '0.00100000'}, {'filterType': 'LOT_SIZE', 'minQty': '0.10000000', 'maxQty': '92141578.00000000', 'stepSize': '0.10000000'}]}

I am trying to access the stepSize value and return it as a float.

I have tried loops, list comprehension, and list comprehension inside a loop.


Solution

  • This is dictionary inside of array inside of dictionary (JSON response). So to access you need to use keys:

    def precision(symbol)
    
        info = client.get_symbol_info(symbol)
        return float(info['filters'][1]['stepSize'])