提问人:Jaya Asiri Prem 提问时间:10/29/2023 更新时间:10/29/2023 访问量:17
对币安的硬币进行测试时出错
Error when running a test on coins from Binance
问:
我已经导入了币安目前可用的所有 USTD 硬币的列表。我在 Stackoverflow 上对另一个问题的回复中使用了这段代码:
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')
然后我尝试使用以下代码在此列表上运行 Dickey-Fuller 测试:
import pandas as pd
import numpy as np
from binance.um_futures import UMFutures
from binance.exceptions import BinanceAPIException
from binance.client import Client
import time
api_key = ''
api_secret = ''
client = UMFutures(key = api_key, secret = api_secret)
def klines(symbol):
try:
df = pd.DataFrame(client.klines(symbol, '1h', limit = 720))
except BinanceAPIException as e:
print(e)
sleep(60)
df = pd.DataFrame(client.klines(symbol, '1h', limit = 720))
df = df.iloc[:,:6]
df.columns = ['Time', 'Open', 'High', 'Low', 'Close', 'Volume']
df = df.set_index('Time')
df.index = pd.to_datetime(df.index, unit='ms')
df.drop(columns = ['Open', 'High', 'Low', 'Volume'], axis = 1, inplace = True)
df = df.astype(float)
return df
from statsmodels.tsa.stattools import adfuller
base = ['BTCUSDT', 'ETHUSDT', 'BNBUSDT', 'BCCUSDT', 'NEOUSDT', 'LTCUSDT',
'QTUMUSDT', 'ADAUSDT', 'XRPUSDT', 'EOSUSDT', 'TUSDUSDT', 'IOTAUSDT',
'XLMUSDT', 'ONTUSDT', 'TRXUSDT', 'ETCUSDT', 'ICXUSDT', 'VENUSDT', 'NULSUSDT',
'VETUSDT', 'PAXUSDT', 'BCHABCUSDT', 'BCHSVUSDT', 'USDCUSDT', 'LINKUSDT',
'WAVESUSDT', 'BTTUSDT', 'USDSUSDT', 'ONGUSDT', 'HOTUSDT', 'ZILUSDT', 'ZRXUSDT', 'FETUSDT',
'BATUSDT', 'XMRUSDT', 'ZECUSDT', 'IOSTUSDT', 'CELRUSDT', 'DASHUSDT', 'NANOUSDT', 'OMGUSDT',
'THETAUSDT', 'ENJUSDT', 'MITHUSDT', 'MATICUSDT', 'ATOMUSDT', 'TFUELUSDT', 'ONEUSDT', 'FTMUSDT',
'ALGOUSDT', 'USDSBUSDT', 'GTOUSDT', 'ERDUSDT', 'DOGEUSDT', 'DUSKUSDT', 'ANKRUSDT', 'WINUSDT', 'COSUSDT',
'NPXSUSDT', 'COCOSUSDT', 'MTLUSDT', 'TOMOUSDT', 'PERLUSDT', 'DENTUSDT', 'MFTUSDT', 'KEYUSDT', 'STORMUSDT',
'DOCKUSDT', 'WANUSDT', 'FUNUSDT', 'CVCUSDT', 'CHZUSDT'] #... etc.
res = []
for i in base:
for j in base[base.index(i):]:
if i != j:
spreadcheck = adfuller((klines(i)['Close'])/(klines(j)['Close']).dropna(), autolag='AIC')
if spreadcheck[1] < 0.001:
res.append([i,j, spreadcheck[0], spreadcheck[1]])
def PValue(inputList):
return inputList[3]
res = sorted(res, key=PValue)
res
但是我收到此错误:
ClientError: (400, -1121, 'Invalid symbol.', {'Date': 'Sun, 29 Oct 2023 13:45:13 GMT', 'Content-Type': 'application/json', 'Content-Length': '38', 'Connection': 'keep-alive', 'Server': 'Tengine', 'X-MBX-USED-WEIGHT-1M': '30', 'x-response-time': '2ms', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS'})
如果这是从币安导入的当前有效硬币的完整列表,为什么会出现此错误?
答: 暂无答案
评论