Reputation: 31
How to query a currency in binance? In the bitfinex API I can only filter BTCUSD, but in binance the query returns all negotiated pairs.
import requests
import json
requisicao = requests.get('https://api.binance.com/api/v3/ticker/price')
cotacao = json.loads(requisicao.text)
def bitfinex_btc():
bitFinexTick1 = requests.get("https://api.bitfinex.com/v1/ticker/btcusd")
return bitFinexTick1.json()['last_price']
bitfinexlivebtc = float(bitfinex_btc())
print ('BITFINEX BTC = U$',bitfinexlivebtc)
print ('BINANCE BTC = U$',cotacao)
Upvotes: 1
Views: 8467
Reputation: 4320
If I understand correctly, you want to filter on BTC->USD only when accessing Binance.
From the API documentation at:
you can add the symbol as a query parameter, so it would look like this:
https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT
The response is of the following form:
{
"price": "8196.79000000",
"symbol": "BTCUSDT"
}
so in Python the function would be something like:
def binance_btc():
binanceTick1 = requests.get("https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT")
return binanceTick1.json()['price']
Upvotes: 4