@n1xyz/nord-ts 0.5.0 → 0.6.0

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, PlacementRequest, 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,8 @@ 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;
17
+ export declare function toProtoU128(value: BigIntValue): proto.U128;
16
18
  export declare function createAction(currentTimestamp: bigint, nonce: number, kind: proto.Action["kind"]): proto.Action;
17
19
  export declare function sendAction(client: Client<paths>, makeSignedMessage: (message: Uint8Array) => Promise<Uint8Array>, action: proto.Action): Promise<proto.Receipt>;
18
20
  export declare function prepareAction(action: proto.Action, makeSignedMessage: (message: Uint8Array) => Promise<Uint8Array>): Promise<Uint8Array<ArrayBufferLike>>;
@@ -54,14 +56,49 @@ export type AtomicSubaction = {
54
56
  quoteSize?: Decimal.Value;
55
57
  clientOrderId?: BigIntValue;
56
58
  delegatorAccountId?: number;
59
+ placement?: PlacementRequest;
60
+ referrer?: BigIntValue;
57
61
  } | {
58
62
  kind: "cancel";
59
63
  orderId: BigIntValue;
60
64
  delegatorAccountId?: number;
65
+ placement?: PlacementRequest;
61
66
  } | {
62
67
  kind: "cancelByClientId";
63
68
  clientOrderId: BigIntValue;
64
69
  delegatorAccountId?: number;
70
+ placement?: PlacementRequest;
71
+ } | {
72
+ kind: "addTrigger";
73
+ marketId: number;
74
+ side: Side;
75
+ triggerKind: TriggerKind;
76
+ triggerPrice: Decimal.Value;
77
+ priceDecimals: number;
78
+ sizeDecimals: number;
79
+ limitPrice?: Decimal.Value;
80
+ limitBaseSize?: Decimal.Value;
81
+ limitQuoteSize?: Decimal.Value;
82
+ placement?: PlacementRequest;
83
+ referrer?: BigIntValue;
84
+ } | {
85
+ kind: "editTrigger";
86
+ triggerId: BigIntValue;
87
+ marketId: number;
88
+ side: Side;
89
+ triggerKind: TriggerKind;
90
+ triggerPrice: Decimal.Value;
91
+ priceDecimals: number;
92
+ sizeDecimals: number;
93
+ limitPrice?: Decimal.Value;
94
+ limitBaseSize?: Decimal.Value;
95
+ limitQuoteSize?: Decimal.Value;
96
+ placement?: PlacementRequest;
97
+ } | {
98
+ kind: "removeTrigger";
99
+ marketId: number;
100
+ triggerId: BigIntValue;
101
+ placement?: PlacementRequest;
65
102
  };
