Skip to content

Commit

Permalink
Update order regression fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wtindall1 committed Nov 10, 2024
1 parent e7226f5 commit c1bddde
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Algorithm.Python/UpdateOrderRegressionAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ def on_data(self, data):
ticket = self.tickets[-1]

if self.time.day > 8 and self.time.day < 14:
if len(ticket.update_requests) == 0 and ticket.status is not OrderStatus.FILLED:
if len(ticket.update_requests) == 0 and self.is_open(ticket):
self.log("TICKET:: {0}".format(ticket))
update_order_fields = UpdateOrderFields()
update_order_fields.quantity = ticket.quantity + copysign(self.delta_quantity, self.quantity)
update_order_fields.tag = "Change quantity: {0}".format(self.time.day)
ticket.update(update_order_fields)

elif self.time.day > 13 and self.time.day < 20:
if len(ticket.update_requests) == 1 and ticket.status is not OrderStatus.FILLED:
if len(ticket.update_requests) == 1 and self.is_open(ticket):
self.log("TICKET:: {0}".format(ticket))
update_order_fields = UpdateOrderFields()
update_order_fields.limit_price = self.security.price*(1 - copysign(self.limit_percentage_delta, ticket.quantity)) \
Expand All @@ -99,7 +99,7 @@ def on_data(self, data):
update_order_fields.tag = "Change prices: {0}".format(self.time.day)
ticket.update(update_order_fields)
else:
if len(ticket.update_requests) == 2 and ticket.status is not OrderStatus.FILLED:
if len(ticket.update_requests) == 2 and self.is_open(ticket):
self.log("TICKET:: {0}".format(ticket))
ticket.cancel("{0} and is still open!".format(self.time.day))
self.log("CANCELLED:: {0}".format(ticket.cancel_request))
Expand All @@ -126,3 +126,6 @@ def on_order_event(self, orderEvent):
else:
self.log(orderEvent.to_string())
self.log("TICKET:: {0}".format(ticket))

def is_open(self, order_ticket):
return order_ticket.status not in (OrderStatus.FILLED, OrderStatus.CANCELED, OrderStatus.INVALID)

0 comments on commit c1bddde

Please sign in to comment.