@n1xyz/nord-ts 0.1.6 → 0.1.7

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.
Files changed (39) hide show
  1. package/dist/actions.d.ts +57 -0
  2. package/dist/actions.js +229 -0
  3. package/dist/client/Nord.d.ts +379 -0
  4. package/dist/client/Nord.js +718 -0
  5. package/dist/client/NordAdmin.d.ts +225 -0
  6. package/dist/client/NordAdmin.js +394 -0
  7. package/dist/client/NordUser.d.ts +350 -0
  8. package/dist/client/NordUser.js +743 -0
  9. package/dist/error.d.ts +35 -0
  10. package/dist/error.js +49 -0
  11. package/dist/gen/openapi.d.ts +40 -0
  12. package/dist/index.d.ts +6 -1
  13. package/dist/index.js +29 -1
  14. package/dist/nord/client/NordAdmin.js +2 -0
  15. package/dist/types.d.ts +4 -50
  16. package/dist/types.js +1 -24
  17. package/dist/utils.d.ts +8 -11
  18. package/dist/utils.js +54 -41
  19. package/dist/websocket/Subscriber.d.ts +37 -0
  20. package/dist/websocket/Subscriber.js +25 -0
  21. package/dist/websocket/index.d.ts +19 -2
  22. package/dist/websocket/index.js +82 -2
  23. package/package.json +1 -1
  24. package/src/actions.ts +333 -0
  25. package/src/{nord/client → client}/Nord.ts +207 -210
  26. package/src/{nord/client → client}/NordAdmin.ts +123 -153
  27. package/src/{nord/client → client}/NordUser.ts +216 -305
  28. package/src/gen/openapi.ts +40 -0
  29. package/src/index.ts +7 -1
  30. package/src/types.ts +4 -54
  31. package/src/utils.ts +44 -47
  32. package/src/{nord/models → websocket}/Subscriber.ts +2 -2
  33. package/src/websocket/index.ts +105 -2
  34. package/src/nord/api/actions.ts +0 -648
  35. package/src/nord/api/core.ts +0 -96
  36. package/src/nord/api/metrics.ts +0 -269
  37. package/src/nord/client/NordClient.ts +0 -79
  38. package/src/nord/index.ts +0 -25
  39. /package/src/{nord/utils/NordError.ts → error.ts} +0 -0
