@rabby-wallet/hyperliquid-sdk 1.1.2-beta.1 → 1.1.2-beta.10

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.
@@ -1,5 +1,5 @@
1
1
  import { ExchangeType } from '../types/constants';
2
- import type { OrderResponse, CancelResponse, ExchangeClientConfig, PlaceOrderParams, MultiOrderParams, CancelOrderParams, ModifyOrderParams, WithdrawParams, ApproveBuilderFeeParams, PrepareApproveBuilderFeeResult, SendApproveParams, MarketOrderParams, UpdateLeverageParams, BindTpslByOrderIdParams, UpdateIsolatedMarginParams, TwapOrderParams, TwapCancelParams, TwapOrderResponse } from '../types';
2
+ import type { OrderResponse, CancelResponse, ExchangeClientConfig, PlaceOrderParams, MultiOrderParams, CancelOrderParams, ModifyOrderParams, WithdrawParams, ApproveBuilderFeeParams, PrepareApproveBuilderFeeResult, SendApproveParams, MarketOrderParams, UpdateLeverageParams, BindTpslByOrderIdParams, UpdateIsolatedMarginParams, TwapOrderParams, TwapCancelParams, TwapOrderResponse, PlaceTPSlMarketOrderParams, PlaceTPSlLimitOrderParams } from '../types';
3
3
  /**
4
4
  * Client for executing trades on Hyperliquid (perpetuals only)
5
5
  * Only includes essential trading APIs as specified
@@ -59,6 +59,16 @@ export declare class ExchangeClient {
59
59
  */
60
60
  marketOrderOpen(params: MarketOrderParams): Promise<OrderResponse>;
61
61
  marketOrderClose(params: Omit<MarketOrderParams, 'tpTriggerPx' | 'slTriggerPx'>): Promise<OrderResponse>;
62
+ /**
63
+ * Place a take profit or stop loss market order
64
+ * default slippage is 0.08
65
+ */
66
+ placeTPSlMarketOrder(params: PlaceTPSlMarketOrderParams): Promise<OrderResponse>;
67
+ /**
68
+ * Place a take profit or stop loss limit order
69
+ * default slippage is 0.08
70
+ */
71
+ placeTPSlLimitOrder(params: PlaceTPSlLimitOrderParams): Promise<OrderResponse>;
62
72
  /**
63
73
  * Place multiple orders at once
64
74
  */
@@ -230,7 +230,7 @@ class ExchangeClient {
230
230
  isBuy: params.isBuy,
231
231
  sz: (0, number_1.removeTrailingZeros)(params.size),
232
232
  limitPx: px,
233
- reduceOnly: false,
233
+ reduceOnly: params.reduceOnly || false,
234
234
  orderType: { limit: { tif: 'Ioc' } },
235
235
  }];
236
236
  if (params.tpTriggerPx) {
@@ -303,6 +303,73 @@ class ExchangeClient {
303
303
  }
304
304
  });
305
305
  }
306
+ /**
307
+ * Place a take profit or stop loss market order
308
+ * default slippage is 0.08
309
+ */
310
+ placeTPSlMarketOrder(params) {
311
+ return __awaiter(this, void 0, void 0, function* () {
312
+ try {
313
+ const slippage = params.slippage || constants_1.SLIPPAGE;
314
+ const szDecimals = yield this.symbolConversion.getAssetSzDecimals(params.coin);
315
+ const px = this.getSlippagePx((0, number_1.removeTrailingZeros)(params.triggerPx), slippage, params.isBuy, szDecimals);
316
+ const orders = [{
317
+ coin: params.coin,
318
+ isBuy: params.isBuy,
319
+ sz: (0, number_1.removeTrailingZeros)(params.size),
320
+ limitPx: px,
321
+ reduceOnly: params.reduceOnly || false,
322
+ orderType: {
323
+ trigger: {
324
+ isMarket: true,
325
+ triggerPx: (0, number_1.removeTrailingZeros)(params.triggerPx),
326
+ tpsl: params.tpsl,
327
+ },
328
+ },
329
+ }];
330
+ const res = yield this.multiOrder({
331
+ orders,
332
+ builder: params.builder,
333
+ });
334
+ return res;
335
+ }
336
+ catch (error) {
337
+ throw error;
338
+ }
339
+ });
340
+ }
341
+ /**
342
+ * Place a take profit or stop loss limit order
343
+ * default slippage is 0.08
344
+ */
345
+ placeTPSlLimitOrder(params) {
346
+ return __awaiter(this, void 0, void 0, function* () {
347
+ try {
348
+ const orders = [{
349
+ coin: params.coin,
350
+ isBuy: params.isBuy,
351
+ sz: (0, number_1.removeTrailingZeros)(params.size),
352
+ limitPx: (0, number_1.removeTrailingZeros)(params.limitPx),
353
+ reduceOnly: params.reduceOnly || false,
354
+ orderType: {
355
+ trigger: {
356
+ isMarket: false,
357
+ triggerPx: (0, number_1.removeTrailingZeros)(params.triggerPx),
358
+ tpsl: params.tpsl,
359
+ },
360
+ },
361
+ }];
362
+ const res = yield this.multiOrder({
363
+ orders,
364
+ builder: params.builder,
365
+ });
366
+ return res;
367
+ }
368
+ catch (error) {
369
+ throw error;
370
+ }
371
+ });
372
+ }
306
373
  /**
307
374
  * Place multiple orders at once
308
375
  */
