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


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

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



  • Noted, thanks.


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.