Skip to content

Commit 66da907

Browse files
committed
Refine order status report logging
1 parent 95d6d6a commit 66da907

File tree

8 files changed

+55
-27
lines changed

8 files changed

+55
-27
lines changed

nautilus_trader/adapters/binance/execution.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from nautilus_trader.common.component import LiveClock
4141
from nautilus_trader.common.component import MessageBus
4242
from nautilus_trader.common.enums import LogColor
43+
from nautilus_trader.common.enums import LogLevel
4344
from nautilus_trader.common.providers import InstrumentProvider
4445
from nautilus_trader.core.correctness import PyCondition
4546
from nautilus_trader.core.datetime import nanos_to_millis
@@ -490,10 +491,14 @@ async def generate_order_status_reports(
490491
self._log.debug(f"Received {reports}")
491492
reports.append(report)
492493

493-
if command.log_received:
494-
len_reports = len(reports)
495-
plural = "" if len_reports == 1 else "s"
496-
self._log.info(f"Received {len(reports)} OrderStatusReport{plural}")
494+
len_reports = len(reports)
495+
plural = "" if len_reports == 1 else "s"
496+
receipt_log = f"Received {len(reports)} OrderStatusReport{plural}"
497+
498+
if command.log_receipt_level == LogLevel.INFO:
499+
self._log.info(receipt_log)
500+
else:
501+
self._log.debug(receipt_log)
497502

498503
return reports
499504

nautilus_trader/adapters/bybit/execution.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from nautilus_trader.adapters.bybit.schemas.ws import BybitWsMessageGeneral
4747
from nautilus_trader.adapters.bybit.websocket.client import BybitWebSocketClient
4848
from nautilus_trader.common.enums import LogColor
49+
from nautilus_trader.common.enums import LogLevel
4950
from nautilus_trader.core.correctness import PyCondition
5051
from nautilus_trader.core.datetime import millis_to_nanos
5152
from nautilus_trader.core.uuid import UUID4
@@ -346,10 +347,14 @@ async def generate_order_status_reports(
346347
except BybitError as e:
347348
self._log.error(f"Failed to generate OrderStatusReports: {e}")
348349

349-
if command.log_received:
350-
len_reports = len(reports)
351-
plural = "" if len_reports == 1 else "s"
352-
self._log.info(f"Received {len(reports)} OrderStatusReport{plural}")
350+
len_reports = len(reports)
351+
plural = "" if len_reports == 1 else "s"
352+
receipt_log = f"Received {len(reports)} OrderStatusReport{plural}"
353+
354+
if command.log_receipt_level == LogLevel.INFO:
355+
self._log.info(receipt_log)
356+
else:
357+
self._log.debug(receipt_log)
353358

354359
return reports
355360

nautilus_trader/adapters/dydx/execution.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
from nautilus_trader.common.component import Logger
6666
from nautilus_trader.common.component import MessageBus
6767
from nautilus_trader.common.enums import LogColor
68+
from nautilus_trader.common.enums import LogLevel
6869
from nautilus_trader.core.correctness import PyCondition
6970
from nautilus_trader.core.datetime import dt_to_unix_nanos
7071
from nautilus_trader.core.datetime import nanos_to_secs
@@ -579,10 +580,14 @@ async def generate_order_status_reports(
579580
else:
580581
self._log.error("Failed to generate OrderStatusReports")
581582

582-
if command.log_received:
583-
len_reports = len(reports)
584-
plural = "" if len_reports == 1 else "s"
585-
self._log.info(f"Received {len(reports)} OrderStatusReport{plural}")
583+
len_reports = len(reports)
584+
plural = "" if len_reports == 1 else "s"
585+
receipt_log = f"Received {len(reports)} OrderStatusReport{plural}"
586+
587+
if command.log_receipt_level == LogLevel.INFO:
588+
self._log.info(receipt_log)
589+
else:
590+
self._log.debug(receipt_log)
586591

587592
return reports
588593

nautilus_trader/adapters/okx/execution.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
from nautilus_trader.common.component import LiveClock
5757
from nautilus_trader.common.component import MessageBus
5858
from nautilus_trader.common.enums import LogColor
59+
from nautilus_trader.common.enums import LogLevel
5960
from nautilus_trader.core.correctness import PyCondition
6061
from nautilus_trader.core.datetime import millis_to_nanos
6162
from nautilus_trader.core.datetime import unix_nanos_to_dt
@@ -499,10 +500,14 @@ async def generate_order_status_reports( # noqa: C901
499500
filter(lambda r: unix_nanos_to_dt(r.ts_accepted) <= command.end, reports),
500501
)
501502

502-
if command.log_received:
503-
len_reports = len(reports)
504-
plural = "" if len_reports == 1 else "s"
505-
self._log.info(f"Received {len(reports)} OrderStatusReport{plural}")
503+
len_reports = len(reports)
504+
plural = "" if len_reports == 1 else "s"
505+
receipt_log = f"Received {len(reports)} OrderStatusReport{plural}"
506+
507+
if command.log_receipt_level == LogLevel.INFO:
508+
self._log.info(receipt_log)
509+
else:
510+
self._log.debug(receipt_log)
506511

507512
return reports
508513

nautilus_trader/adapters/polymarket/execution.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from nautilus_trader.common.component import LiveClock
5858
from nautilus_trader.common.component import MessageBus
5959
from nautilus_trader.common.enums import LogColor
60+
from nautilus_trader.common.enums import LogLevel
6061
from nautilus_trader.core.datetime import millis_to_nanos
6162
from nautilus_trader.core.datetime import nanos_to_secs
6263
from nautilus_trader.core.stats import basis_points_as_percentage
@@ -475,10 +476,14 @@ async def generate_order_status_reports( # noqa: C901
475476
self._log.warning(f"Generated from fill report: {report}")
476477
reports.append(report)
477478

478-
if command.log_received:
479-
len_reports = len(reports)
480-
plural = "" if len_reports == 1 else "s"
481-
self._log.info(f"Received {len(reports)} OrderStatusReport{plural}")
479+
len_reports = len(reports)
480+
plural = "" if len_reports == 1 else "s"
481+
receipt_log = f"Received {len(reports)} OrderStatusReport{plural}"
482+
483+
if command.log_receipt_level == LogLevel.INFO:
484+
self._log.info(receipt_log)
485+
else:
486+
self._log.debug(receipt_log)
482487

483488
return reports
484489

nautilus_trader/execution/messages.pxd

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from cpython.datetime cimport datetime
1717

1818
from nautilus_trader.core.message cimport Command
19+
from nautilus_trader.core.rust.common cimport LogLevel
1920
from nautilus_trader.core.rust.model cimport OrderSide
2021
from nautilus_trader.model.identifiers cimport ClientId
2122
from nautilus_trader.model.identifiers cimport ClientOrderId
@@ -52,8 +53,8 @@ cdef class GenerateOrderStatusReport(TradingReportCommand):
5253
cdef class GenerateOrderStatusReports(TradingReportCommand):
5354
cdef readonly bint open_only
5455
"""If the request is only for open orders.\n\n:returns: `bool`"""
55-
cdef readonly bint log_received
56-
"""Whether the client should log receipt of the reports.\n\n:returns: `bool`"""
56+
cdef readonly LogLevel log_receipt_level
57+
"""The log level for logging received reports.\n\n:returns: `LogLevel`"""
5758

5859

5960
cdef class GenerateFillReports(TradingReportCommand):

nautilus_trader/execution/messages.pyx

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ from cpython.datetime cimport datetime
1919
from libc.stdint cimport uint64_t
2020

2121
from nautilus_trader.core.correctness cimport Condition
22+
from nautilus_trader.core.rust.common cimport LogLevel
2223
from nautilus_trader.core.rust.model cimport TriggerType
2324
from nautilus_trader.core.uuid cimport UUID4
2425
from nautilus_trader.model.events.order cimport OrderInitialized
@@ -139,8 +140,8 @@ cdef class GenerateOrderStatusReports(TradingReportCommand):
139140
UNIX timestamp (nanoseconds) when the object was initialized.
140141
params : dict[str, object], optional
141142
Additional parameters for the command.
142-
log_received : bool, default True
143-
Whether the client should log receipt of the reports.
143+
log_receipt_level : LogLevel, default 'INFO'
144+
The log level for logging received reports. Must be either `LogLevel.DEBUG` or `LogLevel.INFO`.
144145
"""
145146

146147
def __init__(
@@ -152,7 +153,7 @@ cdef class GenerateOrderStatusReports(TradingReportCommand):
152153
UUID4 command_id not None,
153154
uint64_t ts_init,
154155
dict[str, object] params: dict | None = None,
155-
bint log_received = True,
156+
LogLevel log_receipt_level = LogLevel.INFO,
156157
) -> None:
157158
super().__init__(
158159
instrument_id,
@@ -164,7 +165,7 @@ cdef class GenerateOrderStatusReports(TradingReportCommand):
164165
)
165166

166167
self.open_only = open_only
167-
self.log_received = log_received
168+
self.log_receipt_level = log_receipt_level
168169

169170

170171
cdef class GenerateFillReports(TradingReportCommand):

nautilus_trader/live/execution_engine.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from nautilus_trader.common.component import LiveClock
2727
from nautilus_trader.common.component import MessageBus
2828
from nautilus_trader.common.enums import LogColor
29+
from nautilus_trader.common.enums import LogLevel
2930
from nautilus_trader.config import LiveExecEngineConfig
3031
from nautilus_trader.core.correctness import PyCondition
3132
from nautilus_trader.core.datetime import dt_to_unix_nanos
@@ -535,7 +536,7 @@ async def _check_open_orders(self) -> None:
535536
open_only=self.open_check_open_only,
536537
command_id=UUID4(),
537538
ts_init=self._clock.timestamp_ns(),
538-
log_received=False,
539+
log_receipt_level=LogLevel.DEBUG,
539540
),
540541
)
541542
for c in clients

0 commit comments

Comments
 (0)