From 7e214180a61a79297ed7f14ee230d30566a0752d Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 7 Mar 2021 22:17:19 -0500 Subject: [PATCH] Remove old simulated order price on update --- piker/exchange/_paper_engine.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/piker/exchange/_paper_engine.py b/piker/exchange/_paper_engine.py index 06499732..740345f5 100644 --- a/piker/exchange/_paper_engine.py +++ b/piker/exchange/_paper_engine.py @@ -70,15 +70,15 @@ class PaperBoi: if brid is None: reqid = str(uuid.uuid4()) - # register order internally - self._reqids[reqid] = (oid, symbol, action, price) - else: # order is already existing, this is a modify (oid, symbol, action, old_price) = self._reqids[brid] assert old_price != price reqid = brid + # register order internally + self._reqids[reqid] = (oid, symbol, action, price) + if action == 'alert': # bypass all fill simulation return reqid @@ -129,6 +129,10 @@ class PaperBoi: # and trigger by the simulated clearing task normally # running ``simulate_fills()``. + if brid is not None: + # remove any existing order for the old price + orders[symbol].pop((oid, old_price)) + # buys/sells: (symbol -> (price -> order)) orders.setdefault(symbol, {})[(oid, price)] = (size, reqid, action)