@n1xyz/nord-ts 0.4.3 → 0.5.1

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/actions.d.ts CHANGED
@@ -2,7 +2,7 @@ import Decimal from "decimal.js";
2
2
  import * as proto from "./gen/nord_pb";
3
3
  import { paths } from "./gen/openapi";
4
4
  import { Client } from "openapi-fetch";
5
- import { FillMode, Side } from "./types";
5
+ import { FillMode, Side, TriggerKind } from "./types";
6
6
  import { BigIntValue } from "./utils";
7
7
  import { PublicKey, Transaction } from "@solana/web3.js";
8
8
  type ReceiptKind = NonNullable<proto.Receipt["kind"]>;
@@ -13,6 +13,7 @@ export declare function formatReceiptError(receipt: proto.Receipt): string;
13
13
  export declare function expectReceiptKind<K extends ReceiptKind["case"]>(receipt: proto.Receipt, expected: K, action: string): asserts receipt is proto.Receipt & {
14
14
  kind: ExtractReceiptKind<K>;
15
15
  };
16
+ export declare function buildLimits(marketPriceDecimals: number, marketSizeDecimals: number, limitPrice?: Decimal.Value, limitBaseSize?: Decimal.Value, limitQuoteSize?: Decimal.Value): proto.OrderLimit | undefined;
16
17
  export declare function createAction(currentTimestamp: bigint, nonce: number, kind: proto.Action["kind"]): proto.Action;
17
18
  export declare function sendAction(client: Client<paths>, makeSignedMessage: (message: Uint8Array) => Promise<Uint8Array>, action: proto.Action): Promise<proto.Receipt>;
18
19
  export declare function prepareAction(action: proto.Action, makeSignedMessage: (message: Uint8Array) => Promise<Uint8Array>): Promise<Uint8Array<ArrayBufferLike>>;
@@ -53,12 +54,42 @@ export type AtomicSubaction = {
53
54
  price?: Decimal.Value;
54
55
  quoteSize?: Decimal.Value;
55
56
  clientOrderId?: BigIntValue;
57
+ delegatorAccountId?: number;
56
58
  } | {
57
59
  kind: "cancel";
58
60
  orderId: BigIntValue;
61
+ delegatorAccountId?: number;
59
62
  } | {
60
63
  kind: "cancelByClientId";
61
64
  clientOrderId: BigIntValue;
65
+ delegatorAccountId?: number;
66
+ } | {
67
+ kind: "addTrigger";
68
+ marketId: number;
69
+ side: Side;
70
+ triggerKind: TriggerKind;
71
+ triggerPrice: Decimal.Value;
72
+ priceDecimals: number;
73
+ sizeDecimals: number;
74
+ limitPrice?: Decimal.Value;
75
+ limitBaseSize?: Decimal.Value;
76
+ limitQuoteSize?: Decimal.Value;
77
+ } | {
78
+ kind: "editTrigger";
79
+ triggerId: BigIntValue;
80
+ marketId: number;
81
+ side: Side;
82
+ triggerKind: TriggerKind;
83
+ triggerPrice: Decimal.Value;
84
+ priceDecimals: number;
85
+ sizeDecimals: number;
86
+ limitPrice?: Decimal.Value;
87
+ limitBaseSize?: Decimal.Value;
88
+ limitQuoteSize?: Decimal.Value;
89
+ } | {
90
+ kind: "removeTrigger";
91
+ marketId: number;
92
+ triggerId: BigIntValue;
62
93
  };
