跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
设计与 UI

hyperliquid-orders

Place, cancel and modify Hyperliquid orders correctly from the desk computer - limit and IOC (market-style) orders, take-profit and stop-loss trigger orders with grouping, client order ids, reduce-only, batch actions, price and size rounding, and how to read every response status. Write path - Execution Trader only, on an approved ticket. Use for any order action and for reconciling by cloid.

galleonlabs · 已有 AI 审核记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add galleonlabs/hypergrok-trading-desk --skill hyperliquid-orders

技能说明


name: hyperliquid-orders description: Place, cancel and modify Hyperliquid orders correctly from the desk computer - limit and IOC (market-style) orders, take-profit and stop-loss trigger orders with grouping, client order ids, reduce-only, batch actions, price and size rounding, and how to read every response status. Write path - Execution Trader only, on an approved ticket. Use for any order action and for reconciling by cloid. license: MIT metadata: version: "1.1.0" author: Galleon Labs category: hyperliquid network-default: testnet

Hyperliquid orders

Everything here ends in a signed request to /exchange. On this desk only the Execution Trader runs it, only on a ticket with a Risk PASS and the user's approval by id, and only once per approval (desk-execution-protocol). Reads used for reconciliation are in hyperliquid-account.

Concepts you must get right

  • Asset index, not symbol. Perps use the index of the coin in meta.universe (BTC is 0 on mainnet, but never hardcode: read meta). Spot uses 10000 + index in spotMeta.universe. The Python SDK's Exchange accepts the coin name and resolves the index; the TS SDK wants the number.
  • Price rounding. At most 5 significant figures, and at most 6 - szDecimals decimal places for perps (8 - szDecimals for spot). Integer prices are always valid. Wrong precision is rejected by the exchange.
  • Size rounding. Round down to the market's szDecimals. Never round up.
  • Minimum order value is 10 USD notional.
  • Time in force: Gtc rests until filled or cancelled; Ioc fills what it can immediately and cancels the rest; Alo (add liquidity only) rests or is rejected if it would take.
  • There is no market order. A market-style order is an Ioc limit at a price bounded by your slippage tolerance (buy: above mid; sell: below mid).
  • reduceOnly orders can only reduce an existing position; use it for exits, stops and take-profits.
  • cloid (client order id) is 0x + 32 hex characters (16 bytes). Unique per order. It lets you query and cancel an order even if the response was lost.
  • Trigger orders (tp/sl): triggerPx is the mark price that arms the order; isMarket: true executes market-style once triggered, false places a limit at p. p is always required and acts as the worst-acceptable price after the trigger, so for market triggers set it beyond the trigger: a sell trigger's p below triggerPx, a buy trigger's p above it. A stop whose p equals its trigger can rest unfilled through a gap, so the desk defaults to a 5% bound for stop-losses (filling matters more than slippage) and 1% for take-profits; the app uses 10% for both. The ticket may override.
  • Grouping: na (independent orders); normalTpsl (entry plus TP/SL as one-cancels-other tied to that entry: children are sized to the entry, placed only when it fills, cancelled if it is cancelled, and when one child fills the sibling is cancelled); positionTpsl (TP/SL tied to the position rather than to an order, shown as the position's own TP/SL, isPositionTpsl: true). Every TP/SL with an explicit size is fixed-size once placed; it does not resize when the position changes. The app's "entire position" TP/SL is a reduce-only trigger sent with size 0 under positionTpsl grouping (such orders show up live in frontendOpenOrders as sz: "0.0", isPositionTpsl: true); rehearse it on testnet before the desk relies on it.
  • Responses: each order in an action gets a status: {"resting": {"oid": ...}}, {"filled": {"totalSz", "avgPx", "oid"}}, "waitingForTrigger", "waitingForFill", or {"error": "..."}. A top-level {"status": "err", "response": "..."} means the whole action was rejected.

Python (official SDK, hyperliquid-python-sdk)

Common header for every snippet below (network, account, key loader, rounding helpers):

import os, secrets
from decimal import Decimal, ROUND_DOWN, ROUND_HALF_UP
import eth_account
from hyperliquid.exchange import Exchange
from hyperliquid.info import Info
from hyperliquid.utils import constants
from hyperliquid.utils.types import Cloid

def load_key():
    k = os.environ.get("HYPERLIQUID_PRIVATE_KEY")
    if not k:
        p = os.path.expanduser("~/.hyperliquid/api-wallet.key")
        if os.path.exists(p):
            k = open(p).read().strip()
    if not k:
        raise SystemExit("no API wallet key available - see hyperliquid-setup section 4")
    return k

NETWORK = os.environ.get("HYPERLIQUID_NETWORK", "testnet")
BASE = constants.MAINNET_API_URL if NETWORK == "mainnet" else constants.TESTNET_API_URL
ACCOUNT = os.environ["HYPERLIQUID_ACCOUNT_ADDRESS"]           # main account the API wallet acts for

info = Info(BASE, skip_ws=True)
exchange = Exchange(eth_account.Account.from_key(load_key()), BASE, account_address=ACCOUNT)

SZ_DECIMALS = {a["name"]: a["szDecimals"] for a in info.meta()["universe"]}

def round_px(coin, px, spot=False):
    """5 significant figures, then at most (6|8) - szDecimals decimals. Integers are always valid,
    so above 100,000 keep whole-dollar precision instead of rounding to tens."""
    px = float(px)
    if px >= 100_000:
        return float(round(px))
    max_dec = max((8 if spot else 6) - SZ_DECIMALS[coin], 0)
    px = float(f"{px:.5g}")
    return float(Decimal(str(px)).quantize(Decimal(1).scaleb(-max_dec), rounding=ROUND_HALF_UP))

def round_sz(coin, sz):
    """Round DOWN to szDecimals (Decimal, so 0.29 stays 0.29 and never becomes 0.28)."""
    return float(Decimal(str(sz)).quantize(Decimal(1).scaleb(-SZ_DECIMALS[coin]), rounding=ROUND_DOWN))

def new_cloid():
    return Cloid.from_str("0x" + secrets.token_hex(16))

Resting limit order (Gtc)

coin, is_buy, sz, px = "ETH", True, round_sz("ETH", 0.51), round_px("ETH", 3000)
assert sz * px >= 10, "below 10 USD minimum order value"
cloid = new_cloid()
print("cloid", cloid.to_raw())                     # write this 
阅读完整来源 ↗