Error message: Function is not callable, not sure what is wrong?

179 views Asked by At
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]

when trying to call smaShort function

logger.info("sma short value:" (self.smaShort()))

I get the error smaShort is not callable, anybody know what I am doing wrong?

1

There are 1 answers

0
Igor Kroitor On
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 does not have a XBTUSD symbol, it's a market id not a symbol, as explained in the Manual: https://github.com/ccxt/ccxt/wiki/Manual#symbols-and-market-ids. The correct symbol is BTC/USD.
  2. Also, according to CCXT Manual, the call to bitmex.fetch_ohlcv will return the following structure: https://github.com/ccxt/ccxt/wiki/Manual#ohlcv-structure.
  3. The ohlcv structure is a plain array/list of arrays with OHLCV candle values, not a Pandas DataFrame, so you can't call .rolling(window=5).mean() on a list, you have to convert it to a DataFrame first, like shown above (or in any other way supported by Pandas).