0

I'm using python and i'm trying to exxtract only the 'ticker' and the 'last' fields.

page = requests.get('https://api.coinex.com/perpetual/v1/market/ticker/all')
print page.json
print a['ticker']['last']

{"code": 0, "data": {"date": 1654345634529, "ticker": {"KAVAUSDT": {"vol": "798288", "low": "2.3881", "open": "2.4666", "high": "2.5812", "last": "2.4625", "buy": "2.4640", "period": 86400, "funding_time": 212, "position_amount": "53008", "funding_rate_last": "-0.00018969", "funding_rate_next": "-0.00087790", "funding_rate_predict": "-0.00045043", "insurance": "17628475.33491688425550626390", "sign_price": "2.4666", "index_price": "2.4676", "sell_total": "54759", "buy_total": "50186", "buy_amount": "395", "sell": "2.4654", "sell_amount": "138"}, "ONTUSDT": {"vol": "1473187", "low": "0.2709", "open": "0.2773", "high": "0.2829", "last": "0.2750", "buy": "0.2749", "period": 86400, "funding_time": 212, "position_amount": "109416", "funding_rate_last": "-0.00053684", "funding_rate_next": "0.00017823", "funding_rate_predict": "-0.00062364", "insurance": "17628475.33491688425550626390", "sign_price": "0.2757", "index_price": "0.2757", "sell_total": "343448", "buy_total": "401166", "buy_amount": "2347", "sell": "0.2752", "sell_amount": "2347"}}}, "message": "OK"}

Expected output

KAVAUSDT 2.4625
ONTUSDT 0.2750

One boy
  • 216
  • 1
  • 7
  • [Please try](https://meta.stackoverflow.com/questions/261592) to research questions before asking. I found the linked duplicate by putting `[python-requests] json` into the site search: even with that little, it is the third result. You can also try reading the [documentation](https://requests.readthedocs.io/en/latest/), which shows an example in the very first code block of the main page, without any need to scroll on the page at all. – Karl Knechtel Jun 04 '22 at 12:35
  • From https://api.coinex.com/perpetual/v1/market/ticker/all, I see `ticker` is the large variable and `last` is the last price of the items which are inside `ticker`. Can you list some expected output? Are you using Python 2? – arshovon Jun 04 '22 at 12:39
  • I'm using python 3. Expected output: Ticker: KAVAUSDT 2.4625 ONTUSDT 0.2750 – One boy Jun 04 '22 at 12:47
  • hello, you know how to do it? – One boy Jun 04 '22 at 18:14

0 Answers0