Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions examples/priority_fees.py
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 8 additions & 0 deletions hyperliquid/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 4 additions & 2 deletions hyperliquid/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion hyperliquid/utils/signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]}
)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <hello@hyperliquid.xyz>"]
Expand Down
Loading