import pandas as pd
from binance.client import Client
client = Client(api_key, api_secret)
klines = client.get_historical_klines("BTCUSDT", Client.KLINE_INTERVAL_1HOUR, "1 day ago UTC")
df = pd.DataFrame(klines, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume', 'close_time',
'quote_asset_volume', 'number_of_trades', 'taker_buy_base_asset_volume',
'taker_buy_quote_asset_volume', 'ignore'])
df = df.astype(float)
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
df.set_index('timestamp', inplace=True)
def EMA(data, period=20, column='close'):
return data[column].ewm(span=period, adjust=False).mean()
df['EMA10'] = EMA(df, period=10)
df['EMA20'] = EMA(df, period=20)
print(df[['close', 'EMA10', 'EMA20']])
上一篇:BinanceAPIK线图/蜡烛图数据的JSON语法无效。
下一篇:BinanceAPI期货交易-{'code':-1117,'msg':'无效的交易方向。'}