@n1xyz/nord-ts 0.0.20 → 0.0.21

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.
@@ -13,4 +13,4 @@ import { NordWebSocketClient } from "../../websocket/index";
13
13
  * @returns WebSocket client
14
14
  * @throws {NordError} If initialization fails or invalid subscription is provided
15
15
  */
16
- export declare function initWebSocketClient(webServerUrl: string, subscriptions?: SubscriptionPattern[] | "trades" | "delta" | "account", initialSubscriptions?: SubscriptionPattern[]): NordWebSocketClient;
16
+ export declare function initWebSocketClient(webServerUrl: string, subscriptions?: SubscriptionPattern[] | "trades" | "delta" | "account"): NordWebSocketClient;
@@ -16,11 +16,10 @@ const NordError_1 = require("../utils/NordError");
16
16
  * @returns WebSocket client
17
17
  * @throws {NordError} If initialization fails or invalid subscription is provided
18
18
  */
19
- function initWebSocketClient(webServerUrl, subscriptions, initialSubscriptions) {
19
+ function initWebSocketClient(webServerUrl, subscriptions) {
20
20
  try {
21
21
  // Determine URL and subscriptions based on parameters
22
22
  let wsUrl = webServerUrl.replace(/^http/, "ws") + `/ws`;
23
- let wsSubscriptions = [];
24
23
  // Validate subscriptions parameter
25
24
  if (typeof subscriptions === "string") {
26
25
  // Legacy mode - handle endpoint string
@@ -28,12 +27,6 @@ function initWebSocketClient(webServerUrl, subscriptions, initialSubscriptions)
28
27
  subscriptions === "delta" ||
29
28
  subscriptions === "account") {
30
29
  wsUrl += `/${subscriptions}`;
31
- // If initialSubscriptions provided, use them
32
- if (initialSubscriptions && initialSubscriptions.length > 0) {
33
- // Validate initialSubscriptions
34
- initialSubscriptions.forEach(validateSubscription);
35
- wsSubscriptions = initialSubscriptions;
36
- }
37
30
  }
38
31
  else {
39
32
  throw new NordError_1.NordError(`Invalid endpoint: ${subscriptions}. Must be "trades", "deltas", or "account".`);
@@ -58,11 +51,6 @@ function initWebSocketClient(webServerUrl, subscriptions, initialSubscriptions)
58
51
  // Add connected handler for debugging
59
52
  ws.on("connected", () => {
60
53
  console.log("Nord WebSocket connected successfully");
61
- // Subscribe to additional subscriptions if provided
62
- // For new format, these are already part of the URL
63
- if (wsSubscriptions.length > 0) {
64
- ws.subscribe(wsSubscriptions);
65
- }
66
54
  });
67
55
  // Connect the WebSocket
68
56
  ws.connect();
@@ -1,7 +1,7 @@
1
- import { EventEmitter } from "events";
2
- import { PublicKey } from "@solana/web3.js";
3
- import { Info, Account, ActionResponse, AggregateMetrics, Market, NordConfig, OrderbookQuery, OrderbookResponse, PeakTpsPeriodUnit, Token, TradesResponse, User, MarketStats } from "../../types";
4
1
  import { ProtonClient } from "@n1xyz/proton";
2
+ import { PublicKey } from "@solana/web3.js";
3
+ import { EventEmitter } from "events";
4
+ import { Account, ActionResponse, AggregateMetrics, Info, Market, MarketStats, NordConfig, OrderbookQuery, OrderbookResponse, PeakTpsPeriodUnit, Token, TradesResponse, User } from "../../types";
5
5
  import { NordWebSocketClient } from "../../websocket/index";
6
6
  import { OrderbookSubscription, TradeSubscription } from "../models/Subscriber";
7
7
  /**
@@ -37,15 +37,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.Nord = void 0;
40
- const events_1 = require("events");
40
+ const proton_1 = require("@n1xyz/proton");
41
41
  const web3_js_1 = require("@solana/web3.js");
42
+ const events_1 = require("events");
42
43
  const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
43
- const types_1 = require("../../types");
44
- const proton_1 = require("@n1xyz/proton");
45
44
  const proto = __importStar(require("../../gen/nord"));
45
+ const types_1 = require("../../types");
46
+ const utils = __importStar(require("../../utils"));
46
47
  const core = __importStar(require("../api/core"));
47
48
  const metrics = __importStar(require("../api/metrics"));
48
- const utils = __importStar(require("../../utils"));
49
49
  const NordError_1 = require("../utils/NordError");
50
50
  /**
51
51
  * Main Nord client class for interacting with the Nord API
@@ -336,7 +336,6 @@ class Nord {
336
336
  };
337
337
  wsClient.on("delta", handleDelta);
338
338
  subscription.close = () => {
339
- wsClient.unsubscribe([`deltas@${symbol}`]);
340
339
  wsClient.removeListener("delta", handleDelta);
341
340
  subscription.removeAllListeners();
342
341
  };
@@ -365,7 +364,6 @@ class Nord {
365
364
  };
366
365
  wsClient.on("trades", handleTrade);
367
366
  subscription.close = () => {
368
- wsClient.unsubscribe([`trades@${symbol}`]);
369
367
  wsClient.removeListener("trades", handleTrade);
370
368
  subscription.removeAllListeners();
371
369
  };
@@ -394,7 +392,6 @@ class Nord {
394
392
  };
395
393
  wsClient.on("account", handleAccountUpdate);
396
394
  subscription.close = () => {
397
- wsClient.unsubscribe([`account@${accountId}`]);
398
395
  wsClient.removeListener("account", handleAccountUpdate);
399
396
  subscription.removeAllListeners();
400
397
  };
package/dist/types.d.ts CHANGED
@@ -208,19 +208,10 @@ export interface ActionNonceResponse {
208
208
  * WebSocket message types
209
209
  */
210
210
  export declare enum WebSocketMessageType {
211
- Subscribe = "subscribe",
212
- Unsubscribe = "unsubscribe",
213
211
  TradeUpdate = "trades",
214
212
  DeltaUpdate = "delta",
215
213
  AccountUpdate = "account"
216
214
  }
217
- /**
218
- * WebSocket subscription request
219
- */
220
- export interface WebSocketSubscription {
221
- e: WebSocketMessageType;
222
- streams: string[];
223
- }
224
215
  /**
225
216
  * WebSocket trade update message
226
217
  */
@@ -251,7 +242,7 @@ export interface WebSocketAccountUpdate {
251
242
  account: Account;
252
243
  timestamp: number;
253
244
  }
254
- export type WebSocketMessage = WebSocketSubscription | WebSocketTradeUpdate | WebSocketDeltaUpdate | WebSocketAccountUpdate;
245
+ export type WebSocketMessage = WebSocketTradeUpdate | WebSocketDeltaUpdate | WebSocketAccountUpdate;
255
246
  export interface SPLTokenInfo {
256
247
  mint: string;
257
248
  precision: number;
package/dist/types.js CHANGED
@@ -95,8 +95,6 @@ function fillModeToProtoFillMode(x) {
95
95
  */
96
96
  var WebSocketMessageType;
97
97
  (function (WebSocketMessageType) {
98
- WebSocketMessageType["Subscribe"] = "subscribe";
99
- WebSocketMessageType["Unsubscribe"] = "unsubscribe";
100
98
  WebSocketMessageType["TradeUpdate"] = "trades";
101
99
  WebSocketMessageType["DeltaUpdate"] = "delta";
102
100
  WebSocketMessageType["AccountUpdate"] = "account";
@@ -12,7 +12,6 @@ import { NordWebSocketClientEvents } from "./events";
12
12
  export declare class NordWebSocketClient extends EventEmitter implements NordWebSocketClientEvents {
13
13
  private ws;
14
14
  private url;
15
- private subscriptions;
16
15
  private reconnectAttempts;
17
16
  private maxReconnectAttempts;
18
17
  private reconnectDelay;
@@ -42,16 +41,6 @@ export declare class NordWebSocketClient extends EventEmitter implements NordWeb
42
41
  * Connect to the Nord WebSocket server
43
42
  */
44
43
  connect(): void;
45
- /**
46
- * Subscribe to one or more streams
47
- * @param streams Array of streams to subscribe to (e.g. ["trades@BTCUSDC", "deltas@BTCUSDC"])
48
- */
49
- subscribe(streams: string[]): void;
50
- /**
51
- * Unsubscribe from one or more streams
52
- * @param streams Array of streams to unsubscribe from
53
- */
54
- unsubscribe(streams: string[]): void;
55
44
  /**
56
45
  * Close the WebSocket connection
57
46
  */
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.NordWebSocketClient = void 0;
7
7
  const events_1 = require("events");
8
8
  const ws_1 = __importDefault(require("ws"));
9
- const types_1 = require("../types");
10
9
  const VALID_STREAM_TYPES = ["trades", "delta", "account"];
11
10
  // Constants for WebSocket readyState
12
11
  const WS_OPEN = 1;
@@ -27,7 +26,6 @@ class NordWebSocketClient extends events_1.EventEmitter {
27
26
  constructor(url) {
28
27
  super();
29
28
  this.ws = null;
30
- this.subscriptions = new Set();
31
29
  this.reconnectAttempts = 0;
32
30
  this.maxReconnectAttempts = 5;
33
31
  this.reconnectDelay = 1000;
@@ -124,10 +122,6 @@ class NordWebSocketClient extends events_1.EventEmitter {
124
122
  this.emit("connected");
125
123
  this.reconnectAttempts = 0;
126
124
  this.reconnectDelay = 1000;
127
- // Resubscribe to previous subscriptions
128
- if (this.subscriptions.size > 0) {
129
- this.subscribe([...this.subscriptions]);
130
- }
131
125
  };
132
126
  this.ws.onmessage = (event) => {
133
127
  try {
@@ -142,12 +136,10 @@ class NordWebSocketClient extends events_1.EventEmitter {
142
136
  const reason = event && event.reason ? ` Reason: ${event.reason}` : "";
143
137
  const code = event && event.code ? ` Code: ${event.code}` : "";
144
138
  this.emit("disconnected");
145
- console.log(`WebSocket closed.${code}${reason}`);
146
139
  this.reconnect();
147
140
  };
148
141
  this.ws.onerror = (event) => {
149
142
  const errorMsg = `WebSocket error: ${event && event.type ? event.type : "unknown"}`;
150
- console.error(errorMsg, event);
151
143
  this.emit("error", new Error(errorMsg));
152
144
  };
153
145
  }
@@ -160,10 +152,6 @@ class NordWebSocketClient extends events_1.EventEmitter {
160
152
  this.reconnectAttempts = 0;
161
153
  this.reconnectDelay = 1000;
162
154
  this.setupHeartbeat();
163
- // Resubscribe to previous subscriptions
164
- if (this.subscriptions.size > 0) {
165
- this.subscribe([...this.subscriptions]);
166
- }
167
155
  });
168
156
  nodeWs.on("message", (data) => {
169
157
  try {
@@ -176,7 +164,6 @@ class NordWebSocketClient extends events_1.EventEmitter {
176
164
  });
177
165
  nodeWs.on("close", (code, reason) => {
178
166
  this.emit("disconnected");
179
- console.log(`WebSocket closed. Code: ${code} Reason: ${reason}`);
180
167
  if (this.pingInterval) {
181
168
  clearInterval(this.pingInterval);
182
169
  }
@@ -186,7 +173,6 @@ class NordWebSocketClient extends events_1.EventEmitter {
186
173
  this.reconnect();
187
174
  });
188
175
  nodeWs.on("error", (error) => {
189
- console.error("WebSocket error:", error);
190
176
  this.emit("error", error);
191
177
  });
192
178
  nodeWs.on("pong", () => {
@@ -198,86 +184,9 @@ class NordWebSocketClient extends events_1.EventEmitter {
198
184
  }
199
185
  catch (error) {
200
186
  const errorMsg = `Failed to initialize WebSocket: ${error instanceof Error ? error.message : String(error)}`;
201
- console.error(errorMsg);
202
187
  this.emit("error", new Error(errorMsg));
203
188
  }
204
189
  }
205
- /**
206
- * Subscribe to one or more streams
207
- * @param streams Array of streams to subscribe to (e.g. ["trades@BTCUSDC", "deltas@BTCUSDC"])
208
- */
209
- subscribe(streams) {
210
- // Validate all streams first
211
- try {
212
- streams.forEach((stream) => this.validateStream(stream));
213
- }
214
- catch (error) {
215
- this.emit("error", error instanceof Error ? error : new Error(String(error)));
216
- return;
217
- }
218
- if (!this.ws ||
219
- (this.isBrowser
220
- ? this.ws.readyState !== WS_OPEN
221
- : this.ws.readyState !== ws_1.default.OPEN)) {
222
- streams.forEach((stream) => this.subscriptions.add(stream));
223
- return;
224
- }
225
- const message = {
226
- e: types_1.WebSocketMessageType.Subscribe,
227
- streams,
228
- };
229
- try {
230
- const messageStr = JSON.stringify(message);
231
- if (this.isBrowser) {
232
- this.ws.send(messageStr);
233
- }
234
- else {
235
- this.ws.send(messageStr);
236
- }
237
- streams.forEach((stream) => this.subscriptions.add(stream));
238
- }
239
- catch (error) {
240
- this.emit("error", error instanceof Error ? error : new Error(String(error)));
241
- }
242
- }
243
- /**
244
- * Unsubscribe from one or more streams
245
- * @param streams Array of streams to unsubscribe from
246
- */
247
- unsubscribe(streams) {
248
- // Validate all streams first
249
- try {
250
- streams.forEach((stream) => this.validateStream(stream));
251
- }
252
- catch (error) {
253
- this.emit("error", error instanceof Error ? error : new Error(String(error)));
254
- return;
255
- }
256
- if (!this.ws ||
257
- (this.isBrowser
258
- ? this.ws.readyState !== WS_OPEN
259
- : this.ws.readyState !== ws_1.default.OPEN)) {
260
- streams.forEach((stream) => this.subscriptions.delete(stream));
261
- return;
262
- }
263
- const message = {
264
- e: types_1.WebSocketMessageType.Unsubscribe,
265
- streams,
266
- };
267
- try {
268
- const messageStr = JSON.stringify(message);
269
- if (this.isBrowser) {
270
- this.ws.send(messageStr);
271
- }
272
- else {
273
- this.ws.send(messageStr);
274
- }
275
- streams.forEach((stream) => this.subscriptions.delete(stream));
276
- }
277
- catch (error) {
278
- this.emit("error", error instanceof Error ? error : new Error(String(error)));
279
- }
280
- }
281
190
  /**
282
191
  * Close the WebSocket connection
283
192
  */
@@ -299,7 +208,6 @@ class NordWebSocketClient extends events_1.EventEmitter {
299
208
  clearTimeout(this.pingTimeout);
300
209
  this.pingTimeout = null;
301
210
  }
302
- this.subscriptions.clear();
303
211
  }
304
212
  /**
305
213
  * Handle incoming WebSocket messages
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n1xyz/nord-ts",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "Typescript for Nord",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@bufbuild/protobuf": "^2.0.0",
45
- "@n1xyz/proton": "0.0.0",
45
+ "@n1xyz/proton": "0.0.2",
46
46
  "@noble/curves": "^1.3.0",
47
47
  "@noble/ed25519": "^2.2.3",
48
48
  "@noble/hashes": "^1.3.2",
@@ -1,5 +1,4 @@
1
- import { Account, Info, SubscriptionPattern } from "../../types";
2
- import { checkedFetch } from "../../utils";
1
+ import { SubscriptionPattern } from "../../types";
3
2
  import { NordWebSocketClient } from "../../websocket/index";
4
3
  import { NordError } from "../utils/NordError";
5
4
 
@@ -19,12 +18,10 @@ import { NordError } from "../utils/NordError";
19
18
  export function initWebSocketClient(
20
19
  webServerUrl: string,
21
20
  subscriptions?: SubscriptionPattern[] | "trades" | "delta" | "account",
22
- initialSubscriptions?: SubscriptionPattern[],
23
21
  ): NordWebSocketClient {
24
22
  try {
25
23
  // Determine URL and subscriptions based on parameters
26
24
  let wsUrl = webServerUrl.replace(/^http/, "ws") + `/ws`;
27
- let wsSubscriptions: SubscriptionPattern[] = [];
28
25
 
29
26
  // Validate subscriptions parameter
30
27
  if (typeof subscriptions === "string") {
@@ -35,12 +32,6 @@ export function initWebSocketClient(
35
32
  subscriptions === "account"
36
33
  ) {
37
34
  wsUrl += `/${subscriptions}`;
38
- // If initialSubscriptions provided, use them
39
- if (initialSubscriptions && initialSubscriptions.length > 0) {
40
- // Validate initialSubscriptions
41
- initialSubscriptions.forEach(validateSubscription);
42
- wsSubscriptions = initialSubscriptions;
43
- }
44
35
  } else {
45
36
  throw new NordError(
46
37
  `Invalid endpoint: ${subscriptions}. Must be "trades", "deltas", or "account".`,
@@ -68,12 +59,6 @@ export function initWebSocketClient(
68
59
  // Add connected handler for debugging
69
60
  ws.on("connected", () => {
70
61
  console.log("Nord WebSocket connected successfully");
71
-
72
- // Subscribe to additional subscriptions if provided
73
- // For new format, these are already part of the URL
74
- if (wsSubscriptions.length > 0) {
75
- ws.subscribe(wsSubscriptions);
76
- }
77
62
  });
78
63
 
79
64
  // Connect the WebSocket
@@ -1,12 +1,16 @@
1
+ import { ProtonClient } from "@n1xyz/proton";
2
+ import { Connection, PublicKey } from "@solana/web3.js";
1
3
  import { EventEmitter } from "events";
2
- import { PublicKey, Connection } from "@solana/web3.js";
3
4
  import createClient, { Client, FetchOptions } from "openapi-fetch";
5
+ import * as proto from "../../gen/nord";
6
+ import type { paths } from "../../gen/openapi.ts";
4
7
  import {
5
- Info,
6
8
  Account,
7
9
  ActionResponse,
8
10
  AggregateMetrics,
11
+ Info,
9
12
  Market,
13
+ MarketStats,
10
14
  NordConfig,
11
15
  OrderbookQuery,
12
16
  OrderbookResponse,
@@ -15,18 +19,13 @@ import {
15
19
  Token,
16
20
  TradesResponse,
17
21
  User,
18
- MarketStats,
19
22
  } from "../../types";
20
- import { ProtonClient } from "@n1xyz/proton";
21
- import * as proto from "../../gen/nord";
22
- // import { base64 } from "@scure/base";
23
+ import * as utils from "../../utils";
23
24
  import { NordWebSocketClient } from "../../websocket/index";
24
25
  import * as core from "../api/core";
25
26
  import * as metrics from "../api/metrics";
26
- import * as utils from "../../utils";
27
27
  import { OrderbookSubscription, TradeSubscription } from "../models/Subscriber";
28
28
  import { NordError } from "../utils/NordError";
29
- import type { paths } from "../../gen/openapi.ts";
30
29
 
31
30
  /**
32
31
  * User subscription interface
@@ -427,7 +426,6 @@ export class Nord {
427
426
  wsClient.on("delta", handleDelta);
428
427
 
429
428
  subscription.close = () => {
430
- wsClient.unsubscribe([`deltas@${symbol}`]);
431
429
  wsClient.removeListener("delta", handleDelta);
432
430
  subscription.removeAllListeners();
433
431
  };
@@ -471,7 +469,6 @@ export class Nord {
471
469
  wsClient.on("trades", handleTrade);
472
470
 
473
471
  subscription.close = () => {
474
- wsClient.unsubscribe([`trades@${symbol}`]);
475
472
  wsClient.removeListener("trades", handleTrade);
476
473
  subscription.removeAllListeners();
477
474
  };
@@ -507,7 +504,6 @@ export class Nord {
507
504
  wsClient.on("account", handleAccountUpdate);
508
505
 
509
506
  subscription.close = () => {
510
- wsClient.unsubscribe([`account@${accountId}`]);
511
507
  wsClient.removeListener("account", handleAccountUpdate);
512
508
  subscription.removeAllListeners();
513
509
  };
package/src/types.ts CHANGED
@@ -251,21 +251,11 @@ export interface ActionNonceResponse {
251
251
  * WebSocket message types
252
252
  */
253
253
  export enum WebSocketMessageType {
254
- Subscribe = "subscribe",
255
- Unsubscribe = "unsubscribe",
256
254
  TradeUpdate = "trades",
257
255
  DeltaUpdate = "delta",
258
256
  AccountUpdate = "account",
259
257
  }
260
258
 
261
- /**
262
- * WebSocket subscription request
263
- */
264
- export interface WebSocketSubscription {
265
- e: WebSocketMessageType;
266
- streams: string[]; // Array of streams to subscribe/unsubscribe (e.g. ["trades@BTCUSDC", "deltas@BTCUSDC"])
267
- }
268
-
269
259
  /**
270
260
  * WebSocket trade update message
271
261
  */
@@ -300,7 +290,6 @@ export interface WebSocketAccountUpdate {
300
290
  }
301
291
 
302
292
  export type WebSocketMessage =
303
- | WebSocketSubscription
304
293
  | WebSocketTradeUpdate
305
294
  | WebSocketDeltaUpdate
306
295
  | WebSocketAccountUpdate;
@@ -4,8 +4,6 @@ import {
4
4
  WebSocketAccountUpdate,
5
5
  WebSocketDeltaUpdate,
6
6
  WebSocketMessage,
7
- WebSocketMessageType,
8
- WebSocketSubscription,
9
7
  WebSocketTradeUpdate,
10
8
  } from "../types";
11
9
  import { NordWebSocketClientEvents } from "./events";
@@ -47,7 +45,6 @@ export class NordWebSocketClient
47
45
  {
48
46
  private ws: WebSocketInstance | null = null;
49
47
  private url: string;
50
- private subscriptions: Set<string> = new Set();
51
48
  private reconnectAttempts: number = 0;
52
49
  private maxReconnectAttempts: number = 5;
53
50
  private reconnectDelay: number = 1000;
@@ -174,11 +171,6 @@ export class NordWebSocketClient
174
171
  this.emit("connected");
175
172
  this.reconnectAttempts = 0;
176
173
  this.reconnectDelay = 1000;
177
-
178
- // Resubscribe to previous subscriptions
179
- if (this.subscriptions.size > 0) {
180
- this.subscribe([...this.subscriptions]);
181
- }
182
174
  };
183
175
 
184
176
  (this.ws as BrowserWebSocket).onmessage = (event: { data: any }) => {
@@ -202,13 +194,11 @@ export class NordWebSocketClient
202
194
  event && event.reason ? ` Reason: ${event.reason}` : "";
203
195
  const code = event && event.code ? ` Code: ${event.code}` : "";
204
196
  this.emit("disconnected");
205
- console.log(`WebSocket closed.${code}${reason}`);
206
197
  this.reconnect();
207
198
  };
208
199
 
209
200
  (this.ws as BrowserWebSocket).onerror = (event: any) => {
210
201
  const errorMsg = `WebSocket error: ${event && event.type ? event.type : "unknown"}`;
211
- console.error(errorMsg, event);
212
202
  this.emit("error", new Error(errorMsg));
213
203
  };
214
204
  } else {
@@ -221,11 +211,6 @@ export class NordWebSocketClient
221
211
  this.reconnectAttempts = 0;
222
212
  this.reconnectDelay = 1000;
223
213
  this.setupHeartbeat();
224
-
225
- // Resubscribe to previous subscriptions
226
- if (this.subscriptions.size > 0) {
227
- this.subscribe([...this.subscriptions]);
228
- }
229
214
  });
230
215
 
231
216
  nodeWs.on("message", (data: WebSocket.Data) => {
@@ -244,7 +229,6 @@ export class NordWebSocketClient
244
229
 
245
230
  nodeWs.on("close", (code: number, reason: string) => {
246
231
  this.emit("disconnected");
247
- console.log(`WebSocket closed. Code: ${code} Reason: ${reason}`);
248
232
  if (this.pingInterval) {
249
233
  clearInterval(this.pingInterval);
250
234
  }
@@ -255,7 +239,6 @@ export class NordWebSocketClient
255
239
  });
256
240
 
257
241
  nodeWs.on("error", (error: Error) => {
258
- console.error("WebSocket error:", error);
259
242
  this.emit("error", error);
260
243
  });
261
244
 
@@ -267,105 +250,10 @@ export class NordWebSocketClient
267
250
  }
268
251
  } catch (error) {
269
252
  const errorMsg = `Failed to initialize WebSocket: ${error instanceof Error ? error.message : String(error)}`;
270
- console.error(errorMsg);
271
253
  this.emit("error", new Error(errorMsg));
272
254
  }
273
255
  }
274
256
 
275
- /**
276
- * Subscribe to one or more streams
277
- * @param streams Array of streams to subscribe to (e.g. ["trades@BTCUSDC", "deltas@BTCUSDC"])
278
- */
279
- public subscribe(streams: string[]): void {
280
- // Validate all streams first
281
- try {
282
- streams.forEach((stream) => this.validateStream(stream));
283
- } catch (error) {
284
- this.emit(
285
- "error",
286
- error instanceof Error ? error : new Error(String(error)),
287
- );
288
- return;
289
- }
290
-
291
- if (
292
- !this.ws ||
293
- (this.isBrowser
294
- ? (this.ws as BrowserWebSocket).readyState !== WS_OPEN
295
- : (this.ws as WebSocket).readyState !== WebSocket.OPEN)
296
- ) {
297
- streams.forEach((stream) => this.subscriptions.add(stream));
298
- return;
299
- }
300
-
301
- const message: WebSocketSubscription = {
302
- e: WebSocketMessageType.Subscribe,
303
- streams,
304
- };
305
-
306
- try {
307
- const messageStr = JSON.stringify(message);
308
- if (this.isBrowser) {
309
- (this.ws as BrowserWebSocket).send(messageStr);
310
- } else {
311
- (this.ws as WebSocket).send(messageStr);
312
- }
313
- streams.forEach((stream) => this.subscriptions.add(stream));
314
- } catch (error) {
315
- this.emit(
316
- "error",
317
- error instanceof Error ? error : new Error(String(error)),
318
- );
319
- }
320
- }
321
-
322
- /**
323
- * Unsubscribe from one or more streams
324
- * @param streams Array of streams to unsubscribe from
325
- */
326
- public unsubscribe(streams: string[]): void {
327
- // Validate all streams first
328
- try {
329
- streams.forEach((stream) => this.validateStream(stream));
330
- } catch (error) {
331
- this.emit(
332
- "error",
333
- error instanceof Error ? error : new Error(String(error)),
334
- );
335
- return;
336
- }
337
-
338
- if (
339
- !this.ws ||
340
- (this.isBrowser
341
- ? (this.ws as BrowserWebSocket).readyState !== WS_OPEN
342
- : (this.ws as WebSocket).readyState !== WebSocket.OPEN)
343
- ) {
344
- streams.forEach((stream) => this.subscriptions.delete(stream));
345
- return;
346
- }
347
-
348
- const message: WebSocketSubscription = {
349
- e: WebSocketMessageType.Unsubscribe,
350
- streams,
351
- };
352
-
353
- try {
354
- const messageStr = JSON.stringify(message);
355
- if (this.isBrowser) {
356
- (this.ws as BrowserWebSocket).send(messageStr);
357
- } else {
358
- (this.ws as WebSocket).send(messageStr);
359
- }
360
- streams.forEach((stream) => this.subscriptions.delete(stream));
361
- } catch (error) {
362
- this.emit(
363
- "error",
364
- error instanceof Error ? error : new Error(String(error)),
365
- );
366
- }
367
- }
368
-
369
257
  /**
370
258
  * Close the WebSocket connection
371
259
  */
@@ -386,7 +274,6 @@ export class NordWebSocketClient
386
274
  clearTimeout(this.pingTimeout);
387
275
  this.pingTimeout = null;
388
276
  }
389
- this.subscriptions.clear();
390
277
  }
391
278
 
392
279
  /**
@@ -1,14 +0,0 @@
1
- import type { paths } from "../gen/openapi";
2
- export interface ClientConfig {
3
- baseUrl: string;
4
- }
5
- export declare function createApiClient(config: ClientConfig): import("openapi-fetch").Client<paths, `${string}/${string}`>;
6
- export declare function handleApiResponse<T>(response: Promise<{
7
- data: T;
8
- error?: unknown;
9
- response: Response;
10
- } | {
11
- data?: never;
12
- error?: unknown;
13
- response: Response;
14
- }>): Promise<T>;