首页 > 解决方案 > 参数中的Python binance非法字符

问题描述

我对python真的很陌生,试图调用binance api并在循环中获取多个货币对的klines数据,并存储到CSV。

我想在 Binance 上引入所有货币对的列表,按标记为活动的货币对进行过滤,然后循环遍历每个货币对的一些代码。

当我将列表值传递给 binance 命令时,我得到“在参数 'symbol' 中发现非法字符;合法范围是 '^[A-Z0-9-_.]{1,20}$'。”

print(pairs_list)给出以下内容:- ['ETHBTC', 'EOSETH']

#import binance api wrapper
from binance.client import Client
# create the Binance client, no need for api key
client = Client("", "")
#import pandas and the json normalizr
import pandas as pd

#bring in the pairs we want to loop through
df1 = pd.read_csv('BINANCE_ALL_PAIRS.csv')
#filter for the active pairs
df = df1[df1.Active.eq(1)]
#Set up a pairs list to be used to call the api in a loop 
pairs_list = df['symbol'].tolist()
#print(pairs_list)

for x in pairs_list:
    # valid intervals - 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w, 1M
    # get timestamp of earliest date data is available
    timestamp = client._get_earliest_valid_timestamp(pairs_list, '1d')

    # request historical candle (or klines) data
    bars = client.get_historical_klines(pairs_list, '1d', timestamp, limit=1000)

标签: pythonloopsbinance

解决方案


推荐阅读