Binance API -代码中的几个符号/对



它确实通过编码与1个加密对一起工作symbol = 'XRPUSDT'但它不适用于2对或更多对。我尝试的方法是:

symbol = ['XRPUSDT', 'DOGEUSDT']
symbol = 'XRPUSDT', 'DOGEUSDT'
symbol = {
"XRP/USDT": "XRP/USDT", 
"DOGE/USDT": "DOGE/USDT"
}
symbol = [(XRP/USDT, 'XRP/USDT'), (DOGE/USDT, 'DOGE/USDT')]

不幸的是,以上都没有成功。有没有人有什么想法可以列出几个加密货币对?TIA

你可以在循环中这样做:

symbols = ['XRPUSDT', 'DOGEUSDT']
for symbol in symbols:
# Binance RESTful API

下面是如何在循环中向Binance API发送GET请求的代码片段:

for symbol in symbols:
candles = requests.get("https://api.binance.com/api/v3/klines", params={'symbol': symbol,
'interval': interval,
'startTime': start_time,
'endTime': end_time}).json()

下面是一个完整的例子:

import requests
from datetime import datetime
api_address = 'https://api.binance.com/api/v3/klines'
start_time = int(datetime(2021, 8, 20).timestamp()) * 1000
end_time = int(datetime(2021, 8, 30).timestamp()) * 1000
interval='1d'
symbols = ['XRPUSDT', 'DOGEUSDT']
for symbol in symbols:
candles = requests.get(url=api_address,
params={'symbol': symbol,
'interval': interval,
'startTime': start_time,
'endTime': end_time})
print(candles.json())

查看文档获取更多信息https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md#klinecandlestick-data

相关内容

  • 没有找到相关文章

最新更新