@rabby-wallet/hyperliquid-sdk 1.0.0-beta.15 → 1.0.0-beta.17
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
|
},
|
|
@@ -28,7 +28,7 @@ export declare class InfoClient {
|
|
|
28
28
|
/**
|
|
29
29
|
* Get user's fill history
|
|
30
30
|
*/
|
|
31
|
-
getUserFills(address?: string): Promise<UserFills>;
|
|
31
|
+
getUserFills(address?: string, aggregateByTime?: boolean): Promise<UserFills>;
|
|
32
32
|
/**
|
|
33
33
|
* Get candlestick data snapshot
|
|
34
34
|
* Supported intervals: "1m", "3m", "5m", "15m", "30m", "1h", "2h", "4h", "8h", "12h", "1d", "3d", "1w", "1M"
|
|
@@ -100,11 +100,12 @@ class InfoClient {
|
|
|
100
100
|
/**
|
|
101
101
|
* Get user's fill history
|
|
102
102
|
*/
|
|
103
|
-
getUserFills(address) {
|
|
103
|
+
getUserFills(address, aggregateByTime) {
|
|
104
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
105
|
return this.httpClient.info({
|
|
106
106
|
type: constants_1.InfoType.USER_FILLS,
|
|
107
107
|
user: address || this.masterAddress,
|
|
108
|
+
aggregateByTime: aggregateByTime || true,
|
|
108
109
|
});
|
|
109
110
|
});
|
|
110
111
|
}
|
|
@@ -184,7 +184,7 @@ class WebSocketClient {
|
|
|
184
184
|
*/
|
|
185
185
|
subscribeToUserFills(callback) {
|
|
186
186
|
return this.subscribe({
|
|
187
|
-
subscription: { type: 'userFills', user: this.config.masterAddress },
|
|
187
|
+
subscription: { type: 'userFills', user: this.config.masterAddress, aggregateByTime: true },
|
|
188
188
|
}, callback);
|
|
189
189
|
}
|
|
190
190
|
/**
|
|
@@ -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