Skip to content

Commit 56ac5e3

Browse files
committed
Resolve non termmination bug when traversing after modifying order with a larger quantity.
1 parent 5dbd18b commit 56ac5e3

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

orderbook/orderlist.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class OrderList(object):
22
'''
33
A doubly linked list of Orders. Used to iterate through Orders when
44
a price match is found. Each OrderList is associated with a single
5-
price. Since a single price match can have more quantity than a single
5+
price. Since a single price match can have more quantity than a single
66
Order, we may need multiple Orders to fullfill a transaction. The
77
OrderList makes this easy to do. OrderList is naturally arranged by time.
88
Orders at the front of the list have priority.
@@ -13,7 +13,7 @@ def __init__(self):
1313
self.tail_order = None # last order in the list
1414
self.length = 0 # number of Orders in the list
1515
self.volume = 0 # sum of Order quantity in the list AKA share volume
16-
self.last = None # helper for iterating
16+
self.last = None # helper for iterating
1717

1818
def __len__(self):
1919
return self.length
@@ -23,8 +23,8 @@ def __iter__(self):
2323
return self
2424

2525
def next(self):
26-
'''Get the next order in the list.
27-
26+
'''Get the next order in the list.
27+
2828
Set self.last as the next order. If there is no next order, stop
2929
iterating through list.
3030
'''
@@ -59,7 +59,7 @@ def remove_order(self, order):
5959
self.length -= 1
6060
if len(self) == 0: # if there are no more Orders, stop/return
6161
return
62-
62+
6363
# Remove an Order from the OrderList. First grab next / prev order
6464
# from the Order we are removing. Then relink everything. Finally
6565
# remove the Order.
@@ -87,6 +87,10 @@ def move_to_tail(self, order):
8787

8888
order.next_order.prev_order = order.prev_order
8989

90+
# Added to resolve non termmination bug when traversing after modifying order with a larger quantity.
91+
order.prev_order = self.tail_order
92+
order.next_order = None
93+
9094
# Move Order to the last position. Link up the previous last position Order.
9195
self.tail_order.next_order = order
9296
self.tail_order = order
@@ -98,7 +102,3 @@ def __str__(self):
98102
temp_file.write("%s\n" % str(order))
99103
#temp_file.write("%s\n" % str(self.head_order))
100104
return temp_file.getvalue()
101-
102-
103-
104-

0 commit comments

Comments
 (0)