For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Testing RSI and SMA using bt.feeds.CCXT for Bittrex



  • Hi,
    New to backtrader, but reasonable python experience.
    Having some problems getting a datafeed from Bittrex using CCXT.
    The data appears to come through, but I can't get the RSI & SMA indicators to work.

    I am quite sure it's something to do with the data structures coming back from CCXT, but I can't be sure.

    Please see the code that WORKS below (using APPL data from Yahoo).

    from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
     from datetime import datetime, timedelta
    import backtrader as bt
    
    class TestStrategy(bt.Strategy):
    
    def __init__(self):
        self.rsi = bt.indicators.RSI_SMA(period=14)
        self.sma = bt.indicators.SMA(period=15)
    
    if __name__ == '__main__':
    
    cerebro = bt.Cerebro()
    data = bt.feeds.YahooFinanceData(
         dataname='AAPL',
         fromdate = datetime(2019,1,1),
         todate = datetime(2020,1,1),
         buffered= True
         )
    
    
    cerebro.adddata(data)
    cerebro.addstrategy(TestStrategy)
    cerebro.run()
    cerebro.plot()
    

    However when I change the time periods the data feed fails;

    from __future__ import (absolute_import, division, print_function,
     
                             unicode_literals)
     
     from datetime import datetime, timedelta
     
     import backtrader as bt
     
     
     
     class SmaCross(bt.SignalStrategy):
     
         def __init__(self):
     
             sma1, sma2 = bt.ind.SMA(period=10), bt.ind.SMA(period=30)
     
             crossover = bt.ind.CrossOver(sma1, sma2)
     
             self.signal_add(bt.SIGNAL_LONG, crossover)
     
     
     
     if __name__ == '__main__':
     
     
     
         cerebro = bt.Cerebro()
     
     #     data = bt.feeds.YahooFinanceData(
     
     #          dataname='AAPL',
     
     #          fromdate = datetime(2019,1,1),
     
     #          todate = datetime(2020,1,1),
     
     #          buffered= True
     
     #          )
     
         symbol = 'BTC/USDT'
     
         hist_start_date = datetime.utcnow() - timedelta(minutes=3600)
     
         #broker = bt.brokers.CCXTBroker(exchange='bittrex')
     
         data = bt.feeds.CCXT(exchange = 'bittrex', symbol='BTC/USDT', 
     
                                   name="btc_usdt_bittrex", timeframe=bt.TimeFrame.Minutes,
     
                                   #compression = 1,
     
                                   fromdate = hist_start_date)
     
     
     
         cerebro.adddata(data)
     
         cerebro.addstrategy(SmaCross)
     
         cerebro.run()
     
         cerebro.plot()nd fails to plot. 
    

    Would anyone have a link to how to interogate the feeds I would be most grateful.
    Thanks



  • OK, CCXT was calling BITTREX far to much for offline testing,
    I applied

          data=bt.feeds.PandasData(dataname=df,datetime=-1,open=-1,high=-1,low=-1,close=-1,volume=-1,openinterest='openinterest',timeframe=bt.TimeFrame.Days,compression=1)
    

    after creating a static extract from the API using

    from bittrex.bittrex import Bittrex, API_V2_0
          trade = 'BTC'
         currency = 'DOGE'
        market = '{0}-{1}'.format(trade, currency)
       tick_interval ='day'
       my_bittrex = Bittrex(None, None, api_version=API_V2_0)  # or defaulting to v1.1 as Bittrex(None, None)
     
        t = my_bittrex.get_candles(market,tick_interval)
    
       df = pd.DataFrame(t['result'])
      df['T'] = pd.to_datetime(df['T']) 
     df.set_index(df['T'],inplace=True)
    
      df.columns = ['BV','close','high','low','open','datetime','volume']
    
      df['openinterest'] = 0

 

});