@@ -2,7 +2,7 @@ class OrderList(object):
2
2
'''
3
3
A doubly linked list of Orders. Used to iterate through Orders when
4
4
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
6
6
Order, we may need multiple Orders to fullfill a transaction. The
7
7
OrderList makes this easy to do. OrderList is naturally arranged by time.
8
8
Orders at the front of the list have priority.
@@ -13,7 +13,7 @@ def __init__(self):
13
13
self .tail_order = None # last order in the list
14
14
self .length = 0 # number of Orders in the list
15
15
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
17
17
18
18
def __len__ (self ):
19
19
return self .length
@@ -23,8 +23,8 @@ def __iter__(self):
23
23
return self
24
24
25
25
def next (self ):
26
- '''Get the next order in the list.
27
-
26
+ '''Get the next order in the list.
27
+
28
28
Set self.last as the next order. If there is no next order, stop
29
29
iterating through list.
30
30
'''
@@ -59,7 +59,7 @@ def remove_order(self, order):
59
59
self .length -= 1
60
60
if len (self ) == 0 : # if there are no more Orders, stop/return
61
61
return
62
-
62
+
63
63
# Remove an Order from the OrderList. First grab next / prev order
64
64
# from the Order we are removing. Then relink everything. Finally
65
65
# remove the Order.
@@ -87,6 +87,10 @@ def move_to_tail(self, order):
87
87
88
88
order .next_order .prev_order = order .prev_order
89
89
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
+
90
94
# Move Order to the last position. Link up the previous last position Order.
91
95
self .tail_order .next_order = order
92
96
self .tail_order = order
@@ -98,7 +102,3 @@ def __str__(self):
98
102
temp_file .write ("%s\n " % str (order ))
99
103
#temp_file.write("%s\n" % str(self.head_order))
100
104
return temp_file .getvalue ()
101
-
102
-
103
-
104
-
0 commit comments