View Source Hyperliquid.Api.Exchange.Order (hyperliquid v0.2.2)
Place orders on Hyperliquid.
Supports limit orders, trigger orders (stop-loss/take-profit), and batch ordering.
See: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint
Summary
Functions
Build a limit order.
Build a limit order using coin symbol.
Build a market order (IOC limit order at far price).
Build a market order using coin symbol.
Place a single order.
Place multiple orders in a batch.
Build and place a limit order in one call.
Build and place a market order in one call.
Build and place a trigger order in one call.
Build a trigger order (stop-loss or take-profit).
Build a trigger order using coin symbol.
Types
@type builder_info() :: %{builder: String.t(), fee: non_neg_integer()}
@type grouping() :: :na | :normal_tpsl | :position_tpsl
@type order() :: limit_order() | trigger_order()
@type order_opts() :: [vault_address: String.t(), builder: builder_info()]
Functions
@spec limit(non_neg_integer(), boolean(), String.t(), String.t(), keyword()) :: limit_order()
Build a limit order.
Parameters
asset: Asset indexis_buy: true for buy, false for selllimit_px: Limit price as stringsz: Size as stringopts: Optional parameters
Options
:reduce_only- Only reduce position (default: false):tif- Time in force: "Gtc", "Ioc", "Alo" (default: "Gtc"):cloid- Client order ID
Examples
Order.limit(0, true, "50000.0", "0.1")
Order.limit(0, true, "50000.0", "0.1", tif: "Ioc", cloid: "my-order-1")
@spec limit_order( String.t(), boolean(), number() | String.t(), number() | String.t(), keyword() ) :: limit_order() | {:error, term()}
Build a limit order using coin symbol.
Automatically looks up asset index and formats price/size.
Parameters
coin: Coin symbol (e.g., "BTC", "ETH", "HYPE/USDC")is_buy: true for buy, false for selllimit_px: Limit pricesz: Sizeopts: Optional parameters (seelimit/5)
Examples
Order.limit_order("BTC", true, 50000.0, 0.1)
Order.limit_order("ETH", false, "3500.5", "1.5", tif: "Ioc")
@spec market(non_neg_integer(), boolean(), String.t(), keyword()) :: limit_order()
Build a market order (IOC limit order at far price).
Parameters
asset: Asset indexis_buy: true for buy, false for sellsz: Size as stringopts: Optional parameters
Options
:slippage_price- Far limit price for slippage protection (auto-calculated if not provided):slippage- Slippage percentage (default: 0.05 = 5%):reduce_only- Only reduce position (default: false):cloid- Client order ID
When :slippage_price is not provided, the coin is resolved from the asset index
via cache reverse lookup and the mid price is used to calculate slippage.
Examples
# Automatic price lookup (resolves coin from asset index)
Order.market(0, true, "0.1")
# With explicit slippage price
Order.market(0, true, "0.1", slippage_price: "100000.0")
@spec market_order(String.t(), boolean(), number() | String.t(), keyword()) :: limit_order() | {:error, term()}
Build a market order using coin symbol.
Automatically looks up asset index, mid price, and formats size.
Parameters
coin: Coin symbolis_buy: true for buy, false for sellsz: Sizeopts: Optional parameters:slippage- Slippage percentage (default: 0.05 = 5%):slippage_price- Explicit far price (overrides automatic calculation):reduce_only- Only reduce position:cloid- Client order ID
Examples
Order.market_order("BTC", true, 0.1)
Order.market_order("ETH", false, 1.5, slippage: 0.03)
@spec place(order(), order_opts()) :: {:ok, order_response()} | {:error, term()}
Place a single order.
Parameters
Options
:private_key- Private key for signing (falls back to config):vault_address- Trade on behalf of a vault:builder- Builder info for builder fee
Returns
{:ok, response}- Order placement result{:error, term()}- Error details
Examples
order = Order.limit(0, true, "50000.0", "0.1")
{:ok, result} = Order.place(order)Breaking Change (v0.2.0)
private_key was previously the first positional argument. It is now
an option in the opts keyword list (:private_key).
@spec place_batch([order()], grouping(), order_opts()) :: {:ok, order_response()} | {:error, term()}
Place multiple orders in a batch.
Parameters
orders: List of ordersgrouping: Order grouping strategyopts: Optional parameters
Grouping Options
:na- No grouping (default):normal_tpsl- Group TP/SL with entry order:position_tpsl- Attach TP/SL to existing position
Options
:private_key- Private key for signing (falls back to config):vault_address- Trade on behalf of a vault:builder- Builder info for builder fee
Returns
{:ok, response}- Batch order result{:error, term()}- Error details
Examples
orders = [
Order.limit(0, true, "50000.0", "0.1"),
Order.limit(0, true, "49000.0", "0.1")
]
{:ok, result} = Order.place_batch(orders, :na)Breaking Change (v0.2.0)
private_key was previously the first positional argument. It is now
an option in the opts keyword list (:private_key).
Build and place a limit order in one call.
Parameters
coin: Coin symbolis_buy: true for buy, false for selllimit_px: Limit pricesz: Sizeopts: Optional parameters (seelimit_order/5andplace/3)
Options
:private_key- Private key for signing (falls back to config)
Examples
{:ok, result} = Order.place_limit("BTC", true, 50000, 0.1)
{:ok, result} = Order.place_limit("ETH", false, 3500, 1.5, tif: "Ioc", private_key: "abc...")Breaking Change (v0.2.0)
private_key was previously the first positional argument. It is now
an option in the opts keyword list (:private_key).
Build and place a market order in one call.
Parameters
coin: Coin symbolis_buy: true for buy, false for sellsz: Sizeopts: Optional parameters (seemarket_order/4andplace/3)
Options
:private_key- Private key for signing (falls back to config)
Examples
{:ok, result} = Order.place_market("BTC", true, 0.1)
{:ok, result} = Order.place_market("ETH", false, 1.5, slippage: 0.03)Breaking Change (v0.2.0)
private_key was previously the first positional argument. It is now
an option in the opts keyword list (:private_key).
Build and place a trigger order in one call.
Parameters
coin: Coin symbolis_buy: true for buy, false for selllimit_px: Limit pricesz: Sizetrigger_px: Trigger priceopts: Optional parameters (seetrigger_order/6andplace/3)
Options
:private_key- Private key for signing (falls back to config)
Examples
{:ok, result} = Order.place_trigger("BTC", false, 48000, 0.1, 49000, tpsl: "sl")Breaking Change (v0.2.0)
private_key was previously the first positional argument. It is now
an option in the opts keyword list (:private_key).
@spec trigger( non_neg_integer(), boolean(), String.t(), String.t(), String.t(), keyword() ) :: trigger_order()
Build a trigger order (stop-loss or take-profit).
Parameters
asset: Asset indexis_buy: true for buy, false for selllimit_px: Limit price as string (use far price for market trigger)sz: Size as stringtrigger_px: Trigger price as stringopts: Optional parameters
Options
:reduce_only- Only reduce position (default: false):is_market- Execute as market order when triggered (default: true):tpsl- "sl" for stop-loss, "tp" for take-profit (default: "sl"):cloid- Client order ID
Examples
# Stop-loss at 49000
Order.trigger(0, false, "48000.0", "0.1", "49000.0", tpsl: "sl")
# Take-profit at 55000
Order.trigger(0, false, "56000.0", "0.1", "55000.0", tpsl: "tp")
@spec trigger_order( String.t(), boolean(), number() | String.t(), number() | String.t(), number() | String.t(), keyword() ) :: trigger_order() | {:error, term()}
Build a trigger order using coin symbol.
Automatically looks up asset index and formats price/size.
Parameters
coin: Coin symbolis_buy: true for buy, false for selllimit_px: Limit pricesz: Sizetrigger_px: Trigger priceopts: Optional parameters (seetrigger/6)
Examples
# Stop-loss
Order.trigger_order("BTC", false, 48000, 0.1, 49000, tpsl: "sl")
# Take-profit
Order.trigger_order("BTC", false, 56000, 0.1, 55000, tpsl: "tp")