@n1xyz/nord-ts 0.3.5 → 0.4.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/README.md CHANGED
@@ -110,6 +110,27 @@ try {
110
110
  }
111
111
  ```
112
112
 
113
+ ### Quote-Sized Orders
114
+
115
+ For orders limited by quote amount (e.g., USD value), pass a single decimal value:
116
+
117
+ ```typescript
118
+ // Place a market/limit order capped by quote value
119
+ await user.placeOrder({
120
+ marketId: 0,
121
+ side: Side.Bid,
122
+ fillMode: FillMode.Limit,
123
+ isReduceOnly: false,
124
+ // Limit by quote: $100 at $50,000 results in ~0.002 BTC
125
+ quoteSize: 100,
126
+ });
127
+ ```
128
+
129
+ Notes:
130
+ - `quoteSize` is a positive decimal representing the desired quote amount.
131
+ - The wire format encodes quote amount as a 128-bit value scaled by `price_decimals + size_decimals` of the target market.
132
+ - At least one limit must be provided among `size`, `price`, or `quoteSize`.
133
+
113
134
  ### Deposits and Withdrawals
114
135
 
115
136
  ```typescript
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, QuoteSize } from "./types";
5
+ import { FillMode, Side } 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"]>;
@@ -41,7 +41,7 @@ export type AtomicSubaction = {
41
41
  priceDecimals: number;
42
42
  size?: Decimal.Value;
43
43
  price?: Decimal.Value;
44
- quoteSize?: QuoteSize;
44
+ quoteSize?: Decimal.Value;
45
45
  clientOrderId?: BigIntValue;
46
46
  } | {
47
47
  kind: "cancel";
@@ -1,6 +1,6 @@
1
1
  import { PublicKey, Transaction, SendOptions } from "@solana/web3.js";
2
2
  import Decimal from "decimal.js";
3
- import { FillMode, Side, SPLTokenInfo, QuoteSize, TriggerKind } from "../types";
3
+ import { FillMode, Side, SPLTokenInfo, TriggerKind } from "../types";
4
4
  import * as proto from "../gen/nord_pb";
5
5
  import { BigIntValue } from "../utils";
6
6
  import { Nord } from "./Nord";
@@ -24,8 +24,8 @@ export interface UserAtomicSubaction {
24
24
  size?: Decimal.Value;
25
25
  /** Order price */
26
26
  price?: Decimal.Value;
27
- /** Quote size object (for market-style placement) */
28
- quoteSize?: QuoteSize;
27
+ /** Quote size in `base_decimals` + `price_decimals` (for market-style placement) */
28
+ quoteSize?: Decimal.Value;
29
29
  /** The client order ID of the order. */
30
30
  clientOrderId?: BigIntValue;
31
31
  }
@@ -250,7 +250,7 @@ export declare class NordUser {
250
250
  isReduceOnly: boolean;
251
251
  size?: Decimal.Value;
252
252
  price?: Decimal.Value;
253
- quoteSize?: QuoteSize;
253
+ quoteSize?: Decimal.Value;
254
254
  accountId?: number;
255
255
  clientOrderId?: BigIntValue;
256
256
  }>): Promise<{
@@ -291,20 +291,27 @@ export declare class NordUser {
291
291
  * @param side - Order side for the trigger
292
292
  * @param kind - Stop-loss or take-profit trigger type
293
293
  * @param triggerPrice - Price that activates the trigger
294
- * @param limitPrice - Limit price placed once the trigger fires
294
+ * @param limitPrice - Optional limit price used once the trigger fires
295
+ * @param limitBaseSize - Optional base size limit used once the trigger fires
296
+ * @param limitQuoteSize - Optional quote size limit used once the trigger fires
295
297
  * @param accountId - Account executing the trigger
296
298
  * @returns Object containing the actionId of the submitted trigger
297
299
  * @throws {NordError} If the operation fails
298
300
  *
299
- * NOTE: You can upsert a trigger by providing the same trigger data
300
- * with specifically identifiaction by (marketId, accountId,side,kind).
301
+ * Trigger identity is exact: (marketId, side, kind, triggerPrice, limits).
302
+ * If you add multiple triggers at the same triggerPrice, they must differ by limits.
303
+ * If both `limitBaseSize` and `limitQuoteSize` are omitted, trigger executes with max reduce size
304
+ *
305
+ * Max triggers per position: 16
301
306
  */
302
- addTrigger({ marketId, side, kind, triggerPrice, limitPrice, accountId, }: Readonly<{
307
+ addTrigger({ marketId, side, kind, triggerPrice, limitPrice, limitBaseSize, limitQuoteSize, accountId, }: Readonly<{
303
308
  marketId: number;
304
309
  side: Side;
305
310
  kind: TriggerKind;
306
311
  triggerPrice: Decimal.Value;
307
312
  limitPrice?: Decimal.Value;
313
+ limitBaseSize?: Decimal.Value;
314
+ limitQuoteSize?: Decimal.Value;
308
315
  accountId?: number;
309
316
  }>): Promise<{
310
317
  actionId: bigint;
@@ -315,20 +322,51 @@ export declare class NordUser {
315
322
  * @param marketId - Market the trigger belongs to
316
323
  * @param side - Order side for the trigger
317
324
  * @param kind - Stop-loss or take-profit trigger type
325
+ * @param triggerPrice - Trigger price of the trigger to remove
326
+ * @param limitPrice - Optional limit price of the trigger to remove
327
+ * @param limitBaseSize - Optional base size limit of the trigger to remove
328
+ * @param limitQuoteSize - Optional quote size limit of the trigger to remove
318
329
  * @param accountId - Account executing the trigger
319
330
  * @returns Object containing the actionId of the removal action
320
331
  * @throws {NordError} If the operation fails
332
+ *
333
+ * Removal is exact-match by (marketId, side, kind, triggerPrice, limits).
334
+ * If the trigger was created with any limits, pass the same limit fields here.
335
+ * If trigger size limits were omitted (`NULL`) on add, keep `limitBaseSize` and `limitQuoteSize`
336
+ * omitted here as well.
321
337
  */
322
- removeTrigger({ marketId, side, kind, accountId, }: Readonly<{
338
+ removeTrigger({ marketId, side, kind, triggerPrice, limitPrice, limitBaseSize, limitQuoteSize, accountId, }: Readonly<{
323
339
  marketId: number;
324
340
  side: Side;
325
341
  kind: TriggerKind;
342
+ triggerPrice: Decimal.Value;
343
+ limitPrice?: Decimal.Value;
344
+ limitBaseSize?: Decimal.Value;
345
+ limitQuoteSize?: Decimal.Value;
326
346
  accountId?: number;
327
347
  }>): Promise<{
328
348
  actionId: bigint;
329
349
  }>;
330
350
  /**
331
- * Transfer tokens to another account
351
+ * Transfer tokens to one of the user's subaccounts
352
+ *
353
+ * @param tokenId - Token identifier to move
354
+ * @param amount - Amount to transfer
355
+ * @param fromAccountId - Source account id
356
+ * @param toAccountId - Destination account id
357
+ * @throws {NordError} If the operation fails
358
+ */
359
+ transferOwned({ tokenId, amount, fromAccountId, toAccountId, }: Readonly<{
360
+ tokenId: number;
361
+ amount: Decimal.Value;
362
+ fromAccountId: number;
363
+ toAccountId: number;
364
+ }>): Promise<{
365
+ actionId: bigint;
366
+ newAccountId?: number;
367
+ }>;
368
+ /**
369
+ * Transfer tokens to another unowned account
332
370
  *
333
371
  * @param tokenId - Token identifier to move
334
372
  * @param amount - Amount to transfer
@@ -336,15 +374,25 @@ export declare class NordUser {
336
374
  * @param toAccountId - Destination account id
337
375
  * @throws {NordError} If the operation fails
338
376
  */
339
- transferToAccount({ tokenId, amount, fromAccountId, toAccountId, }: Readonly<{
377
+ transferUnowned({ tokenId, amount, fromAccountId, toAccountId, }: Readonly<{
340
378
  tokenId: number;
341
379
  amount: Decimal.Value;
342
- fromAccountId?: number;
343
- toAccountId?: number;
380
+ fromAccountId: number;
381
+ toAccountId: number;
344
382
  }>): Promise<{
345
383
  actionId: bigint;
346
384
  newAccountId?: number;
347
385
  }>;
386
+ /**
387
+ * Transfer tokens to another account
388
+ *
389
+ * @param tokenId - Token identifier to move
390
+ * @param amount - Amount to transfer
391
+ * @param fromAccountId - Source account id
392
+ * @param toAccountId - Destination account id
393
+ * @throws {NordError} If the operation fails
394
+ */
395
+ private transferToAccount;
348
396
  /**
349
397
  * Execute up to four place/cancel operations atomically.
350
398
  * Per Market:
@@ -395,4 +443,6 @@ export declare class NordUser {
395
443
  };
396
444
  }>;
397
445
  protected submitSignedAction(kind: proto.Action["kind"], makeSignedMessage: (message: Uint8Array) => Promise<Uint8Array>): Promise<proto.Receipt>;
446
+ private buildTriggerKey;
447
+ private buildLimits;
398
448
  }