Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. bazar guru
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    • Profile
    • Following 1
    • Followers 0
    • Topics 0
    • Posts 2
    • Best 0
    • Groups 0

    bazar guru

    @bazar guru

    0
    Reputation
    5
    Profile views
    2
    Posts
    0
    Followers
    1
    Following
    Joined Last Online

    bazar guru Unfollow Follow

    Latest posts made by bazar guru

    • RE: Interactive Broker on daily data and paper account

      Bit late here but would like to know how it got solved for you.

      I qualify both the above conditions but still I am not getting historical data.

      My code is as below :

      from _datetime import datetime
      import backtrader as bt
      
      # Create a Stratey
      class TestStrategy(bt.Strategy):
      
          def log(self, txt, dt=None):
              ''' Logging function for this strategy'''
              dt = dt or self.datas[0].datetime.date(0)
              print('%s, %s' % (dt.isoformat(), txt))
      
          def __init__(self):
              # Keep a reference to the "close" line in the data[0] dataseries
              self.dataclose = self.datas[0].close
      
          def next(self):
              # Simply log the closing price of the series from the reference
              self.log('Close, %.2f' % self.dataclose[0])
      
      
      if __name__ == '__main__':
          # Create a cerebro entity
          cerebro = bt.Cerebro()
      
          ibstore = bt.stores.IBStore(host='127.0.0.1', port=7497, clientId=777)
          #ibstore = bt.stores.IBStore(host='127.0.0.1', port=4002, clientId=6666666)
          data = ibstore.getdata(dataname="ITC-STK-SMART-IND", historical=True, fromdate=datetime(2019, 1, 1), todate=datetime(2019, 8, 1), timeframe=bt.TimeFrame.Minutes, compression=5)
      
          cerebro.adddata(data)
      
          cerebro.addstrategy(TestStrategy)
      
          cerebro.broker.setcash(100000.0)
      
          # Print out the starting conditions
          print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
      
          # Run over everything
          cerebro.run()
      
          # Print out the final result
          print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
      

      Getting below output without data :

      Starting Portfolio Value: 100000.00
      Final Portfolio Value: 100000.00
      

      Please advise

      posted in General Code/Help
      bazar guru
      bazar guru
    • RE: Error while retrieving IBStore historic data with an IB paper account

      @kriku I am trying to replicate the same scenario for Indian stock . I have a paper account with IB.

      from _datetime import datetime
      import backtrader as bt
      
      # Create a Stratey
      class TestStrategy(bt.Strategy):
      
          def log(self, txt, dt=None):
              ''' Logging function for this strategy'''
              dt = dt or self.datas[0].datetime.date(0)
              print('%s, %s' % (dt.isoformat(), txt))
      
          def __init__(self):
              # Keep a reference to the "close" line in the data[0] dataseries
              self.dataclose = self.datas[0].close
      
          def next(self):
              # Simply log the closing price of the series from the reference
              self.log('Close, %.2f' % self.dataclose[0])
      
      
      if __name__ == '__main__':
          # Create a cerebro entity
          cerebro = bt.Cerebro()
      
          ibstore = bt.stores.IBStore(host='127.0.0.1', port=4002, clientId=7777777)
          #ibstore = bt.stores.IBStore(host='127.0.0.1', port=4002, clientId=6666666)
          data = ibstore.getdata(dataname="RELIANCE-STK-SMART-IND", historical=True, fromdate=datetime(2019, 1, 1), todate=datetime(2019, 8, 1), timeframe=bt.TimeFrame.Minutes, compression=5)
      
          cerebro.adddata(data)
      
          cerebro.addstrategy(TestStrategy)
      
          cerebro.broker.setcash(100000.0)
      
          # Print out the starting conditions
          print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
      
          # Run over everything
          cerebro.run()
      
          # Print out the final result
          print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
      

      But this is not giving me any data. Getting below output :

      Starting Portfolio Value: 100000.00
      Final Portfolio Value: 100000.00
      

      I have the permission enabled in IB to share the live account data with paper account. Am i missing something ?

      posted in General Code/Help
      bazar guru
      bazar guru