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

'oid' referenced before assignment - Limit and Stop orders

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

    dave@dave-ThinkPad-T410:~/Dropbox/Documents/Development/Python/Python3/backtrader/tests$ python3 --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/", line 914, in _bootstrap_inner
      File "/usr/lib/python3.5/", line 862, in run
        self._target(*self._args, **self._kwargs)
      File "/home/dave/.local/lib/python3.5/site-packages/backtrader/stores/", line 335, in _t_streaming_listener
      File "/home/dave/.local/lib/python3.5/site-packages/backtrader/stores/", 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).


  • administrators

    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.

  • Noted, thanks.

Log in to reply