@rabby-wallet/hyperliquid-sdk 1.0.8-beta4 → 1.0.9-beta.1
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,4 +1,4 @@
|
|
|
1
|
-
import type { OrderResponse, CancelResponse, ExchangeClientConfig, PlaceOrderParams, MultiOrderParams, CancelOrderParams, ModifyOrderParams, WithdrawParams, ApproveBuilderFeeParams, PrepareApproveBuilderFeeResult, SendApproveParams, MarketOrderParams, UpdateLeverageParams, BindTpslByOrderIdParams } from '../types';
|
|
1
|
+
import type { OrderResponse, CancelResponse, ExchangeClientConfig, PlaceOrderParams, MultiOrderParams, CancelOrderParams, ModifyOrderParams, WithdrawParams, ApproveBuilderFeeParams, PrepareApproveBuilderFeeResult, SendApproveParams, MarketOrderParams, UpdateLeverageParams, BindTpslByOrderIdParams, UpdateIsolatedMarginParams } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Client for executing trades on Hyperliquid (perpetuals only)
|
|
4
4
|
* Only includes essential trading APIs as specified
|
|
@@ -41,7 +41,6 @@ export declare class ExchangeClient {
|
|
|
41
41
|
* @param slippage - Slippage rate (e.g., 0.08 for 8%)
|
|
42
42
|
* @param isBuy - True for buy orders, false for sell orders
|
|
43
43
|
* @param szDecimals - Size decimals from meta endpoint (default 0)
|
|
44
|
-
* @param isSpot - Whether this is a spot asset (default false for perps)
|
|
45
44
|
*/
|
|
46
45
|
private getSlippagePx;
|
|
47
46
|
/**
|
|
@@ -68,6 +67,7 @@ export declare class ExchangeClient {
|
|
|
68
67
|
* Modify an existing order
|
|
69
68
|
*/
|
|
70
69
|
modifyOrder(params: ModifyOrderParams): Promise<any>;
|
|
70
|
+
updateIsolatedMargin(params: UpdateIsolatedMarginParams): Promise<any>;
|
|
71
71
|
/**
|
|
72
72
|
* Set referrer for 10% fee
|
|
73
73
|
*/
|
|
@@ -179,7 +179,6 @@ class ExchangeClient {
|
|
|
179
179
|
* @param slippage - Slippage rate (e.g., 0.08 for 8%)
|
|
180
180
|
* @param isBuy - True for buy orders, false for sell orders
|
|
181
181
|
* @param szDecimals - Size decimals from meta endpoint (default 0)
|
|
182
|
-
* @param isSpot - Whether this is a spot asset (default false for perps)
|
|
183
182
|
*/
|
|
184
183
|
getSlippagePx(midPx, slippage, isBuy, szDecimals = 0) {
|
|
185
184
|
let px = parseFloat(midPx);
|
|
@@ -439,6 +438,24 @@ class ExchangeClient {
|
|
|
439
438
|
});
|
|
440
439
|
});
|
|
441
440
|
}
|
|
441
|
+
updateIsolatedMargin(params) {
|
|
442
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
443
|
+
const nonce = Date.now();
|
|
444
|
+
const assetIndex = yield this.symbolConversion.getAssetIndex(params.coin);
|
|
445
|
+
const action = {
|
|
446
|
+
asset: assetIndex,
|
|
447
|
+
isBuy: true,
|
|
448
|
+
ntli: (0, number_1.floatToInt)(params.value, 6), // 6 decimals
|
|
449
|
+
type: constants_1.ExchangeType.UPDATE_ISOLATED_MARGIN,
|
|
450
|
+
};
|
|
451
|
+
const signature = (0, signer_1.signL1AgentAction)(this.getAgentPrivateKey(), action, this.isTestnet, nonce);
|
|
452
|
+
return this.httpClient.exchange({
|
|
453
|
+
action,
|
|
454
|
+
nonce,
|
|
455
|
+
signature,
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
}
|
|
442
459
|
/**
|
|
443
460
|
* Set referrer for 10% fee
|
|
444
461
|
*/
|
|
@@ -92,7 +92,7 @@ class SymbolConversion {
|
|
|
92
92
|
yield this.ensureInitialized();
|
|
93
93
|
const szDecimals = this.assetSzDecimalsMap.get(assetSymbol);
|
|
94
94
|
if (szDecimals === undefined) {
|
|
95
|
-
throw new Error(`Unknown asset
|
|
95
|
+
throw new Error(`Unknown asset szDecimals: ${assetSymbol}`);
|
|
96
96
|
}
|
|
97
97
|
return szDecimals;
|
|
98
98
|
});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -393,6 +393,10 @@ export interface CancelOrderParams {
|
|
|
393
393
|
coin: string;
|
|
394
394
|
oid: OrderId;
|
|
395
395
|
}
|
|
396
|
+
export interface UpdateIsolatedMarginParams {
|
|
397
|
+
coin: string;
|
|
398
|
+
value: number;
|
|
399
|
+
}
|
|
396
400
|
export interface ModifyOrderParams {
|
|
397
401
|
oid: OrderId;
|
|
398
402
|
coin: string;
|
package/dist/utils/number.d.ts
CHANGED
package/dist/utils/number.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.removeTrailingZeros = removeTrailingZeros;
|
|
4
|
+
exports.floatToInt = floatToInt;
|
|
4
5
|
/**
|
|
5
6
|
* Removes trailing zeros from a string representation of a number.
|
|
6
7
|
* This is useful when working with price and size fields directly.
|
|
@@ -20,3 +21,10 @@ function removeTrailingZeros(value) {
|
|
|
20
21
|
return '0';
|
|
21
22
|
return normalized;
|
|
22
23
|
}
|
|
24
|
+
function floatToInt(x, power) {
|
|
25
|
+
const withDecimals = x * Math.pow(10, power);
|
|
26
|
+
if (Math.abs(Math.round(withDecimals) - withDecimals) >= 1e-3) {
|
|
27
|
+
throw new Error(`floatToInt causes rounding: ${x}`);
|
|
28
|
+
}
|
|
29
|
+
return Math.round(withDecimals);
|
|
30
|
+
}
|
package/package.json
CHANGED