66
103
  export declare function atomic(client: Client<paths>, signFn: (message: Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
67
104
  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, AccountPositionInfoPage, AccountPnlSummaryResult, 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";
6
+ import { Account, AccountPnlInfoPage, AccountPositionInfoPage, AccountPnlSummaryResult, ActionIdSubActionIdMarketIdCursor, AtomicActionId, GetAccountPositionHistoryQuery, 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
  /**
@@ -321,7 +321,10 @@ export declare class Nord {
321
321
  * @returns Page of PnL entries ordered from latest to oldest
322
322
  * @throws {NordError} If the request fails
323
323
  */
324
- getAccountPnl(accountId: number, { since, until, startInclusive, pageSize, }?: Readonly<Partial<PagedQuery>>): Promise<AccountPnlInfoPage>;
324
+ getAccountPnl(accountId: number, { since, until, startInclusive, pageSize, }?: Readonly<Partial<GetAccountPnlQuery> & {
325
+ startInclusive?: ActionIdSubActionIdMarketIdCursor;
326
+ pageSize?: number;
327
+ }>): Promise<AccountPnlInfoPage>;
325
328
  /**
326
329
  * Get profit and loss totals for an account over a time window.
327
330
  *
@@ -344,9 +347,7 @@ export declare class Nord {
344
347
  * @returns History of position updates
345
348
  * @throws {NordError} If the request fails
346
349
  */
347
- getAccountPositionHistory(accountId: number, { since, until, marketId, pageSize, startInclusive, }?: Readonly<Partial<GetAccountPnlQuery & Omit<PagedQuery, "startInclusive">> & {
348
- startInclusive?: string;
349
- }>): Promise<AccountPositionInfoPage>;
350
+ getAccountPositionHistory(accountId: number, { since, until, marketId, pageSize, startInclusive, }?: Readonly<Partial<GetAccountPositionHistoryQuery>>): Promise<AccountPositionInfoPage>;
350
351
  getAccountPnlSummary(accountId: number, { since, until, marketId }?: Readonly<Partial<GetAccountPnlQuery>>): Promise<AccountPnlSummaryResult>;
351
352
  getMarketsLive(): Promise<MarketsLiveInfo>;
352
353
  getMarketLive({ marketId, }: Readonly<{
@@ -425,8 +426,9 @@ export declare class Nord {
425
426
  * @param startInclusive - Pagination cursor to resume from
426
427
  * @throws {NordError} If no account can be resolved or the request fails.
427
428
  */
428
- getAccountTriggerPlaceHistory({ accountId, since, until, pageSize, startInclusive, }: Readonly<PagedQuery & {
429
+ getAccountTriggerPlaceHistory({ accountId, since, until, pageSize, startInclusive, }: Readonly<Omit<PagedQuery, "startInclusive"> & {
429
430
  accountId?: number;
431
+ startInclusive?: AtomicActionId;
430
432
  }>): Promise<TriggerPlaceHistoryPage>;
431
433
  /**
432
434
  * Fetch trigger finalisation history for an account.
@@ -156,6 +156,24 @@ export declare class NordAdmin {
156
156
  }>): Promise<{
157
157
  actionId: bigint;
158
158
  } & proto.Receipt_BackstopAccountSet>;
159
+ createVault({ manager, config, }: Readonly<{
160
+ manager: PublicKey;
161
+ config: proto.VaultConfig;
162
+ }>): Promise<{
163
+ actionId: bigint;
164
+ } & proto.CreateVaultReceipt>;
165
+ updateVaultConfig({ vaultId, configPatch, }: Readonly<{
166
+ vaultId: number;
167
+ configPatch: proto.VaultConfigPatch;
168
+ }>): Promise<{
169
+ actionId: bigint;
170
+ } & proto.UpdateVaultConfigReceipt>;
171
+ setVaultManager({ vaultId, manager, }: Readonly<{
172
+ vaultId: number;
173
+ manager: PublicKey;
174
+ }>): Promise<{
175
+ actionId: bigint;
176
+ } & proto.SetVaultManagerReceipt>;
159
177
  /**
160
178
  * Freeze an individual market, preventing new trades and orders.
161
179
  *
@@ -1,36 +1,60 @@
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, PlacementRequest, VaultWithdrawRequestKind } 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
- /** Optional account to delegate this subaction to. */
32
17
  delegatorAccountId?: number;
33
- }
18
+ placement?: PlacementRequest;
19
+ referrer?: BigIntValue;
20
+ } | {
21
+ kind: "cancel";
22
+ orderId: BigIntValue;
23
+ delegatorAccountId?: number;
24
+ placement?: PlacementRequest;
25
+ } | {
26
+ kind: "cancelByClientId";
27
+ clientOrderId: BigIntValue;
28
+ delegatorAccountId?: number;
29
+ placement?: PlacementRequest;
30
+ } | {
31
+ kind: "addTrigger";
32
+ marketId: number;
33
+ side: Side;
34
+ triggerKind: TriggerKind;
35
+ triggerPrice: Decimal.Value;
36
+ limitPrice?: Decimal.Value;
37
+ limitBaseSize?: Decimal.Value;
38
+ limitQuoteSize?: Decimal.Value;
39
+ placement?: PlacementRequest;
40
+ referrer?: BigIntValue;
41
+ } | {
42
+ kind: "editTrigger";
43
+ triggerId: BigIntValue;
44
+ marketId: number;
45
+ side: Side;
46
+ triggerKind: TriggerKind;
47
+ triggerPrice: Decimal.Value;
48
+ limitPrice?: Decimal.Value;
49
+ limitBaseSize?: Decimal.Value;
50
+ limitQuoteSize?: Decimal.Value;
51
+ placement?: PlacementRequest;
52
+ } | {
53
+ kind: "removeTrigger";
54
+ marketId: number;
55
+ triggerId: BigIntValue;
56
+ placement?: PlacementRequest;
57
+ };
34
58
  export interface NormalizedReceiptTrade {
35
59
  orderId: bigint;
36
60
  price: number;
@@ -217,7 +241,7 @@ export declare class NordUser {
217
241
  *
218
242
  * @throws {NordError} If the operation fails
219
243
  */
220
- refreshSession(): Promise<void>;
244
+ refreshSession(expiryTimestamp?: bigint): Promise<void>;
221
245
  /**
222
246
  * Revoke a session
223
247
  *
@@ -246,6 +270,29 @@ export declare class NordUser {
246
270
  }>): Promise<{
247
271
  actionId: bigint;
248
272
  }>;
273
+ vaultDeposit({ vaultId, amount, }: Readonly<{
274
+ vaultId: number;
275
+ amount: Decimal.Value;
276
+ }>): Promise<{
277
+ actionId: bigint;
278
+ } & proto.VaultDepositReceipt>;
279
+ vaultWithdrawRequest({ vaultId, kind, amount, }: Readonly<{
280
+ vaultId: number;
281
+ kind: VaultWithdrawRequestKind;
282
+ amount: Decimal.Value;
283
+ }>): Promise<{
284
+ actionId: bigint;
285
+ } & proto.VaultWithdrawReceipt>;
286
+ vaultWithdrawClaim({ vaultId, }: Readonly<{
287
+ vaultId: number;
288
+ }>): Promise<{
289
+ actionId: bigint;
290
+ } & proto.VaultWithdrawReceipt>;
291
+ vaultSyncEpochs({ vaultId, }: Readonly<{
292
+ vaultId: number;
293
+ }>): Promise<{
294
+ actionId: bigint;
295
+ } & proto.VaultSyncEpochsReceipt>;
249
296
  /**
250
297
  * Place an order on the exchange
251
298
  *
@@ -258,10 +305,11 @@ export declare class NordUser {
258
305
  * @param quoteSize - Quote-sized order representation
259
306
  * @param accountId - Account executing the order
260
307
  * @param clientOrderId - Optional client-specified identifier
308
+ * @param referrer - Optional referrer ID. Tracks which frontend/referral source placed order.
261
309
  * @returns Object containing actionId, orderId (if posted), fills, and reducedOrders (reduce-only orders fully or partially cancelled by maintenance)
262
310
  * @throws {NordError} If the operation fails
263
311
  */
264
- placeOrder({ marketId, side, fillMode, isReduceOnly, size, price, quoteSize, accountId, clientOrderId, }: Readonly<{
312
+ placeOrder({ marketId, side, fillMode, isReduceOnly, size, price, quoteSize, selfTradePrevention, accountId, clientOrderId, referrer, }: Readonly<{
265
313
  marketId: number;
266
314
  side: Side;
267
315
  fillMode: FillMode;
@@ -269,8 +317,10 @@ export declare class NordUser {
269
317
  size?: Decimal.Value;
270
318
  price?: Decimal.Value;
271
319
  quoteSize?: Decimal.Value;
320
+ selfTradePrevention?: SelfTradePrevention;
272
321
  accountId?: number;
273
322
  clientOrderId?: BigIntValue;
323
+ referrer?: BigIntValue;
274
324
  }>): Promise<{
275
325
  actionId: bigint;
276
326
  orderId?: bigint;
@@ -281,6 +331,12 @@ export declare class NordUser {
281
331
  cancelledSize: number;
282
332
  price: number;
283
333
  }[];
334
+ selfTradeCancels: {
335
+ orderId: bigint;
336
+ remainingSize: number;
337
+ cancelledSize: number;
338
+ price: number;
339
+ }[];
284
340
  }>;
285
341
  /**
286
342
  * Cancel an order
@@ -327,6 +383,7 @@ export declare class NordUser {
327
383
  * @param limitBaseSize - Optional base size limit used once the trigger fires
328
384
  * @param limitQuoteSize - Optional quote size limit used once the trigger fires
329
385
  * @param accountId - Account executing the trigger
386
+ * @param referrer - Optional referrer ID. Tracks which frontend/referral source placed trigger
330
387
  * @returns Object containing the actionId of the submitted trigger
331
388
  * @throws {NordError} If the operation fails
332
389
  *
@@ -336,7 +393,7 @@ export declare class NordUser {
336
393
  *
337
394
  * Max triggers per position: 16
338
395
  */
339
- addTrigger({ marketId, side, kind, triggerPrice, limitPrice, limitBaseSize, limitQuoteSize, accountId, }: Readonly<{
396
+ addTrigger({ marketId, side, kind, triggerPrice, limitPrice, limitBaseSize, limitQuoteSize, accountId, referrer, }: Readonly<{
340
397
  marketId: number;
341
398
  side: Side;
342
399
  kind: TriggerKind;
@@ -345,6 +402,7 @@ export declare class NordUser {
345
402
  limitBaseSize?: Decimal.Value;
346
403
  limitQuoteSize?: Decimal.Value;
347
404
  accountId?: number;
405
+ referrer?: BigIntValue;
348
406
  }>): Promise<{
349
407
  actionId: bigint;
350
408
  triggerId: bigint;
@@ -440,13 +498,25 @@ export declare class NordUser {
440
498
  */
441
499
  private transferToAccount;
442
500
  /**
443
- * Execute up to four place/cancel operations atomically.
444
- * Per Market:
445
- * 1. cancels can only be in the start (one cannot predict future order ids)
501
+ * Execute up to ten supported subactions atomically.
502
+ *
503
+ * Supported subactions:
504
+ * - place
505
+ * - cancel
506
+ * - cancelByClientId
507
+ * - addTrigger
508
+ * - editTrigger
509
+ * - removeTrigger
510
+ *
511
+ * Per market, market-scoped subactions are phase-validated:
512
+ * 1. cancels and trigger removals can only be at the start
446
513
  * 2. intermediate trades can trade only
447
- * 3. placements go last
514
+ * 3. placements and trigger adds/edits go last
515
+ *
516
+ * Across markets, market-scoped subactions can be in any order.
448
517
  *
449
- * Across Markets, order action can be any
518
+ * Trigger subactions are account-scoped. In one atomic sequence, the same
519
+ * trigger target cannot be added, edited, or removed more than once.
450
520
  *
451
521
  * @param userActions array of user-friendly subactions
452
522
  * @param providedAccountId optional account performing the action (defaults to first account)
@@ -489,5 +559,4 @@ export declare class NordUser {
489
559
  };
490
560
  }>;
491
561
  protected submitSignedAction(kind: proto.Action["kind"], makeSignedMessage: (message: Uint8Array) => Promise<Uint8Array>): Promise<proto.Receipt>;
492
- private buildLimits;
493
562
  }