Search code examples
jsonpython-3.xfilterccxt

Python JSON Trying to filter return traffic for specific identifiers/keys


I need to pull the price from the returned json data. I have searched and search. I only want the price printed from the pprint. The pprint at the bottom no matter how I slice it I cant filter it. Not sure if it need to be put into a dictionary or not.

{'ask': 16749.45,
 'average': None,
 'baseVolume': 16313.93360969,
 'bid': 16749.44,
 'change': None,
 'close': None,
 'datetime': '2017-12-14T23:53:43.476Z',
 'first': None,
 'high': None,
 'info': {'ask': '16749.45',
          'bid': '16749.44',
          '**price': '16749.44000000',**
          'size': '0.10000000',
          'time': '2017-12-14T23:53:43.476000Z',
          'trade_id': 28280124,
          'volume': '16313.93360969'},
 'last': None,
 'low': None,
 'open': None,
 'percentage': None,
 'quoteVolume': None,
 'symbol': 'BTC/USD',
 'timestamp': 1513295623476,
 'vwap': None}


import ccxt
import os
import datetime
from pprint import pprint
import json


#TOP LEVEL EXCHANGE 
gdax = ccxt.gdax()
bittrex = ccxt.bittrex()
bitfinex = ccxt.bitfinex()
kraken = ccxt.kraken()

#LOAD MARKETS - MUST BE LOADED BEFORE CALLING ANY DATA.
gdax.load_markets()
bittrex.load_markets()
bitfinex.load_markets()
kraken.load_markets()

#BTC/USD MARKET CALLS
BU_GDAX = gdax.markets['BTC/USD']
BU_BITF = bitfinex.markets['BTC/USD']
BU_KR = kraken.markets['BTC/USD']

#BTC/XRP MARKET CALLS



#BTC/LTC MARKET CALLS
BL_GDAX = gdax.markets['LTC/BTC']
BL_BITF = bitfinex.markets['LTC/BTC']
BL_KR = kraken.markets['LTC/BTC']



#FETCH TICKERS
pprint((gdax.fetch_ticker('BTC/USD'))

Solution

    1. Update to most recent version of ccxt
    2. Change the pprint line like so: pprint(gdax.fetch_ticker('BTC/USD')['last'])