Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    FA (Financial Advisor, IB) setup in Backtrader

    General Code/Help
    2
    2
    610
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mani last edited by mani

      New to Python as well as algo world, but learning and trying.

      Tested my FA paper trading account and it works fine. It is rather easy!
      However, I am getting small error in the commission report, I guess. This could be easy for coding experts. Please take a look at the error and I appreciate if someone can help.

      Data0, 0829, 736705.5020833333, 2018-01-11T12:03:00.000000, 133.323, 133.323, 133.299, 133.304, -1.0, 0, 133.3172
      Data0, 0830, 736705.5027777777, 2018-01-11T12:04:00.000000, 133.304, 133.313, 133.3, 133.304, -1.0, 0, 133.3152
      ***** DATA NOTIF: LIVE
      Data0, 0831, 736705.5034722222, 2018-01-11T12:05:00.000000, 133.299, 133.3, 133.292, 133.292, 0.0, 0, 133.3102
      11-Jan-18 20:05:01 ERROR     Exception in message dispatch.  Handler 'commissionReport' for 'commissionReport'
      Traceback (most recent call last):
        File "/home/mani/backtrader-live/lib/python3.5/site-packages/ib/opt/dispatcher.py", line 44, in __call__
          results.append(listener(message))
        File "/home/mani/backtrader-live/lib/python3.5/site-packages/backtrader/stores/ibstore.py", line 1298, in commissionReport
          self.broker.push_commissionreport(msg.commissionReport)
        File "/home/mani/backtrader-live/lib/python3.5/site-packages/backtrader/brokers/ibbroker.py", line 490, in push_commissionreport
          ostatus = self.ordstatus[oid].pop(ex.m_cumQty)
      KeyError: 200000
      11-Jan-18 20:05:01 ERROR     Exception in message dispatch.  Handler 'commissionReport' for 'commissionReport'
      Traceback (most recent call last):
        File "/home/mani/backtrader-live/lib/python3.5/site-packages/ib/opt/dispatcher.py", line 44, in __call__
          results.append(listener(message))
        File "/home/mani/backtrader-live/lib/python3.5/site-packages/backtrader/stores/ibstore.py", line 1298, in commissionReport
          self.broker.push_commissionreport(msg.commissionReport)
        File "/home/mani/backtrader-live/lib/python3.5/site-packages/backtrader/brokers/ibbroker.py", line 490, in push_commissionreport
          ostatus = self.ordstatus[oid].pop(ex.m_cumQty)
      KeyError: 200000
      11-Jan-18 20:05:01 ERROR     Exception in message dispatch.  Handler 'commissionReport' for 'commissionReport'
      Traceback (most recent call last):
        File "/home/mani/backtrader-live/lib/python3.5/site-packages/ib/opt/dispatcher.py", line 44, in __call__
          results.append(listener(message))
        File "/home/mani/backtrader-live/lib/python3.5/site-packages/backtrader/stores/ibstore.py", line 1298, in commissionReport
          self.broker.push_commissionreport(msg.commissionReport)
        File "/home/mani/backtrader-live/lib/python3.5/site-packages/backtrader/brokers/ibbroker.py", line 490, in push_commissionreport
          ostatus = self.ordstatus[oid].pop(ex.m_cumQty)
      KeyError: 200000
      ***** STORE NOTIF: The current calculated position and the position reported by the broker do not match. Operation can continue, but the trades calculated in the strategy may be wrong
      -------------------------------------------------- ORDER BEGIN 2018-01-11 20:06:01.489278
      Ref: 1
      OrdType: 0
      OrdType: Buy
      Status: 1
      Status: Submitted
      Size: 200000
      Price: 119.96
      Price Limit: None
      TrailAmount: None
      TrailPercent: None
      ExecType: 0
      ExecType: Market
      CommInfo: <backtrader.brokers.ibbroker.IBCommInfo object at 0x7f8ab21ddfd0>
      End of Session: 736705.9999999999
      Info: AutoOrderedDict()
      Broker: <backtrader.brokers.ibbroker.IBBroker object at 0x7f8ab32325c0>
      Alive: True
      Ref: 1
      orderId: 1
      Action: BUY
      Size (ib): 200000
      Lmt Price: 0.0
      Aux Price: 0.0
      OrderType: MKT
      Tif (Time in Force): GTC
      GoodTillDate: 
      -------------------------------------------------- ORDER END
      -------------------------------------------------- ORDER BEGIN 2018-01-11 20:06:01.490557
      Ref: 1
      OrdType: 0
      OrdType: Buy
      Status: 4
      Status: Completed
      Size: 200000
      Price: 119.96
      Price Limit: None
      TrailAmount: None
      TrailPercent: None
      ExecType: 0
      ExecType: Market
      CommInfo: <backtrader.brokers.ibbroker.IBCommInfo object at 0x7f8ab21ddfd0>
      End of Session: 736705.9999999999
      Info: AutoOrderedDict()
      Broker: <backtrader.brokers.ibbroker.IBBroker object at 0x7f8ab32325c0>
      Alive: False
      Ref: 1
      orderId: 1
      Action: BUY
      Size (ib): 200000
      Lmt Price: 0.0
      Aux Price: 0.0
      OrderType: MKT
      Tif (Time in Force): GTC
      GoodTillDate: 
      -------------------------------------------------- ORDER END
      -------------------------------------------------- TRADE BEGIN 2018-01-11 20:06:01.492264
      ref:1
      data:<backtrader.feeds.ibdata.IBData object at 0x7f8ab322bcf8>
      tradeid:0
      size:200000
      price:133.295
      value:26658999.999999996
      commission:4.784887
      pnl:0.0
      pnlcomm:0.0
      justopened:True
      isopen:True
      isclosed:False
      baropen:831
      dtopen:736705.5034722222
      barclose:0
      dtclose:0.0
      barlen:0
      historyon:False
      history:[]
      status:1
      -------------------------------------------------- TRADE END
      Data0, 0832, 736705.5041666667, 2018-01-11T12:06:00.000000, 133.291, 133.324, 133.289, 133.315, 0.0, 0, 133.3076
      Data0, 0833, 736705.504861111, 2018-01-11T12:07:00.000000, 133.314, 133.325, 133.307, 133.317, 0.0, 0, 133.3064
      

      Further test shows this error is produced if a single order sent to a FA group or FA profile, where it will be allocated or sliced according to the setup in TWS. That group or profile contains two or more sub accounts. However, there is no error when an order is sent specifically to a single account. I understand the code are meant for single account only, but I believe since backtrader is able to support FA account structure, such errors can be corrected.

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        Let me be blunt about this: as a Financial Advisor you can consider funding the development of such FA account support.

        1 Reply Last reply Reply Quote 1
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
        $(document).ready(function () { app.coldLoad(); }); }