@@ -0,0 +1,718 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.Nord = void 0;
40
+ const proton_1 = require("@n1xyz/proton");
41
+ const web3_js_1 = require("@solana/web3.js");
42
+ const events_1 = require("events");
43
+ const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
44
+ const proto = __importStar(require("../gen/nord_pb"));
45
+ const utils = __importStar(require("../utils"));
46
+ const websocket_1 = require("../websocket");
47
+ const error_1 = require("../error");
48
+ /**
49
+ * Main Nord client class for interacting with the Nord API
50
+ */
51
+ class Nord {
52
+ /**
53
+ * Create a new Nord client
54
+ *
55
+ * @param config - Configuration options for the Nord client
56
+ * @param config.webServerUrl - Base URL for the Nord web server
57
+ * @param config.solanaUrl - Solana cluster URL
58
+ * @throws {Error} If required configuration is missing
59
+ */
60
+ constructor({ solanaConnection, webServerUrl, protonClient, }) {
61
+ /** Available markets */
62
+ this.markets = [];
63
+ /** Available tokens */
64
+ this.tokens = [];
65
+ /** Map of symbol to market_id */
66
+ this.symbolToMarketId = new Map();
67
+ this.webServerUrl = webServerUrl;
68
+ this.solanaConnection = solanaConnection;
69
+ this.protonClient = protonClient;
70
+ this.httpClient = (0, openapi_fetch_1.default)({ baseUrl: webServerUrl });
71
+ }
72
+ /**
73
+ * Create a WebSocket client with specific subscriptions
74
+ *
75
+ * @param trades - Market symbols to subscribe to for trade updates
76
+ * @param deltas - Market symbols to subscribe to for orderbook delta updates
77
+ * @param accounts - Account IDs to subscribe to for account updates
78
+ * @returns A new WebSocket client with the requested subscriptions
79
+ * @throws {NordError} If invalid subscription options are provided
80
+ *
81
+ * @example
82
+ * // Create a client for trades and deltas from one market and an account
83
+ * const wsClient = nord.createWebSocketClient({
84
+ * trades: ["BTCUSDC"],
85
+ * deltas: ["BTCUSDC"],
86
+ * accounts: [123]
87
+ * });
88
+ *
89
+ * @example
90
+ * // Create a client for trades from multiple markets
91
+ * const tradesClient = nord.createWebSocketClient({
92
+ * trades: ["BTCUSDC", "ETHUSDC"]
93
+ * });
94
+ */
95
+ createWebSocketClient({ trades, deltas, accounts, }) {
96
+ const subscriptions = [];
97
+ // Add trade subscriptions
98
+ if (trades && trades.length > 0) {
99
+ trades.forEach((symbol) => {
100
+ subscriptions.push(`trades@${symbol}`);
101
+ });
102
+ }
103
+ // Add delta subscriptions
104
+ if (deltas && deltas.length > 0) {
105
+ deltas.forEach((symbol) => {
106
+ subscriptions.push(`deltas@${symbol}`);
107
+ });
108
+ }
109
+ // Add account subscriptions
110
+ if (accounts && accounts.length > 0) {
111
+ accounts.forEach((accountId) => {
112
+ if (isNaN(accountId) || accountId <= 0) {
113
+ throw new error_1.NordError(`Invalid account ID: ${accountId}. Must be a positive number.`);
114
+ }
115
+ subscriptions.push(`account@${accountId}`);
116
+ });
117
+ }
118
+ // Validate that at least one subscription was provided
119
+ if (subscriptions.length === 0) {
120
+ throw new error_1.NordError("At least one subscription must be provided");
121
+ }
122
+ // Create and return a new WebSocket client
123
+ return (0, websocket_1.initWebSocketClient)(this.webServerUrl, subscriptions);
124
+ }
125
+ async GET(path, options) {
126
+ const r = await this.httpClient.GET(path, options);
127
+ if (r.error) {
128
+ throw new error_1.NordError(`failed to GET ${path}`, { cause: r.error });
129
+ }
130
+ if (r.data === undefined) {
131
+ // this should never happen, but the type checker seems unhappy.
132
+ // if we catch this we'll need to debug accordingly.
133
+ throw new error_1.NordError("internal assertion violation", { cause: r });
134
+ }
135
+ return r.data;
136
+ }
137
+ /**
138
+ * Get the current timestamp from the Nord server
139
+ *
140
+ * @returns Current timestamp as a bigint
141
+ * @throws {NordError} If the request fails
142
+ */
143
+ async getTimestamp() {
144
+ return BigInt(await this.GET("/timestamp", {}));
145
+ }
146
+ /**
147
+ * Get the last event nonce from the Nord server
148
+ *
149
+ * @returns Next action nonce
150
+ * @throws {NordError} If the request fails
151
+ */
152
+ async getActionNonce() {
153
+ return await this.GET("/event/last-acked-nonce", {});
154
+ }
155
+ /**
156
+ * Get the admin list from the Nord server
157
+ *
158
+ * @returns List of admin registration keys paired with their ACL role mask
159
+ * @throws {NordError} If the request fails
160
+ */
161
+ async getAdminList() {
162
+ return await this.GET("/admin", {});
163
+ }
164
+ /**
165
+ * Fetch information about Nord markets and tokens
166
+ *
167
+ * @throws {NordError} If the request fails
168
+ */
169
+ async fetchNordInfo() {
170
+ try {
171
+ const info = await this.GET("/info", {});
172
+ this.markets = info.markets;
173
+ this.tokens = info.tokens;
174
+ // Populate the symbolToMarketId map
175
+ this.symbolToMarketId.clear();
176
+ info.markets.forEach((market) => {
177
+ this.symbolToMarketId.set(market.symbol, market.marketId);
178
+ });
179
+ }
180
+ catch (error) {
181
+ throw new error_1.NordError("Failed to fetch Nord info", { cause: error });
182
+ }
183
+ }
184
+ /** @deprecated use Nord.new */
185
+ static async initNord(x) {
186
+ return await Nord.new(x);
187
+ }
188
+ /**
189
+ * Initialize a new Nord client
190
+ *
191
+ * @param nordConfig - Configuration options for the Nord client
192
+ * @param nordConfig.webServerUrl - Base URL for the Nord web server
193
+ * @param nordConfig.app - App address
194
+ * @param nordConfig.solanaUrl - Solana cluster URL
195
+ * @returns Initialized Nord client
196
+ * @throws {NordError} If initialization fails
197
+ */
198
+ static async new({ app, solanaConnection, webServerUrl, protonUrl, }) {
199
+ const protonClient = await proton_1.ProtonClient.init({
200
+ protonUrl: protonUrl ?? webServerUrl,
201
+ app: new web3_js_1.PublicKey(app),
202
+ solConn: solanaConnection,
203
+ });
204
+ const nord = new Nord({
205
+ protonClient,
206
+ solanaConnection,
207
+ webServerUrl,
208
+ });
209
+ await nord.init();
210
+ return nord;
211
+ }
212
+ /**
213
+ * Initialize the Nord client
214
+ * @private
215
+ */
216
+ async init() {
217
+ await this.fetchNordInfo();
218
+ }
219
+ /**
220
+ * Query a specific action
221
+ *
222
+ * @param actionId - Action identifier to fetch
223
+ * @returns Action response
224
+ * @throws {NordError} If the request fails
225
+ */
226
+ async queryAction({ actionId, }) {
227
+ return ((await this.queryRecentActions({
228
+ from: actionId,
229
+ to: actionId,
230
+ }))[0] ?? null);
231
+ }
232
+ /**
233
+ * Query recent actions
234
+ *
235
+ * @param from - Starting action index (inclusive)
236
+ * @param to - Ending action index (inclusive)
237
+ * @returns Actions response
238
+ * @throws {NordError} If the request fails
239
+ */
240
+ async queryRecentActions({ from, to, }) {
241
+ const xs = await this.GET("/action", {
242
+ params: {
243
+ query: { from, to },
244
+ },
245
+ });
246
+ return xs.map((x) => ({
247
+ actionId: x.actionId,
248
+ action: utils.decodeLengthDelimited(Buffer.from(x.payload, "base64"), proto.ActionSchema),
249
+ physicalExecTime: new Date(x.physicalTime),
250
+ }));
251
+ }
252
+ /**
253
+ * Get the last action ID
254
+ *
255
+ * @returns Last action ID
256
+ * @throws {NordError} If the request fails
257
+ */
258
+ async getLastActionId() {
259
+ return await this.GET("/action/last-executed-id", {});
260
+ }
261
+ /**
262
+ * Subscribe to orderbook updates for a market
263
+ *
264
+ * @param symbol - Market symbol
265
+ * @returns Orderbook subscription
266
+ * @throws {NordError} If symbol is invalid
267
+ */
268
+ subscribeOrderbook(symbol) {
269
+ if (!symbol || typeof symbol !== "string") {
270
+ throw new error_1.NordError("Invalid market symbol");
271
+ }
272
+ const subscription = new events_1.EventEmitter();
273
+ const wsClient = this.createWebSocketClient({
274
+ deltas: [symbol],
275
+ });
276
+ const handleDelta = (update) => {
277
+ if (update.symbol !== symbol) {
278
+ return;
279
+ }
280
+ subscription.emit("message", update);
281
+ };
282
+ wsClient.on("delta", handleDelta);
283
+ subscription.close = () => {
284
+ wsClient.removeListener("delta", handleDelta);
285
+ subscription.removeAllListeners();
286
+ };
287
+ return subscription;
288
+ }
289
+ /**
290
+ * Subscribe to trade updates for a market
291
+ *
292
+ * @param symbol - Market symbol
293
+ * @returns Trade subscription
294
+ * @throws {NordError} If symbol is invalid
295
+ */
296
+ subscribeTrades(symbol) {
297
+ if (!symbol || typeof symbol !== "string") {
298
+ throw new error_1.NordError("Invalid market symbol");
299
+ }
300
+ const subscription = new events_1.EventEmitter();
301
+ const wsClient = this.createWebSocketClient({
302
+ trades: [symbol],
303
+ });
304
+ const handleTrade = (update) => {
305
+ if (update.symbol !== symbol) {
306
+ return;
307
+ }
308
+ subscription.emit("message", update);
309
+ };
310
+ wsClient.on("trades", handleTrade);
311
+ subscription.close = () => {
312
+ wsClient.removeListener("trades", handleTrade);
313
+ subscription.removeAllListeners();
314
+ };
315
+ return subscription;
316
+ }
317
+ /**
318
+ * Subscribe to account updates
319
+ *
320
+ * @param accountId - Account ID to subscribe to
321
+ * @returns User subscription
322
+ * @throws {NordError} If accountId is invalid
323
+ */
324
+ subscribeAccount(accountId) {
325
+ if (isNaN(accountId) || accountId <= 0) {
326
+ throw new error_1.NordError("Invalid account ID");
327
+ }
328
+ const subscription = new events_1.EventEmitter();
329
+ const wsClient = this.createWebSocketClient({
330
+ accounts: [accountId],
331
+ });
332
+ const handleAccountUpdate = (update) => {
333
+ if (update.account_id !== accountId) {
334
+ return;
335
+ }
336
+ subscription.emit("message", update);
337
+ };
338
+ wsClient.on("account", handleAccountUpdate);
339
+ subscription.close = () => {
340
+ wsClient.removeListener("account", handleAccountUpdate);
341
+ subscription.removeAllListeners();
342
+ };
343
+ return subscription;
344
+ }
345
+ /**
346
+ * Get trades for a market
347
+ *
348
+ * @param marketId - Market identifier to filter by
349
+ * @param takerId - Taker account identifier
350
+ * @param makerId - Maker account identifier
351
+ * @param takerSide - Side executed by the taker
352
+ * @param pageSize - Maximum number of trades to return
353
+ * @param since - RFC3339 timestamp to start from (inclusive)
354
+ * @param until - RFC3339 timestamp to end at (exclusive)
355
+ * @param pageId - Pagination cursor returned from a prior call
356
+ * @returns Trades response
357
+ * @throws {NordError} If the request fails
358
+ */
359
+ async getTrades({ marketId, takerId, makerId, takerSide, pageSize, since, until, startInclusive, }) {
360
+ if (since && !utils.isRfc3339(since)) {
361
+ throw new error_1.NordError(`Invalid RFC3339 timestamp: ${since}`);
362
+ }
363
+ if (until && !utils.isRfc3339(until)) {
364
+ throw new error_1.NordError(`Invalid RFC3339 timestamp: ${until}`);
365
+ }
366
+ return await this.GET("/trades", {
367
+ params: {
368
+ query: {
369
+ takerId,
370
+ makerId,
371
+ marketId,
372
+ pageSize,
373
+ takerSide,
374
+ since,
375
+ until,
376
+ startInclusive,
377
+ },
378
+ },
379
+ });
380
+ }
381
+ /**
382
+ * Get user account IDs
383
+ *
384
+ * @param pubkey - User public key to query
385
+ * @returns User account IDs response
386
+ * @throws {NordError} If the request fails
387
+ */
388
+ async getUser({ pubkey, }) {
389
+ const r = await this.httpClient.GET("/user/{pubkey}", {
390
+ params: {
391
+ path: { pubkey: pubkey.toString() },
392
+ },
393
+ });
394
+ if (r.response.status === 404) {
395
+ return null;
396
+ }
397
+ return r.data;
398
+ }
399
+ /**
400
+ * Get orderbook for a market
401
+ *
402
+ * @param symbol - Market symbol to resolve into an id
403
+ * @param marketId - Market identifier
404
+ * @returns Orderbook response
405
+ * @throws {NordError} If the request fails or if the market symbol is unknown
406
+ * @remarks It's recommended to initialize the Nord client using the static `initNord` method
407
+ * to ensure market information is properly loaded before calling this method.
408
+ */
409
+ async getOrderbook({ symbol, marketId, }) {
410
+ // If only symbol is provided, convert it to market_id
411
+ let _marketId;
412
+ if (symbol && marketId === undefined) {
413
+ // If the map is empty, try to fetch market information first
414
+ if (this.symbolToMarketId.size === 0) {
415
+ await this.fetchNordInfo();
416
+ }
417
+ const id = this.symbolToMarketId.get(symbol);
418
+ if (id === undefined) {
419
+ throw new error_1.NordError(`Unknown market symbol: ${symbol}`);
420
+ }
421
+ _marketId = id;
422
+ }
423
+ else if (marketId !== undefined) {
424
+ _marketId = marketId;
425
+ }
426
+ else {
427
+ throw new error_1.NordError("Either symbol or market_id must be provided for orderbook query");
428
+ }
429
+ return await this.GET("/market/{market_id}/orderbook", {
430
+ params: {
431
+ path: { market_id: _marketId },
432
+ },
433
+ });
434
+ }
435
+ /**
436
+ * Get information about the Nord server
437
+ *
438
+ * @returns Information about markets and tokens
439
+ * @throws {NordError} If the request fails
440
+ */
441
+ async getInfo() {
442
+ return await this.GET("/info", {});
443
+ }
444
+ /**
445
+ * Fetch the current fee tier brackets configured on Nord.
446
+ *
447
+ * @returns Array of fee tier identifiers paired with their configuration
448
+ * @throws {NordError} If the request fails
449
+ */
450
+ async getFeeBrackets() {
451
+ return await this.GET("/fee/brackets/info", {});
452
+ }
453
+ /**
454
+ * Retrieve the fee tier assigned to a specific account.
455
+ *
456
+ * @param accountId - Account identifier to query
457
+ * @returns Fee tier details for the requested account
458
+ * @throws {NordError} If the request fails
459
+ */
460
+ async getAccountFeeTier(accountId) {
461
+ return await this.GET("/account/{account_id}/fee/tier", {
462
+ params: {
463
+ path: { account_id: accountId },
464
+ },
465
+ });
466
+ }
467
+ /**
468
+ * Get account information
469
+ *
470
+ * @param accountId - Account ID to get information for
471
+ * @returns Account information
472
+ * @throws {NordError} If the request fails
473
+ */
474
+ async getAccount(accountId) {
475
+ return await this.GET("/account/{account_id}", {
476
+ params: {
477
+ path: { account_id: accountId },
478
+ },
479
+ });
480
+ }
481
+ /**
482
+ * Get the public key associated with an account id.
483
+ *
484
+ * @param accountId - Account id to query
485
+ * @returns Base58-encoded account public key
486
+ * @throws {NordError} If the request fails
487
+ */
488
+ async getAccountPubkey(accountId) {
489
+ return await this.GET("/account/{account_id}/pubkey", {
490
+ params: {
491
+ path: { account_id: accountId },
492
+ },
493
+ });
494
+ }
495
+ /**
496
+ * Get the withdrawal fee charged for an account.
497
+ *
498
+ * @param accountId - Account id to query
499
+ * @returns Withdrawal fee quoted in quote token units
500
+ * @throws {NordError} If the request fails
501
+ */
502
+ async getAccountWithdrawalFee(accountId) {
503
+ return await this.GET("/account/{account_id}/fees/withdrawal", {
504
+ params: {
505
+ path: { account_id: accountId },
506
+ },
507
+ });
508
+ }
509
+ /**
510
+ * Get open orders for an account.
511
+ *
512
+ * @param accountId - Account id to query
513
+ * @param startInclusive - Pagination cursor (client order id) to resume from
514
+ * @param pageSize - Maximum number of orders to return
515
+ * @returns Page of orders keyed by client order id
516
+ * @throws {NordError} If the request fails
517
+ */
518
+ async getAccountOrders(accountId, { startInclusive, pageSize, } = {}) {
519
+ return await this.GET("/account/{account_id}/orders", {
520
+ params: {
521
+ path: { account_id: accountId },
522
+ query: {
523
+ startInclusive,
524
+ pageSize,
525
+ },
526
+ },
527
+ });
528
+ }
529
+ /**
530
+ * List account fee tiers with pagination support.
531
+ *
532
+ * @param startInclusive - Account id cursor to resume from
533
+ * @param pageSize - Maximum number of entries to return
534
+ */
535
+ async getAccountsFeeTiers({ startInclusive, pageSize, } = {}) {
536
+ return await this.GET("/accounts/fee-tiers", {
537
+ params: {
538
+ query: {
539
+ startInclusive: startInclusive ?? undefined,
540
+ pageSize: pageSize ?? undefined,
541
+ },
542
+ },
543
+ });
544
+ }
545
+ /**
546
+ * Get profit and loss history for an account
547
+ *
548
+ * @param accountId - Account ID to query
549
+ * @param since - RFC3339 timestamp to start from (inclusive)
550
+ * @param until - RFC3339 timestamp to end at (exclusive)
551
+ * @param startInclusive - Pagination cursor to resume from
552
+ * @param pageSize - Maximum number of entries to return
553
+ * @returns Page of PnL entries ordered from latest to oldest
554
+ * @throws {NordError} If the request fails
555
+ */
556
+ async getAccountPnl(accountId, { since, until, startInclusive, pageSize, } = {}) {
557
+ return await this.GET("/account/{account_id}/pnl", {
558
+ params: {
559
+ path: { account_id: accountId },
560
+ query: {
561
+ since,
562
+ until,
563
+ startInclusive,
564
+ pageSize,
565
+ },
566
+ },
567
+ });
568
+ }
569
+ /**
570
+ * Get market statistics (alias for marketsStats for backward compatibility)
571
+ *
572
+ *
573
+ * @param marketId - Market identifier
574
+ *
575
+ * @returns Market statistics response
576
+ */
577
+ async getMarketStats({ marketId, }) {
578
+ return await this.GET("/market/{market_id}/stats", {
579
+ params: {
580
+ path: { market_id: marketId },
581
+ },
582
+ });
583
+ }
584
+ /**
585
+ * Fetch the per-market fee quote for an account.
586
+ *
587
+ * @param marketId - Market identifier
588
+ * @param feeKind - Fill role (maker/taker) to quote
589
+ * @param accountId - Account identifier to quote
590
+ * @returns Fee in quote token units (negative means fee is charged)
591
+ * @throws {NordError} If the request fails
592
+ */
593
+ async getMarketFee({ marketId, feeKind, accountId, }) {
594
+ return await this.GET("/market/{market_id}/fees/{fee_kind}/{account_id}", {
595
+ params: {
596
+ path: {
597
+ market_id: marketId,
598
+ fee_kind: feeKind,
599
+ account_id: accountId,
600
+ },
601
+ },
602
+ });
603
+ }
604
+ /**
605
+ * Fetch token statistics such as index price and oracle metadata.
606
+ *
607
+ * @param tokenId - Token identifier
608
+ * @returns Token stats
609
+ * @throws {NordError} If the request fails
610
+ */
611
+ async getTokenStats(tokenId) {
612
+ return await this.GET("/tokens/{token_id}/stats", {
613
+ params: {
614
+ path: { token_id: tokenId },
615
+ },
616
+ });
617
+ }
618
+ /**
619
+ * Get order summary by order id.
620
+ *
621
+ * @param orderId - Order identifier
622
+ * @returns Order information
623
+ * @throws {NordError} If the request fails
624
+ */
625
+ async getOrder(orderId) {
626
+ return await this.GET("/order/{order_id}", {
627
+ params: {
628
+ path: { order_id: orderId },
629
+ },
630
+ });
631
+ }
632
+ /**
633
+ * Get trade history for a specific order.
634
+ *
635
+ * @param orderId - Order identifier
636
+ * @param startInclusive - Trade pagination cursor
637
+ * @param pageSize - Maximum number of trades to return
638
+ * @returns Page of trades associated with the order
639
+ * @throws {NordError} If the request fails
640
+ */
641
+ async getOrderTrades(orderId, { startInclusive, pageSize, } = {}) {
642
+ return await this.GET("/order/{order_id}/trades", {
643
+ params: {
644
+ path: { order_id: orderId },
645
+ query: {
646
+ startInclusive,
647
+ pageSize,
648
+ },
649
+ },
650
+ });
651
+ }
652
+ /**
653
+ * Check if an account exists for the given address
654
+ *
655
+ * @param address - The public key address to check
656
+ * @returns True if the account exists, false otherwise
657
+ * @deprecated use getUser instead
658
+ */
659
+ async accountExists(pubkey) {
660
+ return !!(await this.getUser({ pubkey }));
661
+ }
662
+ /**
663
+ * Fetch active triggers for an account.
664
+ *
665
+ * @param accountId - Account identifier owning the triggers
666
+ * @throws {NordError} If no account can be resolved or the request fails.
667
+ */
668
+ async getAccountTriggers({ accountId, } = {}) {
669
+ if (accountId == null) {
670
+ throw new error_1.NordError("Account ID is undefined. Make sure to call updateAccountId() before requesting triggers.");
671
+ }
672
+ try {
673
+ const triggers = await this.GET("/account/{account_id}/triggers", {
674
+ params: {
675
+ path: { account_id: accountId },
676
+ },
677
+ });
678
+ return triggers ?? [];
679
+ }
680
+ catch (error) {
681
+ throw new error_1.NordError("Failed to fetch account triggers", { cause: error });
682
+ }
683
+ }
684
+ /**
685
+ * Fetch trigger history for an account.
686
+ *
687
+ * @param accountId - Account identifier owning the triggers
688
+ * @param since - RFC3339 timestamp to start from (inclusive)
689
+ * @param until - RFC3339 timestamp to end at (exclusive)
690
+ * @param pageSize - Maximum number of entries to return
691
+ * @param startInclusive - Pagination cursor to resume from
692
+ * @throws {NordError} If no account can be resolved or the request fails.
693
+ */
694
+ async getAccountTriggerHistory({ accountId, since, until, pageSize, startInclusive, }) {
695
+ if (accountId == null) {
696
+ throw new error_1.NordError("Account ID is undefined. Make sure to call updateAccountId() before requesting trigger history.");
697
+ }
698
+ try {
699
+ return await this.GET("/account/{account_id}/triggers/history", {
700
+ params: {
701
+ path: { account_id: accountId },
702
+ query: {
703
+ since,
704
+ until,
705
+ pageSize,
706
+ startInclusive,
707
+ },
708
+ },
709
+ });
710
+ }
711
+ catch (error) {
712
+ throw new error_1.NordError("Failed to fetch account trigger history", {
713
+ cause: error,
714
+ });
715
+ }
716
+ }
717
+ }
718
+ exports.Nord = Nord;