aboutsummaryrefslogtreecommitdiffstats
path: root/packages/connect
diff options
context:
space:
mode:
Diffstat (limited to 'packages/connect')
-rw-r--r--packages/connect/src/schemas/websocket_orderbook_channel_config_schema.ts5
-rw-r--r--packages/connect/src/ws_orderbook_channel.ts12
2 files changed, 15 insertions, 2 deletions
diff --git a/packages/connect/src/schemas/websocket_orderbook_channel_config_schema.ts b/packages/connect/src/schemas/websocket_orderbook_channel_config_schema.ts
index 2e9987e63..81c0cac9c 100644
--- a/packages/connect/src/schemas/websocket_orderbook_channel_config_schema.ts
+++ b/packages/connect/src/schemas/websocket_orderbook_channel_config_schema.ts
@@ -2,6 +2,9 @@ export const webSocketOrderbookChannelConfigSchema = {
id: '/WebSocketOrderbookChannelConfig',
type: 'object',
properties: {
- heartbeatIntervalMs: { type: 'number' },
+ heartbeatIntervalMs: {
+ type: 'number',
+ minimum: 10,
+ },
},
};
diff --git a/packages/connect/src/ws_orderbook_channel.ts b/packages/connect/src/ws_orderbook_channel.ts
index 564e8686b..607749e86 100644
--- a/packages/connect/src/ws_orderbook_channel.ts
+++ b/packages/connect/src/ws_orderbook_channel.ts
@@ -16,6 +16,7 @@ import {
import { orderbookChannelMessageParser } from './utils/orderbook_channel_message_parser';
const DEFAULT_HEARTBEAT_INTERVAL_MS = 15000;
+const MINIMUM_HEARTBEAT_INTERVAL_MS = 10;
/**
* This class includes all the functionality related to interacting with a websocket endpoint
@@ -104,10 +105,19 @@ export class WebSocketOrderbookChannel implements OrderbookChannel {
} else {
this._client.on(WebsocketClientEventType.Connect, connection => {
this._connectionIfExists = connection;
- if (this._heartbeatIntervalMs !== 0) {
+ if (this._heartbeatIntervalMs >= MINIMUM_HEARTBEAT_INTERVAL_MS) {
this._heartbeatTimerIfExists = setInterval(() => {
connection.ping('');
}, this._heartbeatIntervalMs);
+ } else {
+ callback(
+ new Error(
+ `Heartbeat interval is ${
+ this._heartbeatIntervalMs
+ }ms which is less than the required minimum of ${MINIMUM_HEARTBEAT_INTERVAL_MS}ms`,
+ ),
+ undefined,
+ );
}
callback(undefined, this._connectionIfExists);
});