@nightlylabs/dex-sdk 0.3.39 → 0.3.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +36 -4
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +36 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -23936,6 +23936,8 @@ var getRandomId = () => (0, import_uuid.v7)();
|
|
|
23936
23936
|
var Client = class _Client {
|
|
23937
23937
|
constructor(connection, config = {}) {
|
|
23938
23938
|
this._apiKeySequenceNumber = 0;
|
|
23939
|
+
this._pingIntervalMs = 3e4;
|
|
23940
|
+
this._lastPongAt = 0;
|
|
23939
23941
|
this._subscriptions = /* @__PURE__ */ new Map();
|
|
23940
23942
|
this._gasUnitPrice = 100;
|
|
23941
23943
|
this._expirationTimestampDelay = 20;
|
|
@@ -24395,6 +24397,7 @@ var Client = class _Client {
|
|
|
24395
24397
|
this._expirationTimestampDelay = config.params?.expirationTimestampSecs || 20;
|
|
24396
24398
|
this.wsDebug = config.wsDebug || false;
|
|
24397
24399
|
this.timeout = config.timeout || 5e3;
|
|
24400
|
+
this._pingIntervalMs = config.pingIntervalMs || 3e4;
|
|
24398
24401
|
}
|
|
24399
24402
|
static async init(connection, config = {}) {
|
|
24400
24403
|
const id = config.chainId || await connection.getChainId();
|
|
@@ -24504,6 +24507,12 @@ var Client = class _Client {
|
|
|
24504
24507
|
}
|
|
24505
24508
|
_setupWebSocketHandlers() {
|
|
24506
24509
|
if (!this._ws) return;
|
|
24510
|
+
this._lastPongAt = Date.now();
|
|
24511
|
+
this._pingInterval = setInterval(() => {
|
|
24512
|
+
if (this._ws && this._ws.readyState === WebSocket.OPEN) {
|
|
24513
|
+
this._ws.send(JSON.stringify({ type: "Ping" }));
|
|
24514
|
+
}
|
|
24515
|
+
}, this._pingIntervalMs);
|
|
24507
24516
|
this._ws.onmessage = async (msg) => {
|
|
24508
24517
|
let data;
|
|
24509
24518
|
if (msg.data.arrayBuffer) {
|
|
@@ -24513,6 +24522,10 @@ var Client = class _Client {
|
|
|
24513
24522
|
}
|
|
24514
24523
|
const decodedMsg = JSON.parse(data);
|
|
24515
24524
|
this._wsLog("Received:", decodedMsg.type, decodedMsg.content);
|
|
24525
|
+
if (data === '{"type":"Pong"}') {
|
|
24526
|
+
this._lastPongAt = Date.now();
|
|
24527
|
+
return;
|
|
24528
|
+
}
|
|
24516
24529
|
const topic = getTopicFromMessage(decodedMsg);
|
|
24517
24530
|
const callback = this._subscriptions.get(topic);
|
|
24518
24531
|
if (callback) {
|
|
@@ -24528,6 +24541,10 @@ var Client = class _Client {
|
|
|
24528
24541
|
"clean=" + event.wasClean
|
|
24529
24542
|
);
|
|
24530
24543
|
this._ws = void 0;
|
|
24544
|
+
if (this._pingInterval) {
|
|
24545
|
+
clearInterval(this._pingInterval);
|
|
24546
|
+
this._pingInterval = void 0;
|
|
24547
|
+
}
|
|
24531
24548
|
this._subscriptions.clear();
|
|
24532
24549
|
this.onWsClose?.(event);
|
|
24533
24550
|
};
|
|
@@ -24541,15 +24558,30 @@ var Client = class _Client {
|
|
|
24541
24558
|
return;
|
|
24542
24559
|
}
|
|
24543
24560
|
this._wsLog("Disconnecting, clearing", this._subscriptions.size, "subscriptions");
|
|
24561
|
+
if (this._pingInterval) {
|
|
24562
|
+
clearInterval(this._pingInterval);
|
|
24563
|
+
this._pingInterval = void 0;
|
|
24564
|
+
}
|
|
24544
24565
|
this._subscriptions.clear();
|
|
24545
24566
|
this._ws.close();
|
|
24546
24567
|
this._ws = void 0;
|
|
24547
24568
|
}
|
|
24548
|
-
// Method to check if WebSocket is connected
|
|
24569
|
+
// Method to check if WebSocket is connected and responsive
|
|
24549
24570
|
isWebSocketConnected() {
|
|
24550
|
-
|
|
24551
|
-
|
|
24552
|
-
|
|
24571
|
+
if (!this._ws || this._ws.readyState !== WebSocket.OPEN) {
|
|
24572
|
+
this._wsLog("isWebSocketConnected: false (not open)");
|
|
24573
|
+
return false;
|
|
24574
|
+
}
|
|
24575
|
+
const pongTimeout = this._pingIntervalMs * 2;
|
|
24576
|
+
const alive = Date.now() - this._lastPongAt < pongTimeout;
|
|
24577
|
+
this._wsLog(
|
|
24578
|
+
"isWebSocketConnected:",
|
|
24579
|
+
alive,
|
|
24580
|
+
"lastPong:",
|
|
24581
|
+
Date.now() - this._lastPongAt,
|
|
24582
|
+
"ms ago"
|
|
24583
|
+
);
|
|
24584
|
+
return alive;
|
|
24553
24585
|
}
|
|
24554
24586
|
sendWsMessage(message) {
|
|
24555
24587
|
if (!this._ws) throw new Error("WebSocket is not connected");
|
package/dist/index.d.cts
CHANGED
|
@@ -5467,6 +5467,7 @@ interface ClientConfig {
|
|
|
5467
5467
|
networkMode?: NetworkMode;
|
|
5468
5468
|
wsDebug?: boolean;
|
|
5469
5469
|
timeout?: number;
|
|
5470
|
+
pingIntervalMs?: number;
|
|
5470
5471
|
}
|
|
5471
5472
|
interface ChangePerpOrderParams {
|
|
5472
5473
|
userId: string;
|
|
@@ -5777,6 +5778,9 @@ declare class Client {
|
|
|
5777
5778
|
_apiKey: Account;
|
|
5778
5779
|
_apiKeySequenceNumber: number;
|
|
5779
5780
|
_ws: WebSocket | undefined;
|
|
5781
|
+
_pingInterval: ReturnType<typeof setInterval> | undefined;
|
|
5782
|
+
_pingIntervalMs: number;
|
|
5783
|
+
_lastPongAt: number;
|
|
5780
5784
|
_serverUrl: string;
|
|
5781
5785
|
_subscriptions: Map<string, (data: WsMessage) => void>;
|
|
5782
5786
|
_sequenceNumberManager: AccountSequenceNumber;
|
package/dist/index.d.ts
CHANGED
|
@@ -5467,6 +5467,7 @@ interface ClientConfig {
|
|
|
5467
5467
|
networkMode?: NetworkMode;
|
|
5468
5468
|
wsDebug?: boolean;
|
|
5469
5469
|
timeout?: number;
|
|
5470
|
+
pingIntervalMs?: number;
|
|
5470
5471
|
}
|
|
5471
5472
|
interface ChangePerpOrderParams {
|
|
5472
5473
|
userId: string;
|
|
@@ -5777,6 +5778,9 @@ declare class Client {
|
|
|
5777
5778
|
_apiKey: Account;
|
|
5778
5779
|
_apiKeySequenceNumber: number;
|
|
5779
5780
|
_ws: WebSocket | undefined;
|
|
5781
|
+
_pingInterval: ReturnType<typeof setInterval> | undefined;
|
|
5782
|
+
_pingIntervalMs: number;
|
|
5783
|
+
_lastPongAt: number;
|
|
5780
5784
|
_serverUrl: string;
|
|
5781
5785
|
_subscriptions: Map<string, (data: WsMessage) => void>;
|
|
5782
5786
|
_sequenceNumberManager: AccountSequenceNumber;
|
package/dist/index.js
CHANGED
|
@@ -23894,6 +23894,8 @@ var getRandomId = () => uuidv7();
|
|
|
23894
23894
|
var Client = class _Client {
|
|
23895
23895
|
constructor(connection, config = {}) {
|
|
23896
23896
|
this._apiKeySequenceNumber = 0;
|
|
23897
|
+
this._pingIntervalMs = 3e4;
|
|
23898
|
+
this._lastPongAt = 0;
|
|
23897
23899
|
this._subscriptions = /* @__PURE__ */ new Map();
|
|
23898
23900
|
this._gasUnitPrice = 100;
|
|
23899
23901
|
this._expirationTimestampDelay = 20;
|
|
@@ -24353,6 +24355,7 @@ var Client = class _Client {
|
|
|
24353
24355
|
this._expirationTimestampDelay = config.params?.expirationTimestampSecs || 20;
|
|
24354
24356
|
this.wsDebug = config.wsDebug || false;
|
|
24355
24357
|
this.timeout = config.timeout || 5e3;
|
|
24358
|
+
this._pingIntervalMs = config.pingIntervalMs || 3e4;
|
|
24356
24359
|
}
|
|
24357
24360
|
static async init(connection, config = {}) {
|
|
24358
24361
|
const id = config.chainId || await connection.getChainId();
|
|
@@ -24462,6 +24465,12 @@ var Client = class _Client {
|
|
|
24462
24465
|
}
|
|
24463
24466
|
_setupWebSocketHandlers() {
|
|
24464
24467
|
if (!this._ws) return;
|
|
24468
|
+
this._lastPongAt = Date.now();
|
|
24469
|
+
this._pingInterval = setInterval(() => {
|
|
24470
|
+
if (this._ws && this._ws.readyState === WebSocket.OPEN) {
|
|
24471
|
+
this._ws.send(JSON.stringify({ type: "Ping" }));
|
|
24472
|
+
}
|
|
24473
|
+
}, this._pingIntervalMs);
|
|
24465
24474
|
this._ws.onmessage = async (msg) => {
|
|
24466
24475
|
let data;
|
|
24467
24476
|
if (msg.data.arrayBuffer) {
|
|
@@ -24471,6 +24480,10 @@ var Client = class _Client {
|
|
|
24471
24480
|
}
|
|
24472
24481
|
const decodedMsg = JSON.parse(data);
|
|
24473
24482
|
this._wsLog("Received:", decodedMsg.type, decodedMsg.content);
|
|
24483
|
+
if (data === '{"type":"Pong"}') {
|
|
24484
|
+
this._lastPongAt = Date.now();
|
|
24485
|
+
return;
|
|
24486
|
+
}
|
|
24474
24487
|
const topic = getTopicFromMessage(decodedMsg);
|
|
24475
24488
|
const callback = this._subscriptions.get(topic);
|
|
24476
24489
|
if (callback) {
|
|
@@ -24486,6 +24499,10 @@ var Client = class _Client {
|
|
|
24486
24499
|
"clean=" + event.wasClean
|
|
24487
24500
|
);
|
|
24488
24501
|
this._ws = void 0;
|
|
24502
|
+
if (this._pingInterval) {
|
|
24503
|
+
clearInterval(this._pingInterval);
|
|
24504
|
+
this._pingInterval = void 0;
|
|
24505
|
+
}
|
|
24489
24506
|
this._subscriptions.clear();
|
|
24490
24507
|
this.onWsClose?.(event);
|
|
24491
24508
|
};
|
|
@@ -24499,15 +24516,30 @@ var Client = class _Client {
|
|
|
24499
24516
|
return;
|
|
24500
24517
|
}
|
|
24501
24518
|
this._wsLog("Disconnecting, clearing", this._subscriptions.size, "subscriptions");
|
|
24519
|
+
if (this._pingInterval) {
|
|
24520
|
+
clearInterval(this._pingInterval);
|
|
24521
|
+
this._pingInterval = void 0;
|
|
24522
|
+
}
|
|
24502
24523
|
this._subscriptions.clear();
|
|
24503
24524
|
this._ws.close();
|
|
24504
24525
|
this._ws = void 0;
|
|
24505
24526
|
}
|
|
24506
|
-
// Method to check if WebSocket is connected
|
|
24527
|
+
// Method to check if WebSocket is connected and responsive
|
|
24507
24528
|
isWebSocketConnected() {
|
|
24508
|
-
|
|
24509
|
-
|
|
24510
|
-
|
|
24529
|
+
if (!this._ws || this._ws.readyState !== WebSocket.OPEN) {
|
|
24530
|
+
this._wsLog("isWebSocketConnected: false (not open)");
|
|
24531
|
+
return false;
|
|
24532
|
+
}
|
|
24533
|
+
const pongTimeout = this._pingIntervalMs * 2;
|
|
24534
|
+
const alive = Date.now() - this._lastPongAt < pongTimeout;
|
|
24535
|
+
this._wsLog(
|
|
24536
|
+
"isWebSocketConnected:",
|
|
24537
|
+
alive,
|
|
24538
|
+
"lastPong:",
|
|
24539
|
+
Date.now() - this._lastPongAt,
|
|
24540
|
+
"ms ago"
|
|
24541
|
+
);
|
|
24542
|
+
return alive;
|
|
24511
24543
|
}
|
|
24512
24544
|
sendWsMessage(message) {
|
|
24513
24545
|
if (!this._ws) throw new Error("WebSocket is not connected");
|