Skip to content

Commit 5dbd18b

Browse files
authored
Merge pull request #15 from joequant/algosim-fixes
algosim fixes
2 parents 45482c1 + 54182b0 commit 5dbd18b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

bin/algosim.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ def process_line(order_book, line, output=True):
154154
printme ("participation=", stats[3])
155155

156156
if myalgo != None:
157-
(algo_orders, mode) = myalgo.process_order(line,
158-
trade, order)
157+
(algo_orders, mode) = myalgo.process_order(line, order)
159158
printme('')
160159
printme("RUNNING ALGO WITH MODE=", mode)
161160
old_orderbook = copy.deepcopy(order_book)
@@ -164,6 +163,18 @@ def process_line(order_book, line, output=True):
164163
if line['type'] == 'cancel':
165164
order_book.cancel_order(line['side'],
166165
line['order_id'])
166+
elif line['type'] == 'cancel_all':
167+
if line['side'] == "bid":
168+
q = order_book.bids
169+
elif line['size'] == 'ask':
170+
q = order_book.asks
171+
else:
172+
sys.exit('not given bid or ask')
173+
for order in q.price_tree.get(Decimal(line['price']),
174+
[]):
175+
if order.trade_id == line['trade_id']:
176+
order_book.cancel_order(line['side'],
177+
order.order_id)
167178
elif line['type'] == 'modify':
168179
order_book.modify_order(line['order_id'], {
169180
'side': line['side'],

bin/myalgo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def __init__(self, order_book):
77
self.volume = 0
88
self.my_volume = 0
99

10-
def process_order(self, line, trade, order):
10+
def process_order(self, line, order):
1111
tokens = line.strip().split(",")
1212
if tokens[0] == 'C' and tokens[1] == 'start-algo':
1313
print("starting-algo")

0 commit comments

Comments
 (0)