Skip to content

Commit 01ce598

Browse files
committed
move get_uid_trades function to orderbook api
it is used in two tests and only depends on the orderbook api at the moment.
1 parent 6d3e910 commit 01ce598

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/apis/orderbookapi.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ def get_trade(
110110
)
111111
return Trade(data, execution)
112112

113+
def get_uid_trades(self, solution: dict[str, Any]) -> dict[str, Trade] | None:
114+
"""Get a dictionary mapping UIDs to trades in a solution."""
115+
trades_dict: dict[str, Trade] = {}
116+
for execution in solution["orders"]:
117+
uid = execution["id"]
118+
order_data = self.get_order_data(uid)
119+
if order_data is None:
120+
return None
121+
trades_dict[uid] = self.get_trade(order_data, execution)
122+
123+
return trades_dict
124+
113125
def get_quote(self, trade: Trade) -> Optional[Trade]:
114126
"""
115127
Given a trade, compute buy_amount, sell_amount, and fee_amount of the trade

src/monitoring_tests/solver_competition_surplus_test.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def compare_orders_surplus(self, competition_data: dict[str, Any]) -> bool:
3030

3131
solution = competition_data["solutions"][-1]
3232

33-
trades_dict = self.get_uid_trades(solution)
33+
trades_dict = self.orderbook_api.get_uid_trades(solution)
3434
if trades_dict is None:
3535
return False
3636

@@ -98,18 +98,6 @@ def get_trade_alternatives(
9898

9999
return trade_alt_list
100100

101-
def get_uid_trades(self, solution: dict[str, Any]) -> dict[str, Trade] | None:
102-
"""Get a dictionary mapping UIDs to trades in a solution."""
103-
trades_dict: dict[str, Trade] = {}
104-
for execution in solution["orders"]:
105-
uid = execution["id"]
106-
order_data = self.orderbook_api.get_order_data(uid)
107-
if order_data is None:
108-
return None
109-
trades_dict[uid] = self.orderbook_api.get_trade(order_data, execution)
110-
111-
return trades_dict
112-
113101
def get_uid_order_execution(
114102
self, solution: dict[str, Any]
115103
) -> dict[str, OrderExecution]:

0 commit comments

Comments
 (0)