I tried like this, but it doesn’t work. It worked with an other json file (https://www.binance.com/fapi/v1/ticker/price) I think it’s because the beginning and end is different. There is some parts before the bracket and after.
I got the error: symbol = (pair[‘symbol’]) TypeError: string indices must be integers
JavaScript
x
13
13
1
import requests
2
import json
3
4
bybit = requests.get("https://api-testnet.bybit.com/v2/public/tickers")
5
e = bybit.json()
6
7
for pair in e:
8
symbol = (pair['symbol'])
9
price = (pair['last_price'])
10
11
print (symbol)
12
print (price)
13
Advertisement
Answer
e contains some other information. The data that you want is in e[‘result’]
JavaScript
1
13
13
1
import requests
2
import json
3
4
bybit = requests.get("https://api-testnet.bybit.com/v2/public/tickers")
5
e = bybit.json()
6
7
for pair in e['result']:
8
symbol = (pair['symbol'])
9
price = (pair['last_price'])
10
11
print (symbol)
12
print (price)
13