diff --git a/examples/priority_fees.py b/examples/priority_fees.py new file mode 100644 index 0000000..b4fbdb9 --- /dev/null +++ b/examples/priority_fees.py @@ -0,0 +1,27 @@ +import example_utils + +from hyperliquid.utils import constants + + +def main(): + address, info, exchange = example_utils.setup(base_url=constants.TESTNET_API_URL, skip_ws=True, perp_dexs=["test"]) + + # Place a bid on gossip priority slot 0 + bid_result = exchange.gossip_priority_bid(0, "8.8.8.8", 1) + print(bid_result) + + # Place an order with priority fee that should be rejected by setting the price very low + order = { + "coin": "test:ABC", + "is_buy": True, + "sz": 100, + "limit_px": 0.9, + "order_type": {"limit": {"tif": "Ioc"}}, + "reduce_only": False, + } + order_result = exchange.bulk_orders([order], grouping={"p": 12345}) + print(order_result) + + +if __name__ == "__main__": + main() diff --git a/hyperliquid/exchange.py b/hyperliquid/exchange.py index 688f640..8e560f3 100644 --- a/hyperliquid/exchange.py +++ b/hyperliquid/exchange.py @@ -1198,3 +1198,11 @@ def noop(self, nonce): self.wallet, action, self.vault_address, nonce, self.expires_after, self.base_url == MAINNET_API_URL ) return self._post_action(action, signature, nonce) + + def gossip_priority_bid(self, slot_id, ip, max_gas): + nonce = get_timestamp_ms() + action = {"type": "gossipPriorityBid", "slotId": slot_id, "ip": ip, "maxGas": max_gas} + signature = sign_l1_action( + self.wallet, action, self.vault_address, nonce, self.expires_after, self.base_url == MAINNET_API_URL + ) + return self._post_action(action, signature, nonce) diff --git a/hyperliquid/info.py b/hyperliquid/info.py index a86ac80..360d058 100644 --- a/hyperliquid/info.py +++ b/hyperliquid/info.py @@ -39,14 +39,16 @@ def __init__( self.name_to_coin = {} self.asset_to_sz_decimals = {} + token_by_index = {token["index"]: token for token in spot_meta["tokens"]} + # spot assets start at 10000 for spot_info in spot_meta["universe"]: asset = spot_info["index"] + 10000 self.coin_to_asset[spot_info["name"]] = asset self.name_to_coin[spot_info["name"]] = spot_info["name"] base, quote = spot_info["tokens"] - base_info = spot_meta["tokens"][base] - quote_info = spot_meta["tokens"][quote] + base_info = token_by_index[base] + quote_info = token_by_index[quote] self.asset_to_sz_decimals[asset] = base_info["szDecimals"] name = f'{base_info["name"]}/{quote_info["name"]}' if name not in self.name_to_coin: diff --git a/hyperliquid/utils/signing.py b/hyperliquid/utils/signing.py index 10cca4d..5604147 100644 --- a/hyperliquid/utils/signing.py +++ b/hyperliquid/utils/signing.py @@ -42,7 +42,8 @@ CancelRequest = TypedDict("CancelRequest", {"coin": str, "oid": int}) CancelByCloidRequest = TypedDict("CancelByCloidRequest", {"coin": str, "cloid": Cloid}) -Grouping = Union[Literal["na"], Literal["normalTpsl"], Literal["positionTpsl"]] +PriorityGrouping = TypedDict("PriorityGrouping", {"p": int}) +Grouping = Union[Literal["na"], Literal["normalTpsl"], Literal["positionTpsl"], PriorityGrouping] Order = TypedDict( "Order", {"asset": int, "isBuy": bool, "limitPx": float, "sz": float, "reduceOnly": bool, "cloid": Optional[Cloid]} ) diff --git a/pyproject.toml b/pyproject.toml index a749590..ba2e07d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "hyperliquid-python-sdk" -version = "0.22.0" +version = "0.23.0" description = "SDK for Hyperliquid API trading with Python." readme = "README.md" authors = ["Hyperliquid "]