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/

    trade history

    General Code/Help
    2
    2
    882
    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.
    • bb2
      bb2 last edited by bb2

      Hello,

      I am paper trading with IB and have trade history enabled. I want to find out in which case notify_trade doesn't obtain a new Trade instance after a closed one. Assuming I have a closed trade for a given contract, if I make a new order and not close the trade, should notify_trade obtain a new trade with new history or append to history?

      Every once in a while I notice that trade.history[0] is does not belong to my new open order but the previous opening order of the closed price. An example of trade.history you can see below:

      [TradeHistory([('status', AutoOrderedDict([('status', 1), ('dt', 736969.4541666667), ('barlen', 0), ('size', -107500), ('price', 1.15164), ('value', 123801.3), ('pnl', 0.0), ('pnlcomm', 0.0), ('tz', <UTC>)])), ('event', AutoOrderedDict([('order', <backtrader.brokers.ibbroker.IBOrder object at 0x113c50cc0>), ('size', -107500), ('price', 1.15164), ('commission', 2.476026)]))]),
      TradeHistory([('status', AutoOrderedDict([('status', 2), ('dt', 736969.4736689815), ('barlen', 337), ('size', 0), ('price', 1.15164), ('value', 0.0), ('pnl', -95.67500000000618), ('pnlcomm', -100.62896600000617), ('tz', <UTC>)])), ('event', AutoOrderedDict([('order', <backtrader.brokers.ibbroker.IBOrder object at 0x114dbe710>), ('size', 107500), ('price', 1.15253), ('commission', 2.47794)]))]),
      TradeHistory([('status', AutoOrderedDict([('status', 1), ('dt', 736969.4907986111), ('barlen', 0), ('size', 107500), ('price', 1.15262), ('value', 123906.65), ('pnl', -95.67500000000618), ('pnlcomm', -100.62896600000617), ('tz', <UTC>)])), ('event', AutoOrderedDict([('order', <backtrader.brokers.ibbroker.IBOrder object at 0x114c9cbe0>), ('size', 107500), ('price', 1.15262), ('commission', 2.4781330000000006)]))])]
      
      B 1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators @bb2 last edited by

        @bb2 said in trade history:

        should notify_trade obtain a new trade with new history or append to history?

        These are different things. If you open a new trade you get a new Trade instance in notify_trade. In this method there is no notification about history.

        Each trade keep its own history.

        @bb2 said in trade history:

        [TradeHistory([('status', AutoOrderedDict([('status', 1), ('dt', 736969.4541666667), ('barlen', 0), ('size', -107500), ('price', 1.15164), ('value', 123801.3), ('pnl', 0.0), ('pnlcomm', 0.0), ('tz', <UTC>)])), ('event', AutoOrderedDict([('order', <backtrader.brokers.ibbroker.IBOrder object at 0x113c50cc0>), ('size', -107500), ('price', 1.15164), ('commission', 2.476026)]))]),
        TradeHistory([('status', AutoOrderedDict([('status', 2), ('dt', 736969.4736689815), ('barlen', 337), ('size', 0), ('price', 1.15164), ('value', 0.0), ('pnl', -95.67500000000618), ('pnlcomm', -100.62896600000617), ('tz', <UTC>)])), ('event', AutoOrderedDict([('order', <backtrader.brokers.ibbroker.IBOrder object at 0x114dbe710>), ('size', 107500), ('price', 1.15253), ('commission', 2.47794)]))]),
        TradeHistory([('status', AutoOrderedDict([('status', 1), ('dt', 736969.4907986111), ('barlen', 0), ('size', 107500), ('price', 1.15262), ('value', 123906.65), ('pnl', -95.67500000000618), ('pnlcomm', -100.62896600000617), ('tz', <UTC>)])), ('event', AutoOrderedDict([('order', <backtrader.brokers.ibbroker.IBOrder object at 0x114c9cbe0>), ('size', 107500), ('price', 1.15262), ('commission', 2.4781330000000006)]))])]
        

        You may want to elaborate on what has to be seen there.

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors