From 57a31d14ded2446e7bd153fc00bd0cefa17c92a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mihael=20=C5=A0inkec?= <44239392+msinkec@users.noreply.github.com> Date: Tue, 30 Dec 2025 09:29:07 +0000 Subject: [PATCH] feat: add halt trading action for HIP-3 perps --- examples/perp_deploy.py | 24 +++++++++++++++++------- hyperliquid/exchange.py | 23 +++++++++++++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/examples/perp_deploy.py b/examples/perp_deploy.py index ffffac78..60093cdd 100644 --- a/examples/perp_deploy.py +++ b/examples/perp_deploy.py @@ -10,6 +10,12 @@ REGISTER_PERP_DEX = False DUMMY_DEX = "test" +COIN_0 = f"{DUMMY_DEX}:TEST0" +COIN_1 = f"{DUMMY_DEX}:TEST1" + +# Trading on a newly deployed perp is halted by default. +# Set to True to enable trading on the new perp. +ENABLE_TRADING = True def main(): @@ -34,7 +40,7 @@ def main(): register_asset_result = exchange.perp_deploy_register_asset( dex=DUMMY_DEX, max_gas=1000000000000, - coin=f"{DUMMY_DEX}:TEST0", + coin=COIN_0, sz_decimals=2, oracle_px="10.0", margin_table_id=10, @@ -45,24 +51,28 @@ def main(): # If registration is successful, the "dex" that was used can serve as the index into this clearinghouse for later asset # registrations and oracle updates. + if ENABLE_TRADING: + print(f"\nEnabling trading on {COIN_0}...") + halt_result = exchange.perp_deploy_halt_trading(coin=COIN_0, is_halted=False) + # Step 2: Set the Oracle Prices # # Oracle updates can be sent multiple times set_oracle_result = exchange.perp_deploy_set_oracle( DUMMY_DEX, { - f"{DUMMY_DEX}:TEST0": "12.0", - f"{DUMMY_DEX}:TEST1": "1.0", + COIN_0: "12.0", + COIN_1": "1.0", }, [ { - f"{DUMMY_DEX}:TEST1": "3.0", - f"{DUMMY_DEX}:TEST0": "14.0", + COIN_1: "3.0", + COIN_0: "14.0", } ], { - f"{DUMMY_DEX}:TEST0": "12.1", - f"{DUMMY_DEX}:TEST1": "1.1", + COIN_0: "12.1", + COIN_1: "1.1", }, ) print("set oracle result:", set_oracle_result) diff --git a/hyperliquid/exchange.py b/hyperliquid/exchange.py index cc539fa1..9d84eb93 100644 --- a/hyperliquid/exchange.py +++ b/hyperliquid/exchange.py @@ -949,6 +949,29 @@ def perp_deploy_set_oracle( timestamp, ) + def perp_deploy_halt_trading(self, coin: str, is_halted: bool) -> Any: + timestamp = get_timestamp_ms() + action = { + "type": "perpDeploy", + "haltTrading": { + "coin": coin, + "isHalted": is_halted, + }, + } + signature = sign_l1_action( + self.wallet, + action, + None, + timestamp, + self.expires_after, + self.base_url == MAINNET_API_URL, + ) + return self._post_action( + action, + signature, + timestamp, + ) + def c_signer_unjail_self(self) -> Any: return self.c_signer_inner("unjailSelf")