-1
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 is not callable,有人知道我做错了什么吗?

4

1 回答 1

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
  1. Bitmex 没有XBTUSD符号,它是市场id而不是符号,如手册中所述:https ://github.com/ccxt/ccxt/wiki/Manual#symbols-and-market-ids 。正确的符号是BTC/USD
  2. 此外,根据 CCXT 手册,调用bitmex.fetch_ohlcv将返回以下结构:https ://github.com/ccxt/ccxt/wiki/Manual#ohlcv-structure 。
  3. ohlcv 结构是具有 OHLCV 蜡烛值的普通数组/数组列表,而不是 Pandas DataFrame,因此您不能调用.rolling(window=5).mean()列表,您必须先将其转换为 DataFrame,如上所示(或以任何其他方式熊猫支持)。
于 2018-11-11T17:31:14.980 回答