Search code examples
pythondatabaseetrade-api

trade api data collecting


hi there when i type this data

url = 'https://rest.coinapi.io/v1/quotes/BITSTAMP_SPOT_BTC_USD/current'

headers={'X-CoinAPI-Key' : '73034021-0EBC-493D-8A00-E0F138111F41'}
response = requests.get(url, headers=headers)
x=response.json()
print(x)

my print list is

{'ask_size': 1.0105962, 'ask_price': 3422.58, 'time_exchange': '2019-02-05T13:11:10.0724918Z', 'symbol_id': 'BITSTAMP_SPOT_BTC_USD', 'bid_size': 2.49846056, 'last_trade': {'uuid': 'a2894632-441e-4ad5-bfb8-c61bd84a724e', 'time_exchange': '2019-02-05T13:10:51.0000000Z', 'size': 0.00553675, 'taker_side': 'BUY', 'price': 3422.58, 'time_coinapi': '2019-02-05T13:10:51.2541019Z'}, 'bid_price': 3421.8, 'time_coinapi': '2019-02-05T13:11:10.0724918Z'}

but i only wanna get taker side and price how can i do it?


Solution

  • The output of response.json() is a Python dictionary, which means you can access data using the following syntax:

    resp = response.json()
    taker_side = resp['last_trade']['taker_side']
    price = resp['last_trade']['price']
    

    You can then use them just like any other variable.