1

The API here: https://api.bitfinex.com/v2/tickers?symbols=ALL

does not have any labels and I want to extract all of the tBTCUSD, tLTCUSD etc.. Basically everything without numbers. Normally, i would extract this information if they are labeled so i can do something like:

data['name']

or something like that however this API does not have labels.. how can i get this info with python?

0

3 Answers 3

2

You can do it like this:

import requests

j = requests.get('https://api.bitfinex.com/v2/tickers?symbols=ALL').json()    

mydict = {}

for i in j:
    mydict[i[0]] = i[1:]

Or using dictionary comprehension:

mydict = {i[0]: i[1:] for i in j}

Then access it as:

mydict['tZRXETH']
Sign up to request clarification or add additional context in comments.

1 Comment

There is no need for j=json.loads(r.text). Just call .json() on the response. r = requests.get('https://api.bitfinex.com/v2/tickers?symbols=ALL').json()
1

I don't have access to Python right now, but it looks like they're organized in a superarray of several subarrays.

You should be able to extract everything (the superarray) as data, and then do a:

for array in data:
print array[0]

Not sure if this answers your question. Let me know!

Comments

1

Even if it doesn't have labels (or, more specifically, if it's not a JSON object) it's still a perfectly legal piece of JSON, since it's just some arrays contained within a parent array.

Assuming you can already get the text from the api, you can load it as a Python object using json.loads:

import json
data = json.loads(your_data_as_string)

Then, since the labels you want to extract are always in the first position of the arrays, you can store them in a list using a list comprehension:

labels = [x[0] for x in data]

labels will be:

['tBTCUSD', 'tLTCUSD', 'tLTCBTC', 'tETHUSD', 'tETHBTC', 'tETCBTC', ...]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.