diff --git a/src/main.c b/src/main.c index 1d14b46..aab1cd4 100644 --- a/src/main.c +++ b/src/main.c @@ -156,17 +156,18 @@ int main(int argc, char *argv[]) { uint32_t conns_needed = (n + 399) / 400; if (conns_needed < 1) conns_needed = 1; - if (conns_needed > WS_MAX_CONNECTIONS) conns_needed = WS_MAX_CONNECTIONS; - ws_client.connection_count = conns_needed; + if (conns_needed >= WS_MAX_CONNECTIONS) conns_needed = WS_MAX_CONNECTIONS - 1; + ws_client.connection_count = conns_needed + 1; - log_write("[MAIN] Connecting %u WS connections...\n", conns_needed); - for (uint32_t i = 0; i < conns_needed; i++) { + log_write("[MAIN] Connecting %u WS connections (%u book + 1 private)...\n", + ws_client.connection_count, conns_needed); + for (uint32_t i = 0; i < ws_client.connection_count; i++) { if (ws_client_connect(&ws_client, i) != 0) { log_write("[MAIN] WS connection %u failed\n", i); } } - // Batch-subscribe up to 400 symbols per WS connection + // Batch-subscribe up to 400 symbols per WS connection (book connections only) uint32_t batch_start = 0; for (uint32_t conn_idx = 0; conn_idx < conns_needed; conn_idx++) { uint32_t batch_end = batch_start + 400; diff --git a/src/ws_client.c b/src/ws_client.c index 2225b0d..d5c846b 100644 --- a/src/ws_client.c +++ b/src/ws_client.c @@ -403,9 +403,9 @@ int ws_client_connect(ws_client_t *client, uint32_t conn_idx) { ws_client_subscribe(client, conn_idx, conn->symbol_indices, conn->symbol_count); } - /* Subscribe to private channels — only on connection 0 to avoid - duplicate delivery of order/balance events across connections */ - if (conn_idx == 0) { + /* Subscribe to private channels — only on the dedicated private connection + (the last one, which has no book subscriptions). */ + if (conn_idx == client->connection_count - 1) { char msg[256]; snprintf(msg, sizeof(msg), "{\"type\":\"subscribe\",\"topic\":\"/spotMarket/tradeOrdersV2\","