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

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, PlaceTPSlMarketOrderParams, PlaceTPSlLimitOrderParams } 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, ClearinghouseState } 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,10 @@ export declare class ExchangeClient {
59
59
  */
60
60
  marketOrderOpen(params: MarketOrderParams): Promise<OrderResponse>;
61
61
  marketOrderClose(params: Omit<MarketOrderParams, 'tpTriggerPx' | 'slTriggerPx'>): Promise<OrderResponse>;
62
+ closeAllPositions(clearinghouseState: ClearinghouseState, slippage?: number, builder?: {
63
+ address: string;
64
+ fee: number;
65
+ }): Promise<OrderResponse>;
62
66
  /**
63
67
  * Place a take profit or stop loss market order
64
68
  * default slippage is 0.08
@@ -280,6 +280,7 @@ class ExchangeClient {
280
280
  }
281
281
  marketOrderClose(params) {
282
282
  return __awaiter(this, void 0, void 0, function* () {
283
+ var _a;
283
284
  try {
284
285
  const slippage = params.slippage || constants_1.SLIPPAGE;
285
286
  const szDecimals = yield this.symbolConversion.getAssetSzDecimals(params.coin);
@@ -289,7 +290,7 @@ class ExchangeClient {
289
290
  isBuy: params.isBuy,
290
291
  sz: (0, number_1.removeTrailingZeros)(params.size),
291
292
  limitPx: px,
292
- reduceOnly: true,
293
+ reduceOnly: (_a = params.reduceOnly) !== null && _a !== void 0 ? _a : true,
293
294
  orderType: { limit: { tif: 'Ioc' } },
294
295
  }];
295
296
  const res = yield this.multiOrder({
@@ -303,6 +304,39 @@ class ExchangeClient {
303
304
  }
304
305
  });
305
306
  }
307
+ closeAllPositions(clearinghouseState_1) {
308
+ return __awaiter(this, arguments, void 0, function* (clearinghouseState, slippage = constants_1.SLIPPAGE, builder) {
309
+ try {
310
+ const closeOrders = [];
311
+ for (const position of clearinghouseState.assetPositions) {
312
+ const item = position.position;
313
+ if (parseFloat(item.szi) !== 0) {
314
+ const isBuy = parseFloat(item.szi) < 0;
315
+ const size = Math.abs(parseFloat(item.szi));
316
+ const markPx = parseFloat(item.positionValue) / size;
317
+ const szDecimals = yield this.symbolConversion.getAssetSzDecimals(item.coin);
318
+ const px = this.getSlippagePx(markPx.toString(), slippage, isBuy, szDecimals);
319
+ closeOrders.push({
320
+ coin: item.coin,
321
+ isBuy,
322
+ sz: (0, number_1.removeTrailingZeros)(size.toString()),
323
+ limitPx: px,
324
+ reduceOnly: true,
325
+ orderType: { limit: { tif: 'Ioc' } },
326
+ });
327
+ }
328
+ }
329
+ const res = yield this.multiOrder({
330
+ orders: closeOrders,
331
+ builder,
332
+ });
333
+ return res;
334
+ }
335
+ catch (error) {
336
+ throw error;
337
+ }
338
+ });
339
+ }
306
340
  /**
307
341
  * Place a take profit or stop loss market order
308
342
  * default slippage is 0.08
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/hyperliquid-sdk",
3
- "version": "1.1.2-beta.10",
3
+ "version": "1.1.2-beta.11",
4
4
  "description": "Simplified Hyperliquid Perpetuals Trading SDK for Frontend Applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",