Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 7 additions & 27 deletions src/lib/BaseWSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { WSTopic } from '../types/websockets/ws-subscriptions.js';
import { checkWebCryptoAPISupported } from './webCryptoAPI.js';
import { DefaultLogger } from './websocket/logger.js';
import {
getNormalisedTopicRequests,
safeTerminateWs,
WSOperation,
WSTopicRequest,
Expand Down Expand Up @@ -155,33 +156,6 @@ function getFinalEmittable(
};
}

/**
* Users can conveniently pass topics as strings or objects (object has topic name + optional params).
*
* This method normalises topics into objects (object has topic name + optional params).
*/
function getNormalisedTopicRequests(
wsTopicRequests: WSTopicRequestOrStringTopic<WSTopic>[],
): WSTopicRequest<WSTopic>[] {
const normalisedTopicRequests: WSTopicRequest<WSTopic>[] = [];

for (const wsTopicRequest of wsTopicRequests) {
// passed as string, convert to object
if (typeof wsTopicRequest === 'string') {
const topicRequest: WSTopicRequest<WSTopic> = {
topic: wsTopicRequest as WSTopic,
payload: undefined,
};
normalisedTopicRequests.push(topicRequest);
continue;
}

// already a normalised object, thanks to user
normalisedTopicRequests.push(wsTopicRequest);
}
return normalisedTopicRequests;
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export abstract class BaseWebsocketClient<
TWSKey extends string,
Expand Down Expand Up @@ -218,15 +192,20 @@ export abstract class BaseWebsocketClient<
pingInterval: 10000,
reconnectTimeout: 500,
recvWindow: 5000,

// Requires a confirmation "response" from the ws connection before assuming it is ready
requireConnectionReadyConfirmation: false,

// Automatically auth after opening a connection?
authPrivateConnectionsOnConnect: false,

// Automatically include auth/sign/token with every WS request.
// Automatically handled during getWsRequestEvents.
authPrivateRequests: true,

// Automatically re-auth WS API, if we were auth'd before and get reconnected
reauthWSAPIOnReconnect: true,

// Whether to use native heartbeats (depends on the exchange)
useNativeHeartbeats: true,

Expand Down Expand Up @@ -1112,6 +1091,7 @@ export abstract class BaseWebsocketClient<
} catch (e) {
this.logger.error(
'Exception trying to resolve "connectionInProgress" promise',
e,
);
}
}
Expand Down
27 changes: 27 additions & 0 deletions src/lib/websocket/websocket-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,30 @@ export function getPromiseRefForWSAPIRequest(
);
return promiseRef;
}

/**
* Users can conveniently pass topics as strings or objects (object has topic name + optional params).
*
* This method normalises topics into objects (object has topic name + optional params).
*/
export function getNormalisedTopicRequests(
wsTopicRequests: WSTopicRequestOrStringTopic<WSTopic>[],
): WSTopicRequest<WSTopic>[] {
const normalisedTopicRequests: WSTopicRequest<WSTopic>[] = [];

for (const wsTopicRequest of wsTopicRequests) {
// passed as string, convert to object
if (typeof wsTopicRequest === 'string') {
const topicRequest: WSTopicRequest<WSTopic> = {
topic: wsTopicRequest as WSTopic,
payload: undefined,
};
normalisedTopicRequests.push(topicRequest);
continue;
}

// already a normalised object, thanks to user
normalisedTopicRequests.push(wsTopicRequest);
}
return normalisedTopicRequests;
}
10 changes: 8 additions & 2 deletions test/REST/private.futures.write.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,17 @@ describe('REST PRIVATE FUTURES WRITE', () => {
});
} catch (e: any) {
// Expected - validates signature is correct
//console.log(`err "${expect.getState().currentTestName}"`, e?.body || e);
// console.log(`err "${expect.getState().currentTestName}"`, e?.body || e);
const responseBody = e?.body;

expect(responseBody).toMatchObject({
result: 'error',
error: expect.stringContaining('invalidArgument'),
});

const firstError = responseBody?.errors?.[0];
expect(firstError).toMatchObject({
code: expect.any(Number),
message: expect.stringContaining('Invalid UUID'),
});
}
});
Expand Down