def smaShort(self):
while True:
ohlcv_candles = bitmex2.bitmex.fetch_ohlcv(self, symbol= 'XBTUSD', timeframe= '5m')
mas = []
mas = ohlcv_candles.rolling(window=5).mean()
return mas#[-1]
在尝试调用smaShort函数时
logger.info("sma short value:" (self.smaShort()))
我收到错误smaShort无法调用,有人知道我在做什么错吗?
答案 0 :(得分:0)
import pandas as pd
import ccxt
exchange = ccxt.bitmex({
'enableRateLimit': True, # required by the Manual
})
ohlcv = exchange.fetch_ohlcv('BTC/USD', '1m')
df = pd.DataFrame (ohlcv)
df[4].rolling(window=5).mean() # OHLCV, C (closing price) has index 4
XBTUSD
符号,它是市场 id ,而不是符号,如《手册》 https://github.com/ccxt/ccxt/wiki/Manual#symbols-and-market-ids中所述。正确的符号是BTC/USD
。bitmex.fetch_ohlcv
的调用将返回以下结构:https://github.com/ccxt/ccxt/wiki/Manual#ohlcv-structure。.rolling(window=5).mean()
,必须先将其转换为DataFrame,例如如上所示(或以熊猫支持的任何其他方式)。