fix: dedicate a separate WS connection for private channels (fills + balance)
Book connections no longer subscribe to tradeOrdersV2 or /account/balance. A dedicated private WS connection is created as the last connection (index = connection_count - 1) with zero book subscriptions, only private channels. Decouples fill delivery from book connection health.
This commit is contained in:
parent
b0056f4b6b
commit
ccf6ff8670
11
src/main.c
11
src/main.c
|
|
@ -156,17 +156,18 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
uint32_t conns_needed = (n + 399) / 400;
|
uint32_t conns_needed = (n + 399) / 400;
|
||||||
if (conns_needed < 1) conns_needed = 1;
|
if (conns_needed < 1) conns_needed = 1;
|
||||||
if (conns_needed > WS_MAX_CONNECTIONS) conns_needed = WS_MAX_CONNECTIONS;
|
if (conns_needed >= WS_MAX_CONNECTIONS) conns_needed = WS_MAX_CONNECTIONS - 1;
|
||||||
ws_client.connection_count = conns_needed;
|
ws_client.connection_count = conns_needed + 1;
|
||||||
|
|
||||||
log_write("[MAIN] Connecting %u WS connections...\n", conns_needed);
|
log_write("[MAIN] Connecting %u WS connections (%u book + 1 private)...\n",
|
||||||
for (uint32_t i = 0; i < conns_needed; i++) {
|
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) {
|
if (ws_client_connect(&ws_client, i) != 0) {
|
||||||
log_write("[MAIN] WS connection %u failed\n", i);
|
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;
|
uint32_t batch_start = 0;
|
||||||
for (uint32_t conn_idx = 0; conn_idx < conns_needed; conn_idx++) {
|
for (uint32_t conn_idx = 0; conn_idx < conns_needed; conn_idx++) {
|
||||||
uint32_t batch_end = batch_start + 400;
|
uint32_t batch_end = batch_start + 400;
|
||||||
|
|
|
||||||
|
|
@ -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);
|
ws_client_subscribe(client, conn_idx, conn->symbol_indices, conn->symbol_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Subscribe to private channels — only on connection 0 to avoid
|
/* Subscribe to private channels — only on the dedicated private connection
|
||||||
duplicate delivery of order/balance events across connections */
|
(the last one, which has no book subscriptions). */
|
||||||
if (conn_idx == 0) {
|
if (conn_idx == client->connection_count - 1) {
|
||||||
char msg[256];
|
char msg[256];
|
||||||
snprintf(msg, sizeof(msg),
|
snprintf(msg, sizeof(msg),
|
||||||
"{\"type\":\"subscribe\",\"topic\":\"/spotMarket/tradeOrdersV2\","
|
"{\"type\":\"subscribe\",\"topic\":\"/spotMarket/tradeOrdersV2\","
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue