@rabby-wallet/hyperliquid-sdk 1.0.0-beta.16 → 1.0.0-beta.18

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.
@@ -48,6 +48,7 @@ const http_client_1 = require("./http-client");
48
48
  const constants_1 = require("../types/constants");
49
49
  const signer_1 = require("../utils/signer");
50
50
  const symbolConversion_1 = require("./symbolConversion");
51
+ const number_1 = require("../utils/number");
51
52
  /**
52
53
  * Client for executing trades on Hyperliquid (perpetuals only)
53
54
  * Only includes essential trading APIs as specified
@@ -163,7 +164,7 @@ class ExchangeClient {
163
164
  const decimals = ((_a = midPx.toString().split('.')[1]) === null || _a === void 0 ? void 0 : _a.length) || 0;
164
165
  const prepDecimals = Math.max(0, decimals - 1);
165
166
  const px = isBuy ? (Number(midPx) * (1 + slippage)).toFixed(prepDecimals) : (Number(midPx) * (1 - slippage)).toFixed(prepDecimals);
166
- return px;
167
+ return (0, number_1.removeTrailingZeros)(px);
167
168
  }
168
169
  /**
169
170
  * Place a market order
@@ -174,11 +175,11 @@ class ExchangeClient {
174
175
  return __awaiter(this, void 0, void 0, function* () {
175
176
  try {
176
177
  const slippage = params.slippage || constants_1.SLIPPAGE;
177
- const px = this.getSlippagePx(params.midPx, slippage, params.isBuy);
178
+ const px = this.getSlippagePx((0, number_1.removeTrailingZeros)(params.midPx), slippage, params.isBuy);
178
179
  const orders = [{
179
180
  coin: params.coin,
180
181
  isBuy: params.isBuy,
181
- sz: params.size,
182
+ sz: (0, number_1.removeTrailingZeros)(params.size),
182
183
  limitPx: px,
183
184
  reduceOnly: false,
184
185
  orderType: { limit: { tif: 'Ioc' } },
@@ -187,13 +188,13 @@ class ExchangeClient {
187
188
  const tpOrder = {
188
189
  coin: params.coin,
189
190
  isBuy: !params.isBuy,
190
- sz: params.size,
191
- limitPx: params.tpTriggerPx,
191
+ sz: (0, number_1.removeTrailingZeros)(params.size),
192
+ limitPx: (0, number_1.removeTrailingZeros)(params.tpTriggerPx),
192
193
  reduceOnly: true,
193
194
  orderType: {
194
195
  trigger: {
195
196
  isMarket: true,
196
- triggerPx: params.tpTriggerPx,
197
+ triggerPx: (0, number_1.removeTrailingZeros)(params.tpTriggerPx),
197
198
  tpsl: 'tp',
198
199
  }
199
200
  }
@@ -204,13 +205,13 @@ class ExchangeClient {
204
205
  const slOrder = {
205
206
  coin: params.coin,
206
207
  isBuy: !params.isBuy,
207
- sz: params.size,
208
- limitPx: params.slTriggerPx,
208
+ sz: (0, number_1.removeTrailingZeros)(params.size),
209
+ limitPx: (0, number_1.removeTrailingZeros)(params.slTriggerPx),
209
210
  reduceOnly: true,
210
211
  orderType: {
211
212
  trigger: {
212
213
  isMarket: true,
213
- triggerPx: params.slTriggerPx,
214
+ triggerPx: (0, number_1.removeTrailingZeros)(params.slTriggerPx),
214
215
  tpsl: 'sl',
215
216
  }
216
217
  }
@@ -235,7 +236,7 @@ class ExchangeClient {
235
236
  const orders = [{
236
237
  coin: params.coin,
237
238
  isBuy: params.isBuy,
238
- sz: params.size,
239
+ sz: (0, number_1.removeTrailingZeros)(params.size),
239
240
  limitPx: px,
240
241
  reduceOnly: true,
241
242
  orderType: { limit: { tif: 'Ioc' } },
@@ -266,8 +267,8 @@ class ExchangeClient {
266
267
  return {
267
268
  a: assetIndex,
268
269
  b: order.isBuy,
269
- p: order.limitPx,
270
- s: order.sz,
270
+ p: (0, number_1.removeTrailingZeros)(order.limitPx),
271
+ s: (0, number_1.removeTrailingZeros)(order.sz),
271
272
  r: order.reduceOnly || false,
272
273
  t: order.orderType || { limit: { tif: 'Gtc' } },
273
274
  };
@@ -299,12 +300,12 @@ class ExchangeClient {
299
300
  coin: params.coin,
300
301
  isBuy: !params.isBuy,
301
302
  sz: '0',
302
- limitPx: this.getSlippagePx(params.tpTriggerPx, constants_1.SLIPPAGE, !params.isBuy),
303
+ limitPx: this.getSlippagePx((0, number_1.removeTrailingZeros)(params.tpTriggerPx), constants_1.SLIPPAGE, !params.isBuy),
303
304
  reduceOnly: true,
304
305
  orderType: {
305
306
  trigger: {
306
307
  isMarket: true,
307
- triggerPx: params.tpTriggerPx,
308
+ triggerPx: (0, number_1.removeTrailingZeros)(params.tpTriggerPx),
308
309
  tpsl: 'tp',
309
310
  }
310
311
  }
@@ -315,12 +316,12 @@ class ExchangeClient {
315
316
  coin: params.coin,
316
317
  isBuy: !params.isBuy,
317
318
  sz: '0',
318
- limitPx: this.getSlippagePx(params.slTriggerPx, constants_1.SLIPPAGE, !params.isBuy),
319
+ limitPx: this.getSlippagePx((0, number_1.removeTrailingZeros)(params.slTriggerPx), constants_1.SLIPPAGE, !params.isBuy),
319
320
  reduceOnly: true,
320
321
  orderType: {
321
322
  trigger: {
322
323
  isMarket: true,
323
- triggerPx: params.slTriggerPx,
324
+ triggerPx: (0, number_1.removeTrailingZeros)(params.slTriggerPx),
324
325
  tpsl: 'sl',
325
326
  }
326
327
  }
@@ -371,8 +372,8 @@ class ExchangeClient {
371
372
  order: {
372
373
  a: yield this.symbolConversion.getAssetIndex(params.coin),
373
374
  b: params.isBuy,
374
- p: params.limitPx,
375
- s: params.sz,
375
+ p: (0, number_1.removeTrailingZeros)(params.limitPx),
376
+ s: (0, number_1.removeTrailingZeros)(params.sz),
376
377
  r: params.reduceOnly || false,
377
378
  t: params.orderType || { limit: { tif: 'Gtc' } },
378
379
  },
@@ -1,4 +1,4 @@
1
- import type { Meta, AssetCtx, ClearinghouseState, UserFills, CandleSnapshot, AllMids, ExtraAgent, OpenOrder, FeeResponse, UserNonFundingLedgerUpdates } from '../types';
1
+ import type { Meta, AssetCtx, ClearinghouseState, UserFills, CandleSnapshot, AllMids, ExtraAgent, OpenOrder, FeeResponse, UserNonFundingLedgerUpdates, UserHistoricalOrders } from '../types';
2
2
  export interface InfoClientConfig {
3
3
  isTestnet?: boolean;
4
4
  timeout?: number;
@@ -29,6 +29,10 @@ export declare class InfoClient {
29
29
  * Get user's fill history
30
30
  */
31
31
  getUserFills(address?: string, aggregateByTime?: boolean): Promise<UserFills>;
32
+ /**
33
+ * Get user's fill and cancel and other all orders history
34
+ */
35
+ getUserHistoricalOrders(address?: string, startTime?: number, endTime?: number): Promise<UserHistoricalOrders[]>;
32
36
  /**
33
37
  * Get candlestick data snapshot
34
38
  * Supported intervals: "1m", "3m", "5m", "15m", "30m", "1h", "2h", "4h", "8h", "12h", "1d", "3d", "1w", "1M"
@@ -109,6 +109,19 @@ class InfoClient {
109
109
  });
110
110
  });
111
111
  }
112
+ /**
113
+ * Get user's fill and cancel and other all orders history
114
+ */
115
+ getUserHistoricalOrders(address, startTime, endTime) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ return this.httpClient.info({
118
+ type: constants_1.InfoType.USER_HISTORICAL_ORDERS,
119
+ user: address || this.masterAddress,
120
+ startTime: startTime || 0,
121
+ endTime,
122
+ });
123
+ });
124
+ }
112
125
  /**
113
126
  * Get candlestick data snapshot
114
127
  * Supported intervals: "1m", "3m", "5m", "15m", "30m", "1h", "2h", "4h", "8h", "12h", "1d", "3d", "1w", "1M"
@@ -28,6 +28,7 @@ export declare enum ExchangeType {
28
28
  export declare enum InfoType {
29
29
  ALL_MIDS = "allMids",
30
30
  USER_NON_FUNDING_LEDGER_UPDATES = "userNonFundingLedgerUpdates",
31
+ USER_HISTORICAL_ORDERS = "historicalOrders",
31
32
  USER_OPEN_ORDERS = "openOrders",
32
33
  USER_FILLS = "userFills",
33
34
  USER_FILLS_BY_TIME = "userFillsByTime",
@@ -36,6 +36,7 @@ var InfoType;
36
36
  (function (InfoType) {
37
37
  InfoType["ALL_MIDS"] = "allMids";
38
38
  InfoType["USER_NON_FUNDING_LEDGER_UPDATES"] = "userNonFundingLedgerUpdates";
39
+ InfoType["USER_HISTORICAL_ORDERS"] = "historicalOrders";
39
40
  InfoType["USER_OPEN_ORDERS"] = "openOrders";
40
41
  InfoType["USER_FILLS"] = "userFills";
41
42
  InfoType["USER_FILLS_BY_TIME"] = "userFillsByTime";
@@ -9,6 +9,28 @@ export interface MarketOverview {
9
9
  assetContexts: AssetCtx[];
10
10
  marginTables: [number, MarginTable][];
11
11
  }
12
+ export interface UserHistoricalOrders {
13
+ order: {
14
+ coin: string;
15
+ side: Side;
16
+ limitPx: string;
17
+ sz: string;
18
+ oid: number;
19
+ timestamp: number;
20
+ triggerCondition: string;
21
+ isTrigger: boolean;
22
+ triggerPx: string;
23
+ children: any;
24
+ isPositionTpsl: boolean;
25
+ reduceOnly: boolean;
26
+ orderType: string;
27
+ origSz: string;
28
+ tif: string;
29
+ cloid: string | null;
30
+ };
31
+ status: string;
32
+ statusTimestamp: number;
33
+ }
12
34
  export interface OpenOrder {
13
35
  coin: string;
14
36
  side: Side;
@@ -229,6 +251,11 @@ export interface WsFill {
229
251
  crossed: boolean;
230
252
  fee: string;
231
253
  tid: number;
254
+ liquidation?: {
255
+ liquidatedUser: string;
256
+ markPx: string;
257
+ method: string;
258
+ };
232
259
  }
233
260
  export interface AssetCtx {
234
261
  dayBaseVlm: string;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Removes trailing zeros from a string representation of a number.
3
+ * This is useful when working with price and size fields directly.
4
+ *
5
+ * Hyperliquid API requires that price ('p') and size ('s') fields do not contain trailing zeros.
6
+ * For example, "12345.0" should be "12345" and "0.123450" should be "0.12345".
7
+ * This function ensures that all numeric string values are properly formatted.
8
+ *
9
+ * @param value - The string value to normalize
10
+ * @returns The normalized string without trailing zeros
11
+ */
12
+ export declare function removeTrailingZeros(value: string): string;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeTrailingZeros = removeTrailingZeros;
4
+ /**
5
+ * Removes trailing zeros from a string representation of a number.
6
+ * This is useful when working with price and size fields directly.
7
+ *
8
+ * Hyperliquid API requires that price ('p') and size ('s') fields do not contain trailing zeros.
9
+ * For example, "12345.0" should be "12345" and "0.123450" should be "0.12345".
10
+ * This function ensures that all numeric string values are properly formatted.
11
+ *
12
+ * @param value - The string value to normalize
13
+ * @returns The normalized string without trailing zeros
14
+ */
15
+ function removeTrailingZeros(value) {
16
+ if (!value.includes('.'))
17
+ return value;
18
+ const normalized = value.replace(/\.?0+$/, '');
19
+ if (normalized === '-0')
20
+ return '0';
21
+ return normalized;
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/hyperliquid-sdk",
3
- "version": "1.0.0-beta.16",
3
+ "version": "1.0.0-beta.18",
4
4
  "description": "Simplified Hyperliquid Perpetuals Trading SDK for Frontend Applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",