63
94
  export declare function atomic(client: Client<paths>, signFn: (message: Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
64
95
  sessionId: BigIntValue;
@@ -3,7 +3,7 @@ import { Connection, PublicKey } from "@solana/web3.js";
3
3
  import { EventEmitter } from "events";
4
4
  import { Client } from "openapi-fetch";
5
5
  import type { paths } from "../gen/openapi.ts";
6
- import { Account, AccountPnlInfoPage, AccountPnlSummaryResult, GetAccountPnlQuery, PagedQuery, ActionResponse, MarketsInfo, Market, MarketStats, NordConfig, OrderbookQuery, OrderbookResponse, FeeTierConfig, Token, TradesResponse, User, AccountTriggerInfo, TriggerHistoryPage, WithdrawalHistoryPage, FeeTierId, AccountFeeTierPage, PageResultStringOrderInfo, PageResultStringTrade, OrderInfoFromApi, TokenStats, FillRole, AdminInfo, AccountVolumeInfo, GetAccountVolumeQuery, CandleResolution, TakeAllInfo } from "../types";
6
+ import { Account, AccountPnlInfoPage, AccountPositionInfoPage, AccountPnlSummaryResult, AtomicActionId, GetAccountPnlQuery, PagedQuery, ActionResponse, MarketsInfo, Market, MarketStats, NordConfig, OrderbookQuery, OrderbookResponse, FeeTierConfig, Token, TradesResponse, User, AccountTriggerInfo, TriggerPlaceHistoryPage, TriggerFinaliseHistoryPage, WithdrawalHistoryPage, FeeTierId, AccountFeeTierPage, PageResultStringOrderInfo, PageResultStringTrade, OrderInfoFromApi, TokenStats, FillRole, AdminInfo, AccountVolumeInfo, GetAccountVolumeQuery, CandleResolution, TakeAllInfo, MarketsLiveInfo, MarketLiveInfo } from "../types";
7
7
  import { NordWebSocketClient } from "../websocket/index";
8
8
  import { OrderbookSubscription, TradeSubscription, CandleSubscription } from "../websocket/Subscriber";
9
9
  /**
@@ -202,11 +202,12 @@ export declare class Nord {
202
202
  * @param pageSize - Maximum number of trades to return
203
203
  * @param since - RFC3339 timestamp to start from (inclusive)
204
204
  * @param until - RFC3339 timestamp to end at (exclusive)
205
- * @param pageId - Pagination cursor returned from a prior call
205
+ * @param startInclusive - Pagination cursor returned from a prior call. Interpreted as a trade ID by default, or an action ID when paginationMode is "actionId".
206
+ * @param paginationMode - Selects whether pagination cursors are trade IDs or action IDs
206
207
  * @returns Trades response
207
208
  * @throws {NordError} If the request fails
208
209
  */
209
- getTrades({ marketId, takerId, makerId, takerSide, pageSize, since, until, startInclusive, }: Readonly<{
210
+ getTrades({ marketId, takerId, makerId, takerSide, pageSize, since, until, startInclusive, paginationMode, }: Readonly<{
210
211
  marketId?: number;
211
212
  takerId?: number;
212
213
  makerId?: number;
@@ -215,6 +216,7 @@ export declare class Nord {
215
216
  since?: string;
216
217
  until?: string;
217
218
  startInclusive?: number;
219
+ paginationMode?: "tradeId" | "actionId";
218
220
  }>): Promise<TradesResponse>;
219
221
  /**
220
222
  * Get user account IDs
@@ -330,15 +332,26 @@ export declare class Nord {
330
332
  * @returns Per-market pnl totals for the requested window
331
333
  * @throws {NordError} If the request fails
332
334
  */
333
- getAccountPnlSummary(accountId: number, { since, until, marketId }?: Readonly<Partial<GetAccountPnlQuery>>): Promise<AccountPnlSummaryResult>;
334
335
  /**
335
- * Get market statistics (alias for marketsStats for backward compatibility)
336
- *
337
- *
338
- * @param marketId - Market identifier
336
+ * Fetch full history of position updates for an account.
339
337
  *
340
- * @returns Market statistics response
338
+ * @param accountId - Account ID to query
339
+ * @param since - RFC3339 timestamp to start from (inclusive)
340
+ * @param until - RFC3339 timestamp to end at (inclusive)
341
+ * @param marketId - Optional market identifier to scope the totals
342
+ * @param pageSize - Maximum number of entries to return
343
+ * @param startInclusive - Pagination cursor to resume from
344
+ * @returns History of position updates
345
+ * @throws {NordError} If the request fails
341
346
  */
347
+ getAccountPositionHistory(accountId: number, { since, until, marketId, pageSize, startInclusive, }?: Readonly<Partial<GetAccountPnlQuery & Omit<PagedQuery, "startInclusive">> & {
348
+ startInclusive?: string;
349
+ }>): Promise<AccountPositionInfoPage>;
350
+ getAccountPnlSummary(accountId: number, { since, until, marketId }?: Readonly<Partial<GetAccountPnlQuery>>): Promise<AccountPnlSummaryResult>;
351
+ getMarketsLive(): Promise<MarketsLiveInfo>;
352
+ getMarketLive({ marketId, }: Readonly<{
353
+ marketId: number;
354
+ }>): Promise<MarketLiveInfo>;
342
355
  getMarketStats({ marketId, }: Readonly<{
343
356
  marketId: number;
344
357
  }>): Promise<MarketStats>;
@@ -403,7 +416,21 @@ export declare class Nord {
403
416
  accountId?: number;
404
417
  }>): Promise<AccountTriggerInfo[]>;
405
418
  /**
406
- * Fetch trigger history for an account.
419
+ * Fetch trigger placement history for an account.
420
+ *
421
+ * @param accountId - Account identifier owning the triggers
422
+ * @param since - RFC3339 timestamp to start from (inclusive)
423
+ * @param until - RFC3339 timestamp to end at (exclusive)
424
+ * @param pageSize - Maximum number of entries to return
425
+ * @param startInclusive - Pagination cursor to resume from
426
+ * @throws {NordError} If no account can be resolved or the request fails.
427
+ */
428
+ getAccountTriggerPlaceHistory({ accountId, since, until, pageSize, startInclusive, }: Readonly<Omit<PagedQuery, "startInclusive"> & {
429
+ accountId?: number;
430
+ startInclusive?: AtomicActionId;
431
+ }>): Promise<TriggerPlaceHistoryPage>;
432
+ /**
433
+ * Fetch trigger finalisation history for an account.
407
434
  *
408
435
  * @param accountId - Account identifier owning the triggers
409
436
  * @param since - RFC3339 timestamp to start from (inclusive)
@@ -412,9 +439,9 @@ export declare class Nord {
412
439
  * @param startInclusive - Pagination cursor to resume from
413
440
  * @throws {NordError} If no account can be resolved or the request fails.
414
441
  */
415
- getAccountTriggerHistory({ accountId, since, until, pageSize, startInclusive, }: Readonly<PagedQuery & {
442
+ getAccountTriggerFinaliseHistory({ accountId, since, until, pageSize, startInclusive, }: Readonly<PagedQuery & {
416
443
  accountId?: number;
417
- }>): Promise<TriggerHistoryPage>;
444
+ }>): Promise<TriggerFinaliseHistoryPage>;
418
445
  /**
419
446
  * Fetch withdrawal history for an account.
420
447
  *
@@ -1,34 +1,52 @@
1
1
  import { PublicKey, Transaction, SendOptions } from "@solana/web3.js";
2
2
  import Decimal from "decimal.js";
3
- import { FillMode, Side, SPLTokenInfo, TriggerKind } from "../types";
3
+ import { FillMode, Side, SPLTokenInfo, TriggerKind, SelfTradePrevention } from "../types";
4
4
  import * as proto from "../gen/nord_pb";
5
5
  import { BigIntValue } from "../utils";
6
6
  import { Nord } from "./Nord";
7
- /**
8
- * Parameters for individual atomic subactions (user-friendly version)
9
- */
10
- export interface UserAtomicSubaction {
11
- /** The type of action to perform. */
12
- kind: "place" | "cancel" | "cancelByClientId";
13
- /** The market ID to place the order in. */
14
- marketId?: number;
15
- /** The order ID to cancel. */
16
- orderId?: BigIntValue;
17
- /** Order side (bid or ask) */
18
- side?: Side;
19
- /** Fill mode (limit, market, etc.) */
20
- fillMode?: FillMode;
21
- /** Whether the order is reduce-only. */
22
- isReduceOnly?: boolean;
23
- /** The size of the order. */
7
+ export type UserAtomicSubaction = {
8
+ kind: "place";
9
+ marketId: number;
10
+ side: Side;
11
+ fillMode: FillMode;
12
+ isReduceOnly: boolean;
24
13
  size?: Decimal.Value;
25
- /** Order price */
26
14
  price?: Decimal.Value;
27
- /** Quote size in `base_decimals` + `price_decimals` (for market-style placement) */
28
15
  quoteSize?: Decimal.Value;
29
- /** The client order ID of the order. */
30
16
  clientOrderId?: BigIntValue;
31
- }
17
+ delegatorAccountId?: number;
18
+ } | {
19
+ kind: "cancel";
20
+ orderId: BigIntValue;
21
+ delegatorAccountId?: number;
22
+ } | {
23
+ kind: "cancelByClientId";
24
+ clientOrderId: BigIntValue;
25
+ delegatorAccountId?: number;
26
+ } | {
27
+ kind: "addTrigger";
28
+ marketId: number;
29
+ side: Side;
30
+ triggerKind: TriggerKind;
31
+ triggerPrice: Decimal.Value;
32
+ limitPrice?: Decimal.Value;
33
+ limitBaseSize?: Decimal.Value;
34
+ limitQuoteSize?: Decimal.Value;
35
+ } | {
36
+ kind: "editTrigger";
37
+ triggerId: BigIntValue;
38
+ marketId: number;
39
+ side: Side;
40
+ triggerKind: TriggerKind;
41
+ triggerPrice: Decimal.Value;
42
+ limitPrice?: Decimal.Value;
43
+ limitBaseSize?: Decimal.Value;
44
+ limitQuoteSize?: Decimal.Value;
45
+ } | {
46
+ kind: "removeTrigger";
47
+ marketId: number;
48
+ triggerId: BigIntValue;
49
+ };
32
50
  export interface NormalizedReceiptTrade {
33
51
  orderId: bigint;
34
52
  price: number;
@@ -259,7 +277,7 @@ export declare class NordUser {
259
277
  * @returns Object containing actionId, orderId (if posted), fills, and reducedOrders (reduce-only orders fully or partially cancelled by maintenance)
260
278
  * @throws {NordError} If the operation fails
261
279
  */
262
- placeOrder({ marketId, side, fillMode, isReduceOnly, size, price, quoteSize, accountId, clientOrderId, }: Readonly<{
280
+ placeOrder({ marketId, side, fillMode, isReduceOnly, size, price, quoteSize, selfTradePrevention, accountId, clientOrderId, }: Readonly<{
263
281
  marketId: number;
264
282
  side: Side;
265
283
  fillMode: FillMode;
@@ -267,6 +285,7 @@ export declare class NordUser {
267
285
  size?: Decimal.Value;
268
286
  price?: Decimal.Value;
269
287
  quoteSize?: Decimal.Value;
288
+ selfTradePrevention?: SelfTradePrevention;
270
289
  accountId?: number;
271
290
  clientOrderId?: BigIntValue;
272
291
  }>): Promise<{
@@ -279,6 +298,12 @@ export declare class NordUser {
279
298
  cancelledSize: number;
280
299
  price: number;
281
300
  }[];
301
+ selfTradeCancels: {
302
+ orderId: bigint;
303
+ remainingSize: number;
304
+ cancelledSize: number;
305
+ price: number;
306
+ }[];
282
307
  }>;
283
308
  /**
284
309
  * Cancel an order
@@ -328,8 +353,8 @@ export declare class NordUser {
328
353
  * @returns Object containing the actionId of the submitted trigger
329
354
  * @throws {NordError} If the operation fails
330
355
  *
331
- * Trigger identity is exact: (marketId, side, kind, triggerPrice, limits).
332
- * If you add multiple triggers at the same triggerPrice, they must differ by limits.
356
+ * Trigger identity is a unique triggerId assigned by engine.
357
+ * Multiple triggers can share the same triggerPrice and limits.
333
358
  * If both `limitBaseSize` and `limitQuoteSize` are omitted, trigger executes with max reduce size
334
359
  *
335
360
  * Max triggers per position: 16
@@ -345,27 +370,41 @@ export declare class NordUser {
345
370
  accountId?: number;
346
371
  }>): Promise<{
347
372
  actionId: bigint;
373
+ triggerId: bigint;
348
374
  }>;
349
375
  /**
350
376
  * Remove a trigger for the current session
351
377
  *
352
378
  * @param marketId - Market the trigger belongs to
353
- * @param side - Order side for the trigger
354
- * @param kind - Stop-loss or take-profit trigger type
355
- * @param triggerPrice - Trigger price of the trigger to remove
356
- * @param limitPrice - Optional limit price of the trigger to remove
357
- * @param limitBaseSize - Optional base size limit of the trigger to remove
358
- * @param limitQuoteSize - Optional quote size limit of the trigger to remove
379
+ * @param triggerId - Unique trigger identifier to remove
359
380
  * @param accountId - Account executing the trigger
360
381
  * @returns Object containing the actionId of the removal action
361
382
  * @throws {NordError} If the operation fails
383
+ */
384
+ removeTrigger({ marketId, triggerId, accountId, }: Readonly<{
385
+ marketId: number;
386
+ triggerId: bigint;
387
+ accountId?: number;
388
+ }>): Promise<{
389
+ actionId: bigint;
390
+ }>;
391
+ /**
392
+ * Edit an existing trigger for the current session
362
393
  *
363
- * Removal is exact-match by (marketId, side, kind, triggerPrice, limits).
364
- * If the trigger was created with any limits, pass the same limit fields here.
365
- * If trigger size limits were omitted (`NULL`) on add, keep `limitBaseSize` and `limitQuoteSize`
366
- * omitted here as well.
394
+ * @param triggerId - Unique trigger identifier to edit
395
+ * @param marketId - Market to watch
396
+ * @param side - Order side for the trigger
397
+ * @param kind - Stop-loss or take-profit trigger type
398
+ * @param triggerPrice - Price that activates the trigger
399
+ * @param limitPrice - Optional limit price used once the trigger fires
400
+ * @param limitBaseSize - Optional base size limit used once the trigger fires
401
+ * @param limitQuoteSize - Optional quote size limit used once the trigger fires
402
+ * @param accountId - Account executing the trigger
403
+ * @returns Object containing the actionId of the edit action
404
+ * @throws {NordError} If the operation fails
367
405
  */
368
- removeTrigger({ marketId, side, kind, triggerPrice, limitPrice, limitBaseSize, limitQuoteSize, accountId, }: Readonly<{
406
+ editTrigger({ triggerId, marketId, side, kind, triggerPrice, limitPrice, limitBaseSize, limitQuoteSize, accountId, }: Readonly<{
407
+ triggerId: bigint;
369
408
  marketId: number;
370
409
  side: Side;
371
410
  kind: TriggerKind;
@@ -424,13 +463,25 @@ export declare class NordUser {
424
463
  */
425
464
  private transferToAccount;
426
465
  /**
427
- * Execute up to four place/cancel operations atomically.
428
- * Per Market:
429
- * 1. cancels can only be in the start (one cannot predict future order ids)
466
+ * Execute up to ten supported subactions atomically.
467
+ *
468
+ * Supported subactions:
469
+ * - place
470
+ * - cancel
471
+ * - cancelByClientId
472
+ * - addTrigger
473
+ * - editTrigger
474
+ * - removeTrigger
475
+ *
476
+ * Per market, market-scoped subactions are phase-validated:
477
+ * 1. cancels and trigger removals can only be at the start
430
478
  * 2. intermediate trades can trade only
431
- * 3. placements go last
479
+ * 3. placements and trigger adds/edits go last
480
+ *
481
+ * Across markets, market-scoped subactions can be in any order.
432
482
  *
433
- * Across Markets, order action can be any
483
+ * Trigger subactions are account-scoped. In one atomic sequence, the same
484
+ * trigger target cannot be added, edited, or removed more than once.
434
485
  *
435
486
  * @param userActions array of user-friendly subactions
436
487
  * @param providedAccountId optional account performing the action (defaults to first account)
@@ -473,6 +524,4 @@ export declare class NordUser {
473
524
  };
474
525
  }>;
475
526
  protected submitSignedAction(kind: proto.Action["kind"], makeSignedMessage: (message: Uint8Array) => Promise<Uint8Array>): Promise<proto.Receipt>;
476
- private buildTriggerKey;
477
- private buildLimits;
478
527
  }