Skip to content

Commit

Permalink
Merge pull request #1214 from tgibson11/missing-data-6
Browse files Browse the repository at this point in the history
Replace fill_exceeds_trade named_object with exception
  • Loading branch information
robcarver17 committed Jul 9, 2023
2 parents 0ccbca9 + cc691f7 commit f8c7ef7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
1 change: 0 additions & 1 deletion syscore/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def __repr__(self):
return self._name


fill_exceeds_trade = named_object("fill too big for trade")
arg_not_supplied = named_object("arg not supplied")
user_exit = named_object("exit")

Expand Down
4 changes: 4 additions & 0 deletions syscore/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class marketClosed(Exception):
pass


class fillExceedsTrade(Exception):
pass


class existingData(Exception):
pass

Expand Down
5 changes: 1 addition & 4 deletions sysexecution/order_stacks/broker_order_stack.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime

from syscore.constants import fill_exceeds_trade
from sysexecution.orders.named_order_objects import missing_order
from sysexecution.order_stacks.order_stack import orderStackData
from sysexecution.orders.broker_orders import brokerOrder
Expand All @@ -16,11 +15,9 @@ def add_execution_details_from_matched_broker_order(
self, broker_order_id: int, matched_broker_order: brokerOrder
):
db_broker_order = self.get_order_with_id_from_stack(broker_order_id)
result = db_broker_order.add_execution_details_from_matched_broker_order(
db_broker_order.add_execution_details_from_matched_broker_order(
matched_broker_order
)
if result is fill_exceeds_trade:
return fill_exceeds_trade

self._change_order_on_stack(broker_order_id, db_broker_order)

Expand Down
5 changes: 3 additions & 2 deletions sysexecution/orders/broker_orders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime

from syscore.exceptions import fillExceedsTrade
from sysexecution.orders.named_order_objects import (
missing_order,
no_order_id,
Expand All @@ -26,7 +27,7 @@
if_empty_string_return_object,
if_object_matches_return_empty_string,
)
from syscore.constants import fill_exceeds_trade, success
from syscore.constants import success


class brokerOrderType(orderType):
Expand Down Expand Up @@ -355,7 +356,7 @@ def add_execution_details_from_matched_broker_order(self, matched_broker_order):
matched_broker_order.fill
)
if not fill_qty_okay:
return fill_exceeds_trade
raise fillExceedsTrade
self.fill_order(
matched_broker_order.fill,
filled_price=matched_broker_order.filled_price,
Expand Down
14 changes: 7 additions & 7 deletions sysexecution/stack_handler/fills.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
import numpy as np
from syscore.constants import fill_exceeds_trade
from syscore.exceptions import fillExceedsTrade
from sysexecution.orders.named_order_objects import (
missing_order,
no_order_id,
Expand Down Expand Up @@ -79,12 +79,12 @@ def apply_broker_order_fills_to_database(
data_broker.calculate_total_commission_for_broker_order(broker_order)
)

# This will add commissions, fills, etc
result = self.broker_stack.add_execution_details_from_matched_broker_order(
broker_order_id, broker_order_with_commissions
)

if result is fill_exceeds_trade:
try:
# This will add commissions, fills, etc
self.broker_stack.add_execution_details_from_matched_broker_order(
broker_order_id, broker_order_with_commissions
)
except fillExceedsTrade:
self.log.warning(
"Fill for exceeds trade for %s, ignoring fill... (hopefully will go away)"
% (broker_order)
Expand Down

0 comments on commit f8c7ef7

Please sign in to comment.