Skip to content

Commit 887d89d

Browse files
committed
Fix OKX WebSocket heartbeat and standardize logging
- Add 20-second heartbeat for OKX WebSocket clients (timeout is 30s) - Standardize reconnection log levels and verbosity
1 parent eed8f47 commit 887d89d

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

RELEASES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ This will be the final release with support for Python 3.11.
117117
- Fixed OKX fee calculations to account for negative fees
118118
- Fixed OKX parsing for `tick_sz` across instrument types
119119
- Fixed OKX parsing for instruments `multiplier` field
120+
- Fixed OKX WebSocket heartbeat and standardize logging
120121
- Fixed Polymarket handling of one-sided quotes (#2950), thanks for reporting @thefabus
121122
- Fixed Polymarket websocket message handling (#2963, #2968), thanks @thefabus
122123
- Fixed Polymarket tick size change handling for quotes (#2980), thanks for reporting @santivazq

crates/adapters/okx/src/websocket/client.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ impl OKXWebSocketClient {
544544
loop {
545545
match handler.next().await {
546546
Some(NautilusWsMessage::Reconnected) => {
547-
tracing::info!("Handling WebSocket reconnection");
547+
tracing::debug!("Handling WebSocket reconnection");
548548

549549
let auth_tracker_for_task = auth_tracker.clone();
550550
let inner_client_for_task = inner_client.clone();
@@ -586,7 +586,7 @@ impl OKXWebSocketClient {
586586
);
587587
auth_tracker.fail(e.to_string());
588588
} else {
589-
tracing::info!(
589+
tracing::debug!(
590590
"Sent re-authentication request, waiting for response before resubscribing",
591591
);
592592
}
@@ -612,7 +612,7 @@ impl OKXWebSocketClient {
612612
.await
613613
{
614614
Ok(()) => {
615-
tracing::info!(
615+
tracing::debug!(
616616
"Authentication successful after reconnect, proceeding with resubscription",
617617
);
618618
true
@@ -809,7 +809,7 @@ impl OKXWebSocketClient {
809809
}
810810
}
811811

812-
tracing::info!("Completed re-subscription after reconnect");
812+
tracing::debug!("Completed re-subscription after reconnect");
813813
} else {
814814
tracing::warn!(
815815
"Skipping resubscription after reconnect: websocket client unavailable",
@@ -3145,7 +3145,7 @@ impl OKXFeedHandler {
31453145

31463146
// Check for reconnection signal
31473147
if text == RECONNECTED {
3148-
tracing::info!("Received WebSocket reconnection signal");
3148+
tracing::debug!("Received WebSocket reconnection signal");
31493149
return Some(OKXWebSocketEvent::Reconnected);
31503150
}
31513151
tracing::trace!("Received WebSocket message: {text}");

nautilus_trader/adapters/okx/data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def __init__(
141141
api_key=None, # Public endpoints don't need authentication
142142
api_secret=None,
143143
api_passphrase=None,
144+
heartbeat=20,
144145
)
145146
self._ws_client_futures: set[asyncio.Future] = set()
146147

@@ -150,6 +151,7 @@ def __init__(
150151
api_key=config.api_key, # Business endpoint requires authentication
151152
api_secret=config.api_secret,
152153
api_passphrase=config.api_passphrase,
154+
heartbeat=20,
153155
)
154156
self._ws_business_client_futures: set[asyncio.Future] = set()
155157

nautilus_trader/adapters/okx/execution.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,14 @@ def __init__(
179179
self._ws_client = nautilus_pyo3.OKXWebSocketClient.with_credentials(
180180
url=config.base_url_ws or nautilus_pyo3.get_okx_ws_url_private(config.is_demo),
181181
account_id=self.pyo3_account_id,
182+
heartbeat=20,
182183
)
183184
self._ws_client_futures: set[asyncio.Future] = set()
184185

185186
self._ws_business_client = nautilus_pyo3.OKXWebSocketClient.with_credentials(
186187
url=nautilus_pyo3.get_okx_ws_url_business(config.is_demo),
187188
account_id=self.pyo3_account_id,
189+
heartbeat=20,
188190
)
189191
self._ws_business_client_futures: set[asyncio.Future] = set()
190192

0 commit comments

Comments
 (0)