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

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
  */
@@ -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 } 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
  */
@@ -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
  */
@@ -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",
@@ -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";
@@ -201,6 +201,7 @@ export interface MarketOrderParams {
201
201
  isBuy: boolean;
202
202
  size: string;
203
203
  midPx: string;
204
+ reduceOnly?: boolean;
204
205
  tpTriggerPx?: string;
205
206
  slTriggerPx?: string;
206
207
  slippage?: number;
@@ -306,6 +307,40 @@ export interface WsActiveAssetCtx {
306
307
  oraclePx: string;
307
308
  };
308
309
  }
310
+ export interface WsActiveAssetData {
311
+ availableToTrade: [string, string];
312
+ coin: string;
313
+ leverage: Leverage;
314
+ markPx: string;
315
+ maxTradeSzs: [string, string];
316
+ user: string;
317
+ }
318
+ export interface PlaceTPSlMarketOrderParams {
319
+ coin: string;
320
+ isBuy: boolean;
321
+ size: string;
322
+ triggerPx: string;
323
+ tpsl: 'tp' | 'sl';
324
+ slippage?: number;
325
+ reduceOnly?: boolean;
326
+ builder?: {
327
+ address: string;
328
+ fee: number;
329
+ };
330
+ }
331
+ export interface PlaceTPSlLimitOrderParams {
332
+ coin: string;
333
+ isBuy: boolean;
334
+ size: string;
335
+ triggerPx: string;
336
+ limitPx: string;
337
+ tpsl: 'tp' | 'sl';
338
+ reduceOnly?: boolean;
339
+ builder?: {
340
+ address: string;
341
+ fee: number;
342
+ };
343
+ }
309
344
  export interface WsTrade {
310
345
  coin: string;
311
346
  hash: string;
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.3",
4
4
  "description": "Simplified Hyperliquid Perpetuals Trading SDK for Frontend Applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",