简体   繁体   English

我怎样才能获得与 Binance API 的美元平价的所有硬币?

[英]How can I get all coins in USD parity to the Binance API?

I need binance data to build a mobile app.我需要币安数据来构建移动应用程序。 Only USDT pairs are sufficient.只有 USDT 对就足够了。 In the link below it takes all trading pairs, but I only want USDT pairs.在下面的链接中,它需要所有交易对,但我只想要 USDT 对。 Which link should I use for this?我应该使用哪个链接?

https://api.binance.com/api/v3/ticker/price https://api.binance.com/api/v3/ticker/price

You can use the Binance Exchange API .您可以使用币安交易所 API There is no need for registering.无需注册。

The used API call is this: https://api.binance.com/api/v3/exchangeInfo使用的 API 调用是这样的: https://api.binance.com/api/v3/exchangeInfo

I recomend you use google colab and python, or any other python resource:我建议您使用 google colab 和 python 或任何其他 python 资源:

import requests

def get_response(url):
    response = requests.get(url)
    response.raise_for_status()  # raises exception when not a 2xx response
    if response.status_code != 204:
        return response.json()

def get_exchange_info():
    base_url = 'https://api.binance.com'
    endpoint = '/api/v3/exchangeInfo'
    return get_response(base_url + endpoint)

def create_symbols_list(filter='USDT'):
    rows = []
    info = get_exchange_info()
    pairs_data = info['symbols']
    full_data_dic = {s['symbol']: s for s in pairs_data if filter in s['symbol']}
    return full_data_dic.keys()

create_symbols_list('USDT')

Result :结果

['BTCUSDT', 'ETHUSDT', 'BNBUSDT', 'BCCUSDT', 'NEOUSDT', 'LTCUSDT',...

The api call brings you a very large response fill with with interesting data about the exchange. api 调用会为您带来非常大的响应,其中包含有关交易所的有趣数据。 In the function create_symbols_list you get all this data in the full_data_dic dictionary.在 function create_symbols_list中,您可以在full_data_dic字典中获得所有这些数据。

There is a python binance client library and you can do check the list of tickers which tickers are quoted in USDT (and status is trading):有一个 python币安客户端库,您可以查看以 USDT 报价的代码列表(状态为交易):

from binance.client import Client
client = Client()
info = client.get_exchange_info()
for c in info['symbols']:
    if c['quoteAsset']=='USDT' and c['status']=="TRADING":
        print(c['symbol'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM