feat: resolve and persist actual order venue
This commit is contained in:
@@ -285,13 +285,25 @@ class PostgreSQLSlotRepository:
|
||||
)
|
||||
return [self._row_to_slot(r) for r in cur.fetchall()]
|
||||
|
||||
def mark_dispatched(self, slot_id: UUID, broker_order_id: str) -> bool:
|
||||
def mark_dispatched(
|
||||
self,
|
||||
slot_id: UUID,
|
||||
broker_order_id: str,
|
||||
*,
|
||||
venue: Optional[str] = None,
|
||||
) -> bool:
|
||||
with self._psycopg.connect(self._dsn, autocommit=False) as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"UPDATE daily_slot SET broker_order_id=%s, updated_at=%s "
|
||||
"UPDATE daily_slot SET broker_order_id=%s, "
|
||||
"venue=COALESCE(%s, venue), updated_at=%s "
|
||||
"WHERE slot_id=%s AND broker_order_id IS NULL",
|
||||
(broker_order_id, datetime.now(tz=timezone.utc), slot_id),
|
||||
(
|
||||
broker_order_id,
|
||||
venue,
|
||||
datetime.now(tz=timezone.utc),
|
||||
slot_id,
|
||||
),
|
||||
)
|
||||
ok = cur.rowcount == 1
|
||||
conn.commit()
|
||||
@@ -456,7 +468,7 @@ class _PgIntentRecord:
|
||||
_OUTBOX_COLUMNS = (
|
||||
"correlation_id, asset_id, order_id, execution_id, side, qty, price, "
|
||||
"fee, tax, executed_at, status, attempts, last_outcome, last_error, "
|
||||
"created_at, updated_at, next_retry_at"
|
||||
"created_at, updated_at, next_retry_at, venue"
|
||||
)
|
||||
|
||||
|
||||
@@ -473,8 +485,8 @@ class PostgreSQLLedgerOutbox:
|
||||
cur.execute(
|
||||
"INSERT INTO ledger_outbox "
|
||||
"(correlation_id, asset_id, order_id, execution_id, side, "
|
||||
" qty, price, fee, tax, executed_at) "
|
||||
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) "
|
||||
" qty, price, fee, tax, executed_at, venue) "
|
||||
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) "
|
||||
"ON CONFLICT (correlation_id) DO NOTHING",
|
||||
(
|
||||
trade.correlation_id,
|
||||
@@ -487,6 +499,7 @@ class PostgreSQLLedgerOutbox:
|
||||
trade.fee,
|
||||
trade.tax,
|
||||
trade.executed_at,
|
||||
trade.venue,
|
||||
),
|
||||
)
|
||||
conn.commit()
|
||||
@@ -590,6 +603,7 @@ class PostgreSQLLedgerOutbox:
|
||||
fee=f(row[7]),
|
||||
tax=f(row[8]),
|
||||
executed_at=row[9],
|
||||
venue=row[17],
|
||||
)
|
||||
return LedgerWorkItem(
|
||||
correlation_id=row[0],
|
||||
|
||||
Reference in New Issue
Block a user