@n1xyz/nord-ts 0.7.2 → 0.7.4

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 { type Duration, FillMode, PlacementRequest, Side, TriggerKind } from "./types";
5
+ import { type Duration, 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"]>;
@@ -58,7 +58,21 @@ export declare function takeAllPositions(client: Client<paths>, signFn: (message
58
58
  }): Promise<{
59
59
  actionId: bigint;
60
60
  } & proto.Receipt_TakeAllPositionsResult>;
61
- export type AtomicSubaction = {
61
+ export type AtomicSelfTarget = {
62
+ targetAccountId?: never;
63
+ useKey?: never;
64
+ };
65
+ export type AtomicDelegatedTarget = {
66
+ targetAccountId: number;
67
+ useKey?: false;
68
+ };
69
+ export type AtomicKeyedTarget = {
70
+ targetAccountId: number;
71
+ useKey: true;
72
+ };
73
+ export type AtomicTarget = AtomicSelfTarget | AtomicDelegatedTarget | AtomicKeyedTarget;
74
+ export type AtomicSelfOrKeyedTarget = AtomicSelfTarget | AtomicKeyedTarget;
75
+ export type AtomicSubaction = (AtomicTarget & ({
62
76
  kind: "place";
63
77
  marketId: number;
64
78
  side: Side;
@@ -70,26 +84,17 @@ export type AtomicSubaction = {
70
84
  price?: Decimal.Value;
71
85
  quoteSize?: Decimal.Value;
72
86
  clientOrderId?: BigIntValue;
73
- delegatorAccountId?: number;
74
- placement?: PlacementRequest;
75
87
  referrer?: BigIntValue;
76
88
  } | {
77
89
  kind: "cancel";
78
90
  orderId: BigIntValue;
79
- delegatorAccountId?: number;
80
- placement?: PlacementRequest;
81
91
  } | {
82
92
  kind: "cancelByClientId";
83
93
  clientOrderId: BigIntValue;
84
- delegatorAccountId?: number;
85
- placement?: PlacementRequest;
86
- } | {
94
+ })) | (AtomicDelegatedTarget & {
87
95
  kind: "reduceOrderLiquidation";
88
- targetAccountId: number;
89
96
  marketId: number;
90
- delegatorAccountId?: number;
91
- placement?: PlacementRequest;
92
- } | {
97
+ }) | (AtomicSelfOrKeyedTarget & ({
93
98
  kind: "rfq";
94
99
  marketId: number;
95
100
  side: Side;
@@ -99,15 +104,19 @@ export type AtomicSubaction = {
99
104
  size: Decimal.Value;
100
105
  timeout?: Duration;
101
106
  clientOrderId?: BigIntValue;
102
- delegatorAccountId?: number;
107
+ minimalFill?: Decimal.Value;
108
+ isReduceOnly?: boolean;
103
109
  } | {
104
110
  kind: "rfqFill";
105
111
  marketId: number;
106
112
  orderId: BigIntValue;
107
113
  priceDecimals: number;
114
+ sizeDecimals: number;
108
115
  price: Decimal.Value;
109
116
  timeout?: Duration;
110
- delegatorAccountId?: number;
117
+ minimumSize?: Decimal.Value;
118
+ maximumSize?: Decimal.Value;
119
+ isReduceOnly?: boolean;
111
120
  } | {
112
121
  kind: "addTrigger";
113
122
  marketId: number;
@@ -119,7 +128,6 @@ export type AtomicSubaction = {
119
128
  limitPrice?: Decimal.Value;
120
129
  limitBaseSize?: Decimal.Value;
121
130
  limitQuoteSize?: Decimal.Value;
122
- placement?: PlacementRequest;
123
131
  referrer?: BigIntValue;
124
132
  } | {
125
133
  kind: "editTrigger";
@@ -133,14 +141,17 @@ export type AtomicSubaction = {
133
141
  limitPrice?: Decimal.Value;
134
142
  limitBaseSize?: Decimal.Value;
135
143
  limitQuoteSize?: Decimal.Value;
136
- placement?: PlacementRequest;
137
144
  } | {
138
145
  kind: "removeTrigger";
139
146
  marketId: number;
140
147
  triggerId: BigIntValue;
141
- placement?: PlacementRequest;
142
- };
143
- export declare function atomicSubactionToProto(currentTimestamp: bigint, a: AtomicSubaction, omitDelegatorAccountId?: boolean): proto.AtomicSubaction;
148
+ }));
149
+ export declare function atomicSubactionToProto(currentTimestamp: bigint, a: AtomicSubaction): proto.AtomicSubaction;
150
+ export declare function createAtomicAction(currentTimestamp: bigint, nonce: number, params: {
151
+ sessionId: BigIntValue;
152
+ accountId?: number;
153
+ actions: AtomicSubaction[];
154
+ }): proto.Action;
144
155
  export declare function atomic(client: Client<paths>, signFn: (message: Uint8Array) => Promise<Uint8Array>, currentTimestamp: bigint, nonce: number, params: {
145
156
  sessionId: BigIntValue;
146
157
  accountId?: number;
@@ -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, ActionIdSubActionIdMarketIdCursor, AtomicActionId, GetAccountPositionHistoryQuery, GetAccountPnlQuery, PagedQuery, ActionResponse, MarketsInfo, Market, MarketSymbol, 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, AccountPositionSummaryResult, ActionIdSubActionIdMarketIdCursor, AtomicActionId, GetAccountPositionHistoryQuery, GetAccountPnlQuery, GetAccountPositionSummaryQuery, PagedQuery, ActionResponse, MarketsInfo, Market, MarketSymbol, 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, RfqFillsSubscription } from "../websocket/Subscriber";
9
9
  /**
@@ -26,8 +26,9 @@ export declare class Nord {
26
26
  tokens: Token[];
27
27
  /** Map of symbol to market_id */
28
28
  private symbolToMarketId;
29
- /** Proton client for proton related operations */
30
- protonClient: ProtonClient;
29
+ /** Configuration and lazily initialized client for proton operations. */
30
+ private readonly protonConfig;
31
+ private protonClientPromise?;
31
32
  /** HTTP client for Nord operations */
32
33
  readonly httpClient: Client<paths>;
33
34
  /**
@@ -39,6 +40,13 @@ export declare class Nord {
39
40
  * @throws {Error} If required configuration is missing
40
41
  */
41
42
  private constructor();
43
+ /**
44
+ * Get the Proton client, initializing it on first use.
45
+ *
46
+ * Concurrent callers share the same initialization attempt. A failed attempt
47
+ * is not cached, allowing a later call to retry after Proton recovers.
48
+ */
49
+ getProtonClient(): Promise<ProtonClient>;
42
50
  /**
43
51
  * Create a WebSocket client with specific subscriptions
44
52
  *
@@ -352,6 +360,15 @@ export declare class Nord {
352
360
  */
353
361
  getAccountPositionHistory(accountId: number, { since, until, marketId, pageSize, startInclusive, }?: Readonly<Partial<GetAccountPositionHistoryQuery>>): Promise<AccountPositionInfoPage>;
354
362
  getAccountPnlSummary(accountId: number, { since, until, marketId }?: Readonly<Partial<GetAccountPnlQuery>>): Promise<AccountPnlSummaryResult>;
363
+ /**
364
+ * get per-market position pnl totals for an account.
365
+ *
366
+ * @param accountId - account id to query
367
+ * @param marketId - optional perpetual market id to restrict the result
368
+ * @returns per-market trading and funding pnl with materializer progress
369
+ * @throws {NordError} if the request fails
370
+ */
371
+ getAccountPositionSummary(accountId: number, { marketId }?: Readonly<Partial<GetAccountPositionSummaryQuery>>): Promise<AccountPositionSummaryResult>;
355
372
  getMarketsLive(): Promise<MarketsLiveInfo>;
356
373
  getMarketLive({ marketId, }: Readonly<{
357
374
  marketId: number;
@@ -1,7 +1,6 @@
1
1
  import { PublicKey, Transaction } from "@solana/web3.js";
2
2
  import * as proto from "../gen/nord_pb";
3
3
  import { Nord } from "./Nord";
4
- import { FeeTierConfig } from "../gen/nord_pb";
5
4
  import Decimal from "decimal.js";
6
5
  export declare enum AclRole {
7
6
  FEE_MANAGER = 1,
@@ -242,8 +241,9 @@ export declare class NordAdmin {
242
241
  unpause(): Promise<{
243
242
  actionId: bigint;
244
243
  }>;
245
- setBackstopAccount({ accountId, }: Readonly<{
244
+ setBackstopAccount({ accountId, marketMode, }: Readonly<{
246
245
  accountId: number;
246
+ marketMode?: proto.MarketMode;
247
247
  }>): Promise<{
248
248
  actionId: bigint;
249
249
  } & proto.Receipt_BackstopAccountSet>;
@@ -332,28 +332,19 @@ export declare class NordAdmin {
332
332
  * @returns Action identifier and fee tier addition receipt
333
333
  * @throws {NordError} If the action submission fails or the new tier exceeds the maximum range (0-15).
334
334
  */
335
- addFeeTier({ config, }: Readonly<{
336
- config: FeeTierConfig;
335
+ addFeeTier({ marketType, config, }: Readonly<{
336
+ marketType?: proto.MarketType;
337
+ config: proto.FeeTierTypeConfig;
337
338
  }>): Promise<{
338
339
  actionId: bigint;
339
- } & proto.Receipt_FeeTierAdded>;
340
- /**
341
- * Update an existing fee tier with new maker/taker rates.
342
- *
343
- * Tier identifiers must already exist; attempting to update a missing tier
344
- * causes the action to fail.
345
- *
346
- * @param tierId - Existing fee tier identifier to update
347
- * @param config - Replacement configuration for the tier
348
- * @returns Action identifier and fee tier update receipt
349
- * @throws {NordError} If the action submission fails or the tier ID exceeds the configured range.
350
- */
351
- updateFeeTier({ tierId, config, }: Readonly<{
340
+ } & proto.Receipt_FeeTierTypeAdded>;
341
+ updateFeeTier({ tierId, marketType, config, }: Readonly<{
352
342
  tierId: number;
353
- config: FeeTierConfig;
343
+ marketType?: proto.MarketType;
344
+ config: proto.FeeTierTypeConfig;
354
345
  }>): Promise<{
355
346
  actionId: bigint;
356
- } & proto.Receipt_FeeTierUpdated>;
347
+ } & proto.Receipt_FeeTierTypeUpdated>;
357
348
  /**
358
349
  * Assign a fee tier to one or more accounts.
359
350
  *
@@ -366,9 +357,13 @@ export declare class NordAdmin {
366
357
  * @returns Action identifier and accounts-tier receipt
367
358
  * @throws {NordError} If the tier id exceeds the configured range or an account id is invalid.
368
359
  */
369
- updateAccountsTier(accounts: number[], tierId: number): Promise<{
360
+ updateAccountsTier({ accounts, tierId, marketType, }: Readonly<{
361
+ accounts: number[];
362
+ tierId: number;
363
+ marketType?: proto.MarketType;
364
+ }>): Promise<{
370
365
  actionId: bigint;
371
- } & proto.Receipt_AccountsTierUpdated>;
366
+ } & proto.Receipt_AccountsFeeTierTypeModeUpdated>;
372
367
  feeVaultTransfer({ recipient, tokenId, amount, }: Readonly<{
373
368
  recipient: number;
374
369
  tokenId: number;
@@ -1,10 +1,11 @@
1
1
  import { PublicKey, Transaction, SendOptions } from "@solana/web3.js";
2
2
  import Decimal from "decimal.js";
3
- import { FillMode, Side, SPLTokenInfo, TriggerKind, SelfTradePrevention, PlacementRequest, VaultWithdrawRequestKind, type Duration, type RfqFillResult } from "../types";
3
+ import { FillMode, Side, SPLTokenInfo, TriggerKind, SelfTradePrevention, VaultWithdrawRequestKind, type Duration, type RfqFillResult } from "../types";
4
4
  import * as proto from "../gen/nord_pb";
5
5
  import { BigIntValue } from "../utils";
6
+ import { AtomicDelegatedTarget, AtomicSelfOrKeyedTarget, AtomicTarget } from "../actions";
6
7
  import { Nord } from "./Nord";
7
- export type UserAtomicSubaction = {
8
+ export type UserAtomicSubaction = (AtomicTarget & ({
8
9
  kind: "place";
9
10
  marketId: number;
10
11
  side: Side;
@@ -14,26 +15,17 @@ export type UserAtomicSubaction = {
14
15
  price?: Decimal.Value;
15
16
  quoteSize?: Decimal.Value;
16
17
  clientOrderId?: BigIntValue;
17
- delegatorAccountId?: number;
18
- placement?: PlacementRequest;
19
18
  referrer?: BigIntValue;
20
19
  } | {
21
20
  kind: "cancel";
22
21
  orderId: BigIntValue;
23
- delegatorAccountId?: number;
24
- placement?: PlacementRequest;
25
22
  } | {
26
23
  kind: "cancelByClientId";
27
24
  clientOrderId: BigIntValue;
28
- delegatorAccountId?: number;
29
- placement?: PlacementRequest;
30
- } | {
25
+ })) | (AtomicDelegatedTarget & {
31
26
  kind: "reduceOrderLiquidation";
32
- targetAccountId: number;
33
27
  marketId: number;
34
- delegatorAccountId?: number;
35
- placement?: PlacementRequest;
36
- } | {
28
+ }) | (AtomicSelfOrKeyedTarget & ({
37
29
  kind: "rfq";
38
30
  marketId: number;
39
31
  side: Side;
@@ -41,14 +33,17 @@ export type UserAtomicSubaction = {
41
33
  size: Decimal.Value;
42
34
  timeout?: Duration;
43
35
  clientOrderId?: BigIntValue;
44
- delegatorAccountId?: number;
36
+ minimalFill?: Decimal.Value;
37
+ isReduceOnly?: boolean;
45
38
  } | {
46
39
  kind: "rfqFill";
47
40
  marketId: number;
48
41
  orderId: BigIntValue;
49
42
  price: Decimal.Value;
50
43
  timeout?: Duration;
51
- delegatorAccountId?: number;
44
+ minimumSize?: Decimal.Value;
45
+ maximumSize?: Decimal.Value;
46
+ isReduceOnly?: boolean;
52
47
  } | {
53
48
  kind: "addTrigger";
54
49
  marketId: number;
@@ -58,7 +53,6 @@ export type UserAtomicSubaction = {
58
53
  limitPrice?: Decimal.Value;
59
54
  limitBaseSize?: Decimal.Value;
60
55
  limitQuoteSize?: Decimal.Value;
61
- placement?: PlacementRequest;
62
56
  referrer?: BigIntValue;
63
57
  } | {
64
58
  kind: "editTrigger";
@@ -70,13 +64,11 @@ export type UserAtomicSubaction = {
70
64
  limitPrice?: Decimal.Value;
71
65
  limitBaseSize?: Decimal.Value;
72
66
  limitQuoteSize?: Decimal.Value;
73
- placement?: PlacementRequest;
74
67
  } | {
75
68
  kind: "removeTrigger";
76
69
  marketId: number;
77
70
  triggerId: BigIntValue;
78
- placement?: PlacementRequest;
79
- };
71
+ }));
80
72
  export declare function decodeRfqFillResult(actionId: bigint, result: proto.Receipt_AtomicSubactionResultKind["inner"] | undefined): RfqFillResult;
81
73
  export interface NormalizedReceiptTrade {
82
74
  orderId: bigint;
@@ -94,6 +86,11 @@ export interface NormalizedTakeAllPosition {
94
86
  settlementPrice: number;
95
87
  bankruptcyPrice: number;
96
88
  }
89
+ export interface NormalizedTakeAllTakerResult {
90
+ takerAccountId: number;
91
+ takenBalances: NormalizedTakeAllBalance[];
92
+ takenPositions: NormalizedTakeAllPosition[];
93
+ }
97
94
  /**
98
95
  * User class for interacting with the Nord protocol
99
96
  */
@@ -405,7 +402,7 @@ export declare class NordUser {
405
402
  orderId: bigint;
406
403
  accountId: number;
407
404
  }>;
408
- placeRfqOrder({ marketId, side, size, price, timeout, accountId, clientOrderId, }: Readonly<{
405
+ placeRfqOrder({ marketId, side, size, price, timeout, accountId, clientOrderId, minimalFill, isReduceOnly, }: Readonly<{
409
406
  marketId: number;
410
407
  side: Side;
411
408
  size: Decimal.Value;
@@ -413,16 +410,21 @@ export declare class NordUser {
413
410
  timeout?: Duration;
414
411
  accountId?: number;
415
412
  clientOrderId?: BigIntValue;
413
+ minimalFill?: Decimal.Value;
414
+ isReduceOnly?: boolean;
416
415
  }>): Promise<{
417
416
  actionId: bigint;
418
417
  orderId: bigint;
419
418
  }>;
420
- fillRfqOrder({ marketId, orderId, price, timeout, accountId, }: Readonly<{
419
+ fillRfqOrder({ marketId, orderId, price, timeout, accountId, minimumSize, maximumSize, isReduceOnly, }: Readonly<{
421
420
  marketId: number;
422
421
  orderId: BigIntValue;
423
422
  price: Decimal.Value;
424
423
  timeout?: Duration;
425
424
  accountId?: number;
425
+ minimumSize?: BigIntValue;
426
+ maximumSize?: BigIntValue;
427
+ isReduceOnly?: boolean;
426
428
  }>): Promise<RfqFillResult>;
427
429
  /**
428
430
  * Cancel an order by client_order_id.
@@ -441,9 +443,7 @@ export declare class NordUser {
441
443
  targetAccountId: number;
442
444
  }>): Promise<{
443
445
  actionId: bigint;
444
- takerAccountId: number;
445
- takenBalances: NormalizedTakeAllBalance[];
446
- takenPositions: NormalizedTakeAllPosition[];
446
+ takers: NormalizedTakeAllTakerResult[];
447
447
  }>;
448
448
  /**
449
449
  * Add a trigger for the current session