diag: Optimize logging in bybit exe gw plugin
* Format params as json (not python pseudo json) * Format params lazily
This commit is contained in:
1 parent
69e338c1ca
commit
e799b6e24b
1 file changed
+11
-11
@@ -196,7 +196,7 @@ class BybitExecutionGateway(ExecutionGateway):
|
||||
"channel_type": "private",
|
||||
"trace_logging": False,
|
||||
}
|
||||
self.logger.info("[bybit_gw_stream_sub.json]%s" % json.dumps(params))
|
||||
self.logger.info("[bybit_gw_stream_sub.json]%s" % JsonElement(params))
|
||||
self.stream_cli = WebSocket(**params)
|
||||
self.stream_cli.order_stream(on_order_update)
|
||||
self.stream_cli.execution_stream(on_exe_report)
|
||||
@@ -206,7 +206,7 @@ class BybitExecutionGateway(ExecutionGateway):
|
||||
"api_secret": self.secret_key,
|
||||
"testnet": self.use_testnet,
|
||||
}
|
||||
self.logger.info("[bybit_gw_start_trd_cli.json]%s" % json.dumps(params))
|
||||
self.logger.info("[bybit_gw_start_trd_cli.json]%s" % JsonElement(params))
|
||||
self.trade_cli = WebSocketTrading(**params)
|
||||
params = {
|
||||
"category": "linear",
|
||||
@@ -229,7 +229,7 @@ class BybitExecutionGateway(ExecutionGateway):
|
||||
logging.INFO
|
||||
if all(map(lambda kv: kv[1], conn_statuses.items()))
|
||||
else logging.WARNING,
|
||||
"[bybit_gw_connection_status.json]%s" % JsonElement(conn_statuses),
|
||||
"[bybit_gw_connection_status.json]%s" % SLog(**conn_statuses),
|
||||
)
|
||||
|
||||
def start(self, bridge: ExecutionGatewayBridge):
|
||||
@@ -241,7 +241,7 @@ class BybitExecutionGateway(ExecutionGateway):
|
||||
'[bybit_gw_start_err.json]{ "err": "%s" }' % str(e), exc_info=True
|
||||
)
|
||||
|
||||
self.logger.info("[bybit_gw_start.json]%s" % json.dumps({"ts": time.time_ns()}))
|
||||
self.logger.info("[bybit_gw_start.json]%s" % SLog())
|
||||
self.bridge = bridge
|
||||
threading.Thread(
|
||||
target=start_wrapper,
|
||||
@@ -250,11 +250,11 @@ class BybitExecutionGateway(ExecutionGateway):
|
||||
).start()
|
||||
|
||||
def stop(self):
|
||||
self.logger.info("[bybit_gw_stop.json]%s" % json.dumps({"ts": time.time_ns()}))
|
||||
self.logger.info("[bybit_gw_stop.json]%s" % SLog())
|
||||
self.stop_event.set()
|
||||
|
||||
def create_order(self, req: PyCreateOrderRequest):
|
||||
self.logger.info("[bybit_gw_crt_ord.json]%s" % str(req))
|
||||
self.logger.info("[bybit_gw_crt_ord.json]%s" % req)
|
||||
if not self.stream_cli or not self.trade_cli or not self.bridge:
|
||||
self._on_abort(
|
||||
req.key(),
|
||||
@@ -283,7 +283,7 @@ class BybitExecutionGateway(ExecutionGateway):
|
||||
"price": format_price(sec, px),
|
||||
"qty": format_quantity(sec, qty),
|
||||
}
|
||||
self.logger.info("[bybit_gw_crt_ord_send.json]%s" % json.dumps(params))
|
||||
self.logger.info("[bybit_gw_crt_ord_send.json]%s" % SLog(params=params))
|
||||
self.trade_cli.place_order(lambda msg: self._on_order_ack("crt", msg), **params)
|
||||
|
||||
def cancel_replace_order(self, req: PyCancelReplaceOrderRequest):
|
||||
@@ -307,12 +307,13 @@ class BybitExecutionGateway(ExecutionGateway):
|
||||
"price": format_price(sec, req.price()),
|
||||
"qty": format_quantity(sec, req.quantity()),
|
||||
}
|
||||
self.logger.info("[bybit_gw_cxlrep_ord_send.json]%s" % SLog(params=params))
|
||||
self.trade_cli.amend_order(
|
||||
lambda msg: self._on_order_ack("cxlrep", msg), **params
|
||||
)
|
||||
|
||||
def cancel_order(self, req: PyCancelOrderRequest):
|
||||
self.logger.info("[bybit_gw_cxl_ord.json]%s" % str(req))
|
||||
self.logger.info("[bybit_gw_cxl_ord.json]%s" % req)
|
||||
if not self.stream_cli or not self.trade_cli:
|
||||
self._on_abort(req.key(), "cxl", "WebSocket client not created.")
|
||||
return
|
||||
@@ -326,12 +327,11 @@ class BybitExecutionGateway(ExecutionGateway):
|
||||
"category": "linear",
|
||||
"symbol": req.exchange_security_id(),
|
||||
}
|
||||
self.logger.info("[bybit_gw_cxl_ord_send.json]%s" % SLog(params=params))
|
||||
self.trade_cli.cancel_order(
|
||||
lambda msg: self._on_order_ack("cxl", msg), **params
|
||||
)
|
||||
|
||||
def on_securities(self, securities: PySecurityList):
|
||||
self.logger.info(
|
||||
"[bybit_gw_sec.json][%s]" % ", ".join([str(sec) for sec in securities])
|
||||
)
|
||||
self.logger.info("[bybit_gw_sec.json]%s" % securities)
|
||||
self.securities = {sec.name(): sec for sec in securities}
|
||||
Reference in new issue
Block a user