Hi everyone :) I am a bit of a newbie when it comes to JSON & Python, working on a new project today and would really appreciate some help. This is what I have so far. I aiming to interact with the Binance API in a few different ways.
url = 'https://api.binance.com/'
urlWithSymbol = 'https://api.binance.com/api/v1/trades?symbol='
def getRecentTrades(symbol):
response = requests.get(urlWithSymbol+symbol+'&limit=10')
# Print the content of the response (the data the server returned)
print(response.content.decode("utf-8"))
data = response.json()
print(type(data))
print(data)
getRecentTrades('NPXSBTC')
Everything works fine here, only the response is given to me in the form of a dictionary, and I would like to be able to individually access 'Bids', etc. What do you guys think is the next step here? Do I turn Data into a JSON Object?
Response:
{'asks': [['0.00000024', '109846420.00000000', []],
['0.00000025', '114178637.00000000', []],
['0.00000026', '82322155.00000000', []],
['0.00000027', '92902459.00000000', []],
['0.00000028', '44228198.00000000', []],
['0.00000029', '56824640.00000000', []],
['0.00000030', '111613234.00000000', []],
['0.00000031', '43773659.00000000', []],
['0.00000032', '80669915.00000000', []],
['0.00000033', '82725221.00000000', []]],
'bids': [['0.00000023', '155213182.00000000', []],
['0.00000022', '191986504.00000000', []],
['0.00000021', '118013185.00000000', []],
['0.00000020', '168162758.00000000', []],
['0.00000019', '64558205.00000000', []],
['0.00000018', '63484191.00000000', []],
['0.00000017', '31635740.00000000', []],
['0.00000016', '39788788.00000000', []],
['0.00000015', '41020041.00000000', []],
['0.00000014', '16370913.00000000', []]],
'lastUpdateId': 5532550}
Printed output:
<class 'list'>
[{'id': 1116367, 'price': '0.00000024', 'qty': '35542.00000000', 'time': 1534169839810, 'isBuyerMaker': False, 'isBestMatch': True}, {'id': 1116368, 'price': '0.00000023', 'qty': '400000.00000000', 'time': 1534169854271, 'isBuyerMaker': True, 'isBestMatch': True}, {'id': 1116369, 'price': '0.00000023', 'qty': '15542.00000000', 'time': 1534169991106, 'isBuyerMaker': True, 'isBestMatch': True}, {'id': 1116370, 'price': '0.00000024', 'qty': '1.00000000', 'time': 1534170015730, 'isBuyerMaker': False, 'isBestMatch': True}, {'id': 1116371, 'price': '0.00000023', 'qty': '19061.00000000', 'time': 1534170017669, 'isBuyerMaker': True, 'isBestMatch': True}, {'id': 1116372, 'price': '0.00000023', 'qty': '39.00000000', 'time': 1534170041722, 'isBuyerMaker': True, 'isBestMatch': True}, {'id': 1116373, 'price': '0.00000024', 'qty': '178943.00000000', 'time': 1534170118065, 'isBuyerMaker': False, 'isBestMatch': True}, {'id': 1116374, 'price': '0.00000023', 'qty': '188.00000000', 'time': 1534170158052, 'isBuyerMaker': True, 'isBestMatch': True}, {'id': 1116375, 'price': '0.00000023', 'qty': '173.00000000', 'time': 1534170160358, 'isBuyerMaker': True, 'isBestMatch': True}, {'id': 1116376, 'price': '0.00000023', 'qty': '32232.00000000', 'time': 1534170293908, 'isBuyerMaker': True, 'isBestMatch': True}]
Process finished with exit code 0