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)