Backtrader Community

    • 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/

    'oid' referenced before assignment - Limit and Stop orders

    General Code/Help
    2
    3
    1196
    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.
    • T
      ThatBlokeDave last edited by

      I am seeing an issue when submitting Limit and Stop orders on the Oanda store.

      At first I thought it was an issue with my implementation so I tested again using the reference script:
      https://github.com/mementum/backtrader/blob/master/samples/oandatest/oandatest.py

      dave@dave-ThinkPad-T410:~/Dropbox/Documents/Development/Python/Python3/backtrader/tests$ python3 oandatest.py --account REMOVED --token REMOVED --data0 GBP_USD --resample --timeframe Minutes --compression 1 --no-backfill_start --exectype Limit --stake 1000 --trade --broker
      --------------------------------------------------
      Strategy Created
      --------------------------------------------------
      -- Contract Details:
      {'maxTradeUnits': 10000000, 'pip': '0.0001', 'instrument': 'GBP_USD', 'displayName': 'GBP/USD'}
      Datetime, Open, High, Low, Close, Volume, OpenInterest, SMA
      ***** DATA NOTIF: LIVE
      Data0, 0001, 736409.331250, 2017-03-21T07:57:00.000000, 1.236770, 1.236830, 1.236760, 1.236830,      0, 0, nan
      Exception in thread Thread-1:
      Traceback (most recent call last):
        File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
          self.run()
        File "/usr/lib/python3.5/threading.py", line 862, in run
          self._target(*self._args, **self._kwargs)
        File "/home/dave/.local/lib/python3.5/site-packages/backtrader/stores/oandastore.py", line 335, in _t_streaming_listener
          self._transaction(trans)
        File "/home/dave/.local/lib/python3.5/site-packages/backtrader/stores/oandastore.py", line 582, in _transaction
          oref = self._ordersrev[oid]
      UnboundLocalError: local variable 'oid' referenced before assignment
      
      -------------------------------------------------- ORDER BEGIN 2017-03-21 15:58:00.176850
      Ref: 1
      OrdType: 0
      OrdType: Buy
      Status: 1
      Status: Submitted
      Size: 1000
      Price: 1.2318300000000002
      Price Limit: None
      ExecType: 2
      ExecType: Limit
      CommInfo: <backtrader.comminfo.CommInfoBase object at 0x7f11bc206198>
      End of Session: 736409.9999999999
      Info: AutoOrderedDict()
      Broker: <backtrader.brokers.oandabroker.OandaBroker object at 0x7f11ba9de898>
      Alive: True
      -------------------------------------------------- ORDER END
      
      

      The order is still submitted and I can see it on the platform.

      0_1490083382983_OID Issue.png

      Testing using market orders works without issue. I also noticed that after the thread is killed, I don't get the follow on "order.Accepted" notification. (I assume because of the exception in the thread).

      Thanks

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

        During development it was a surprise not to see, for example, LIMIT_CREATE notified and that's why the code was catching it later. It would seem that the finishing of the API for REST-2.0 came together with some fixes in the v1 API.

        That message (and STOP_CREATE) are now caught earlier in the code. The development branch has the commit for it.

        https://github.com/mementum/backtrader/commit/06a980b5d21d52bf7a958649322f9e7fe7283715

        T 1 Reply Last reply Reply Quote 0
        • T
          ThatBlokeDave @backtrader last edited by

          Noted, thanks.

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