I created a Python script to fetch open orders from a cryptocurrency exchange.
When i connect to the api using:
order = exchange.fetch_open_orders(symbol)
I receive this response:
[{'info': {'symbol': 'ETHBTC',
'orderId': 507325551, 'orderListId': -1, 'clientOrderId':
'web_b75c7f9be90849beac14cd86f575ac01', 'price': '0.02504200',
'origQty': '0.02100000', 'executedQty': '0.00000000',
'cummulativeQuoteQty': '0.00000000', 'status': 'NEW',
'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'SELL',
'stopPrice': '0.00000000', 'icebergQty': '0.00000000',
'time': 1571163346981, 'updateTime': 1571163346981, 'isWorking': True},
'id': '507325551', 'timestamp': 1571163346981, 'datetime': '2019-10-15T18:15:46.981Z',
'lastTradeTimestamp': None,
'symbol': 'ETH/BTC', 'type': 'limit',
'side': 'sell', 'price': 0.025042,
'amount': 0.021, 'cost': 0.0, 'average': None, 'filled': 0.0,
'remaining': 0.021, 'status': 'open', 'fee': None, 'trades': None}]
Which is a very long response and i don't want everything here, To print only some values i tried this:
for x in order:
sym = x['symbol']
price = x['price']
status = x['status']
amount = x['amount']
side = x['side']
orig = x['origQty']
print(sym, price, status, amount, side, orig)
This code works until the line orig = x['origQty'] where i get a KeyError: 'origQty'.
I don't understand where is this coming from since all the other variables are printed without any error and because origQty is in the response, whereas this error usually appears when i try to look for something that doesn't exist.
Can someone help me find what i'm doing wrong?
x["info"] ["origQty"]instead.