@@ -662,12 +729,14 @@ class ExchangeClient {
662
729
  const nonce = Date.now();
663
730
  const action = {
664
731
  type: constants_1.ExchangeType.TWAP_ORDER,
665
- a: yield this.symbolConversion.getAssetIndex(params.coin),
666
- b: params.isBuy,
667
- s: (0, number_1.removeTrailingZeros)(params.sz),
668
- r: params.reduceOnly || false,
669
- m: params.durationMillis,
670
- t: params.randomizeDelay || false,
732
+ twap: {
733
+ a: yield this.symbolConversion.getAssetIndex(params.coin),
734
+ b: params.isBuy,
735
+ s: (0, number_1.removeTrailingZeros)(params.sz),
736
+ r: params.reduceOnly || false,
737
+ m: params.durationMins,
738
+ t: params.randomizeDelay || false,
739
+ },
671
740
  };
672
741
  if (params.builder) {
673
742
  action.builder = {
@@ -691,8 +760,10 @@ class ExchangeClient {
691
760
  const nonce = Date.now();
692
761
  const action = {
693
762
  type: constants_1.ExchangeType.TWAP_CANCEL,
694
- a: yield this.symbolConversion.getAssetIndex(params.coin),
695
- t: params.twapId,
763
+ twap: {
764
+ a: yield this.symbolConversion.getAssetIndex(params.coin),
765
+ t: params.twapId,
766
+ },
696
767
  };
697
768
  const signature = (0, signer_1.signL1AgentAction)(this.getAgentPrivateKey(), action, this.isTestnet, nonce);
698
769
  return this.httpClient.exchange({
@@ -1,4 +1,4 @@
1
- import type { L2Book, Candle, WsOrder, WebData2, WsActiveAssetCtx, WsUserFills, WsClearinghouseState, Notification, WsTwapStates, WsOpenOrders, WsUserTwapSliceFills, WsUserTwapHistory, wsUserNonFundingLedgerUpdates, WsAllMids, WsTrade } from '../types';
1
+ import type { L2Book, Candle, WsOrder, WebData2, WsActiveAssetCtx, WsUserFills, WsClearinghouseState, Notification, WsTwapStates, WsOpenOrders, WsUserTwapSliceFills, WsUserTwapHistory, wsUserNonFundingLedgerUpdates, WsAllMids, WsTrade, WsActiveAssetData, WsUserHistoricalOrders, WsUserFunding } from '../types';
2
2
  export interface WebSocketClientConfig {
3
3
  masterAddress?: string;
4
4
  isTestnet?: boolean;
@@ -79,6 +79,12 @@ export declare class WebSocketClient {
79
79
  * Subscribe to active asset ctx
80
80
  */
81
81
  subscribeToActiveAssetCtx(coin: string, callback: SubscriptionCallback<WsActiveAssetCtx>): Subscription;
82
+ /**
83
+ * Subscribe to active asset data
84
+ * user: string;
85
+ * coin: string;
86
+ */
87
+ subscribeToActiveAssetData(coin: string, user: string, callback: SubscriptionCallback<WsActiveAssetData>): Subscription;
82
88
  /**
83
89
  * Subscribe to trades for a specific coin
84
90
  */
@@ -92,13 +98,18 @@ export declare class WebSocketClient {
92
98
  */
93
99
  subscribeToUserFills(callback: SubscriptionCallback<WsUserFills>): Subscription;
94
100
  /**
101
+ * Subscribe to user fills
102
+ */
103
+ subscribeToUserHistoricalOrders(callback: SubscriptionCallback<WsUserHistoricalOrders>): Subscription;
104
+ /**
105
+ * @deprecated
95
106
  * Subscribe to user order updates
96
107
  */
97
108
  subscribeToUserOrders(callback: SubscriptionCallback<WsOrder[]>): Subscription;
98
109
  /**
99
110
  * Subscribe to user funding updates
100
111
  */
101
- subscribeToUserFunding(callback: SubscriptionCallback<any>): Subscription;
112
+ subscribeToUserFunding(callback: SubscriptionCallback<WsUserFunding>): Subscription;
102
113
  /**
103
114
  * Subscribe to webData2 - comprehensive user data updates
104
115
  * Includes positions, margin summary, open orders, and other user data
@@ -327,6 +327,16 @@ class WebSocketClient {
327
327
  subscription: { type: constants_1.WsSubscriptionType.ACTIVE_ASSET_CTX, coin },
328
328
  }, callback);
329
329
  }
330
+ /**
331
+ * Subscribe to active asset data
332
+ * user: string;
333
+ * coin: string;
334
+ */
335
+ subscribeToActiveAssetData(coin, user, callback) {
336
+ return this.subscribe({
337
+ subscription: { type: constants_1.WsSubscriptionType.ACTIVE_ASSET_DATA, coin, user },
338
+ }, callback);
339
+ }
330
340
  /**
331
341
  * Subscribe to trades for a specific coin
332
342
  */
@@ -355,6 +365,18 @@ class WebSocketClient {
355
365
  }, callback);
356
366
  }
357
367
  /**
368
+ * Subscribe to user fills
369
+ */
370
+ subscribeToUserHistoricalOrders(callback) {
371
+ if (!this.config.masterAddress) {
372
+ throw new Error('masterAddress is empty');
373
+ }
374
+ return this.subscribe({
375
+ subscription: { type: constants_1.WsSubscriptionType.USER_HISTORICAL_ORDERS, user: this.config.masterAddress },
376
+ }, callback);
377
+ }
378
+ /**
379
+ * @deprecated
358
380
  * Subscribe to user order updates
359
381
  */
360
382
  subscribeToUserOrders(callback) {
@@ -79,6 +79,7 @@ export declare enum WsSubscriptionType {
79
79
  TRADES = "trades",
80
80
  CANDLE = "candle",
81
81
  ACTIVE_ASSET_CTX = "activeAssetCtx",
82
+ ACTIVE_ASSET_DATA = "activeAssetData",
82
83
  USER_FILLS = "userFills",
83
84
  ORDER_UPDATES = "orderUpdates",
84
85
  USER_FUNDINGS = "userFundings",
@@ -89,5 +90,6 @@ export declare enum WsSubscriptionType {
89
90
  OPEN_ORDERS = "openOrders",
90
91
  USER_NON_FUNDING_LEDGER_UPDATES = "userNonFundingLedgerUpdates",
91
92
  USER_TWAP_SLICE_FILLS = "userTwapSliceFills",
92
- USER_TWAP_HISTORY = "userTwapHistory"
93
+ USER_TWAP_HISTORY = "userTwapHistory",
94
+ USER_HISTORICAL_ORDERS = "userHistoricalOrders"
93
95
  }
@@ -94,6 +94,7 @@ var WsSubscriptionType;
94
94
  WsSubscriptionType["TRADES"] = "trades";
95
95
  WsSubscriptionType["CANDLE"] = "candle";
96
96
  WsSubscriptionType["ACTIVE_ASSET_CTX"] = "activeAssetCtx";
97
+ WsSubscriptionType["ACTIVE_ASSET_DATA"] = "activeAssetData";
97
98
  WsSubscriptionType["USER_FILLS"] = "userFills";
98
99
  WsSubscriptionType["ORDER_UPDATES"] = "orderUpdates";
99
100
  WsSubscriptionType["USER_FUNDINGS"] = "userFundings";
@@ -105,4 +106,5 @@ var WsSubscriptionType;
105
106
  WsSubscriptionType["USER_NON_FUNDING_LEDGER_UPDATES"] = "userNonFundingLedgerUpdates";
106
107
  WsSubscriptionType["USER_TWAP_SLICE_FILLS"] = "userTwapSliceFills";
107
108
  WsSubscriptionType["USER_TWAP_HISTORY"] = "userTwapHistory";
109
+ WsSubscriptionType["USER_HISTORICAL_ORDERS"] = "userHistoricalOrders";
108
110
  })(WsSubscriptionType || (exports.WsSubscriptionType = WsSubscriptionType = {}));
@@ -31,6 +31,18 @@ export interface UserHistoricalOrders {
31
31
  status: string;
32
32
  statusTimestamp: number;
33
33
  }
34
+ export interface WsUserFunding {
35
+ isSnapshot?: boolean;
36
+ user: string;
37
+ fundings: {
38
+ coin: string;
39
+ fundingRate: string;
40
+ nSamples: any;
41
+ szi: string;
42
+ time: number;
43
+ usdc: string;
44
+ }[];
45
+ }
34
46
  export interface OpenOrder {
35
47
  coin: string;
36
48
  side: Side;
@@ -46,6 +58,7 @@ export interface OpenOrder {
46
58
  orderType: 'Take Profit Market' | 'Stop Market';
47
59
  origSz: '0.0';
48
60
  tif: null;
61
+ children?: OpenOrder[];
49
62
  }
50
63
  export interface OrderRequest {
51
64
  asset: AssetId;
@@ -201,6 +214,7 @@ export interface MarketOrderParams {
201
214
  isBuy: boolean;
202
215
  size: string;
203
216
  midPx: string;
217
+ reduceOnly?: boolean;
204
218
  tpTriggerPx?: string;
205
219
  slTriggerPx?: string;
206
220
  slippage?: number;
@@ -251,6 +265,11 @@ export interface WsUserFills {
251
265
  user: string;
252
266
  fills: WsFill[];
253
267
  }
268
+ export interface WsUserHistoricalOrders {
269
+ isSnapshot?: boolean;
270
+ user: string;
271
+ orderHistory: UserHistoricalOrders[];
272
+ }
254
273
  export interface WsFill {
255
274
  coin: string;
256
275
  px: string;
@@ -300,12 +319,47 @@ export interface WsActiveAssetCtx {
300
319
  dayNtlVlm: string;
301
320
  prevDayPx: string;
302
321
  markPx: string;
322
+ impactPxs: [string, string];
303
323
  midPx?: string;
304
324
  funding: string;
305
325
  openInterest: string;
306
326
  oraclePx: string;
307
327
  };
308
328
  }
329
+ export interface WsActiveAssetData {
330
+ availableToTrade: [string, string];
331
+ coin: string;
332
+ leverage: Leverage;
333
+ markPx: string;
334
+ maxTradeSzs: [string, string];
335
+ user: string;
336
+ }
337
+ export interface PlaceTPSlMarketOrderParams {
338
+ coin: string;
339
+ isBuy: boolean;
340
+ size: string;
341
+ triggerPx: string;
342
+ tpsl: 'tp' | 'sl';
343
+ slippage?: number;
344
+ reduceOnly?: boolean;
345
+ builder?: {
346
+ address: string;
347
+ fee: number;
348
+ };
349
+ }
350
+ export interface PlaceTPSlLimitOrderParams {
351
+ coin: string;
352
+ isBuy: boolean;
353
+ size: string;
354
+ triggerPx: string;
355
+ limitPx: string;
356
+ tpsl: 'tp' | 'sl';
357
+ reduceOnly?: boolean;
358
+ builder?: {
359
+ address: string;
360
+ fee: number;
361
+ };
362
+ }
309
363
  export interface WsTrade {
310
364
  coin: string;
311
365
  hash: string;
@@ -405,7 +459,7 @@ export interface BindTpslByOrderIdParams {
405
459
  }
406
460
  export interface MultiOrderParams {
407
461
  orders: PlaceOrderParams[];
408
- grouping?: string;
462
+ grouping?: "na" | "normalTpsl" | "positionTpsl";
409
463
  builder?: {
410
464
  address: string;
411
465
  fee: number;
@@ -489,7 +543,7 @@ export interface TwapOrderParams {
489
543
  isBuy: boolean;
490
544
  sz: string;
491
545
  reduceOnly?: boolean;
492
- durationMillis: number;
546
+ durationMins: number;
493
547
  randomizeDelay?: boolean;
494
548
  builder?: {
495
549
  address: string;
@@ -504,65 +558,87 @@ export interface TwapOrderResponse {
504
558
  status: 'ok';
505
559
  response: {
506
560
  type: 'twapOrder';
507
- data: {
508
- twapId: number;
561
+ data?: {
562
+ statuses?: {
563
+ running?: {
564
+ twapId?: number;
565
+ };
566
+ };
567
+ error?: string;
509
568
  };
510
569
  };
511
570
  }
512
- export interface TwapState {
513
- twapId: number;
514
- coin: string;
515
- isBuy: boolean;
516
- sz: string;
517
- reduceOnly: boolean;
518
- totalSz: string;
519
- executedSz: string;
520
- remainingSz: string;
521
- startTime: number;
522
- endTime: number;
523
- status: 'active' | 'completed' | 'cancelled';
524
- }
571
+ type TwapStateArray = [
572
+ number,
573
+ {
574
+ coin: string;
575
+ user: string;
576
+ side: Side;
577
+ sz: string;
578
+ executedSz: string;
579
+ executedNtl: string;
580
+ minutes: number;
581
+ reduceOnly: boolean;
582
+ randomize: boolean;
583
+ timestamp: number;
584
+ }
585
+ ];
525
586
  export interface WsTwapStates {
526
587
  dex: string;
527
588
  user: string;
528
- states?: TwapState[];
589
+ states: TwapStateArray[];
529
590
  }
530
591
  export interface WsOpenOrders {
531
592
  user: string;
532
593
  orders?: OpenOrder[];
533
594
  }
595
+ export interface UserTwapSliceFill {
596
+ fill: {
597
+ closedPnl: string;
598
+ coin: string;
599
+ crossed: boolean;
600
+ dir: string;
601
+ fee: string;
602
+ feeToken: string;
603
+ hash: string;
604
+ oid: number;
605
+ px: string;
606
+ side: Side;
607
+ startPosition: string;
608
+ sz: string;
609
+ tid: number;
610
+ time: number;
611
+ };
612
+ twapId: number;
613
+ }
534
614
  export interface WsUserTwapSliceFills {
535
615
  user: string;
536
- fills?: UserTwapSliceFill[];
616
+ isSnapshot?: boolean;
617
+ twapSliceFills: UserTwapSliceFill[];
537
618
  }
538
619
  export interface WsUserTwapHistory {
539
620
  user: string;
540
- history?: UserTwapHistory[];
541
- }
542
- export interface UserTwapSliceFill {
543
- coin: string;
544
- px: string;
545
- sz: string;
546
- side: Side;
547
- time: number;
548
- hash: string;
549
- oid: number;
550
- crossed: boolean;
551
- fee: string;
552
- tid: number;
553
- twapId: number;
621
+ isSnapshot?: boolean;
622
+ history: UserTwapHistory[];
554
623
  }
555
624
  export interface UserTwapHistory {
625
+ state: {
626
+ coin: string;
627
+ executedNtl: string;
628
+ executedSz: string;
629
+ minutes: number;
630
+ randomize: boolean;
631
+ reduceOnly: boolean;
632
+ side: Side;
633
+ sz: string;
634
+ timestamp: number;
635
+ user: string;
636
+ };
637
+ status: {
638
+ status: 'finished' | 'terminated' | 'activated';
639
+ };
640
+ time: number;
556
641
  twapId: number;
557
- user: string;
558
- coin: string;
559
- side: Side;
560
- sz: string;
561
- totalFilled: string;
562
- avgFillPx: string;
563
- startTime: number;
564
- endTime: number;
565
- status: string;
566
642
  }
567
643
  export interface L2BookSnapshot {
568
644
  coin: string;
@@ -575,13 +651,19 @@ export interface FundingHistoryItem {
575
651
  premium: string;
576
652
  time: number;
577
653
  }
578
- export interface UserFunding {
579
- time: number;
654
+ export interface UserFundingDelta {
580
655
  coin: string;
581
- usdc: string;
582
- szi: string;
583
656
  fundingRate: string;
657
+ szi: string;
658
+ type: 'funding';
659
+ usdc: string;
660
+ }
661
+ export interface UserFunding {
662
+ delta: UserFundingDelta;
663
+ hash: string;
664
+ time: number;
584
665
  }
585
666
  export interface Notification {
586
667
  notification: string;
587
668
  }
669
+ export {};
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- ;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/hyperliquid-sdk",
3
- "version": "1.1.2-beta.1",
3
+ "version": "1.1.2-beta.10",
4
4
  "description": "Simplified Hyperliquid Perpetuals Trading SDK for Frontend Applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,7 +8,6 @@
8
8
  "dist"
9
9
  ],
10
10
  "publishConfig": {
11
-
12
11
  "access": "public"
13
12
  },
14
13
  "scripts": {