Quickstart
You need a Hyperliquid account on testnet with perps balance, at least 10 HYPE in its staking balance (priority fees are paid from there), and a trade-only agent key approved by that account. The Execute page walks through all three and creates the agent key for you.
- Install the SDK:
pnpm add @velocity/sdk - Connect in local mode with your agent key and price an order.
- Execute it. The order goes from your process straight to Hyperliquid.
import { Velocity } from "@velocity/sdk";
// Local mode: the fee model runs in your process against your own
// market-data subscription. No network hop sits before the order.
const client = await Velocity.connect({
network: "testnet",
mode: "local",
agentKey: process.env.HL_AGENT_KEY, // trade-only key; cannot withdraw
account: "0xYourMainWallet",
});
const quote = client.quote({
market: "BTC",
side: "buy",
notionalUsd: 25_000,
urgency: "high",
maxPriorityBps: 4,
maxSlippageBps: 5,
});
console.log(quote.recommendedBps, quote.p); // e.g. 4 40000
// Builds the IOC with grouping {"p": quote.p}, checks your on-chain
// policy, signs with the agent key and sends it straight to Hyperliquid.
const result = await client.executeIoc(quote);
console.log(result.status, result.fillPx, result.priorityFeeUsd);Prefer plain HTTP? One request returns the same recommendation:
curl -s -X POST "$ENGINE_URL/v1/quote" \
-H "content-type: application/json" \
-H "x-api-key: $VELOCITY_API_KEY" \
-d '{
"market": "BTC",
"side": "buy",
"notionalUsd": 25000,
"urgency": "high",
"maxPriorityBps": 4,
"maxSlippageBps": 5
}'Priority fees in one page
A Hyperliquid order action can carry "grouping": {"p": N}. The fee rate is N / 1e8 of notional, so 10000 is 1 bp and 80000 is 8 bps.
- IOC orders are sorted in the mempool by arrival time minus a credit for the fee. Hyperliquid reports the effect as about 45 ms of end-to-end latency per 1 bp, linear from 0 to 8 bps. Above 8 bps the time preference is flat; orders at or above the cap are ordered by fee inside each 70 ms block.
- The fee is charged on filled notional, paid in HYPE from the account’s undelegated staking balance at the spot mark price, and burned. An IOC that does not fill pays nothing.
- Cancels always go first. No fee puts an IOC ahead of a cancel sent at the same time.
- Requirements. The account needs at least 10 HYPE of staking balance and must be in standard account mode. Every order in the action must be an IOC on a non-outcome asset.
- One thing to avoid. Any action other than orders, modifies and cancels (an approval, a transfer) deprioritises all of the account’s orders until it commits. Do approvals well before you trade.
An order with a 4 bps priority fee and a builder fee looks like this on the wire:
{
"type": "order",
"orders": [
{ "a": 3, "b": true, "p": "59399", "s": "0.42095", "r": false,
"t": { "limit": { "tif": "Ioc" } } }
],
"grouping": { "p": 40000 },
"builder": { "b": "0xbuilder…", "f": 5 }
}API reference
Generated from the engine’s OpenAPI document, which it serves at /openapi.json. All bodies are JSON. Times are Unix milliseconds; costs are basis points of notional.
- Authentication. Send an API key as
x-api-key. Public read endpoints work without one inside the free tier. Key management uses a session from Sign-In with Ethereum on Elysium Testnet (chain 99801). - Rate limits. Per key, or per IP without one. A
429carriesretry-afterin seconds. - Errors.
{"error": "code", "message": "what to do"}with a 4xx status.
Market data
GET/v1/marketsMarket states, regimes and recommended feesshow
Returns every supported market with its mid, spread, depth, volatility, regime and the recommended priority fee at each urgency for the reference order described in `reference`.
Auth: public / Errors: 429
GET/v1/scheduleLatency schedule constantsshow
The schedule the model uses (milliseconds per basis point, and the cap), where those constants came from, and our own measurement of the slope when there are enough executions to make one.
Auth: public
{
"kMsPerBp": 45,
"capBps": 8,
"bucketMs": 70,
"gridBps": [
0,
0.25,
0.5,
1,
1.5,
2,
3,
4,
6,
8
],
"modelVersion": "v1.0.0",
"source": "published",
"measured": null
}GET/v1/streamLive recommendations (WebSocket)show
Upgrade to a WebSocket. The server sends `{"type":"markets","asOf":…,"markets":[…]}` about once a second with every market's state and recommended fees, and `{"type":"priority","order":{…}}` for each priority order it observes. No messages need to be sent by the client.
Auth: public
Quotes
POST/v1/quotePrice one ordershow
Evaluates the order at every fee level on the model grid at or under `maxPriorityBps` and returns the cheapest in expectation, the integer `p` to place in the order action's `grouping`, and the full cost curve. Quotes expire after 2 seconds; price again rather than reuse one.
Auth: API key (optional on the free tier) / Errors: 400, 401, 429
{
"market": "BTC",
"side": "buy",
"notionalUsd": 25000,
"urgency": "high",
"maxPriorityBps": 4,
"maxSlippageBps": 5
}{
"quoteId": "q_m3x9k2_1f8",
"market": "BTC",
"side": "buy",
"recommendedBps": 4,
"p": 40000,
"chosen": {
"feeBps": 4,
"p": 40000,
"delayMs": 180,
"msBought": 180,
"fillProb": 0.998,
"fee": 3.99,
"delayCost": 1.21,
"missCost": 0.02,
"impact": 0.31,
"builder": 0.5,
"total": 6.03
},
"zero": {
"feeBps": 0,
"p": 0,
"delayMs": 360,
"msBought": 0,
"fillProb": 0.97,
"fee": 0,
"delayCost": 7.9,
"missCost": 0.4,
"impact": 0.31,
"builder": 0.5,
"total": 9.11
},
"curve": [
{
"feeBps": 4,
"p": 40000,
"delayMs": 180,
"msBought": 180,
"fillProb": 0.998,
"fee": 3.99,
"delayCost": 1.21,
"missCost": 0.02,
"impact": 0.31,
"builder": 0.5,
"total": 6.03
}
],
"expectedGainBps": 3.08,
"ceilingBps": 4,
"regime": "extreme",
"mid": 59370.5,
"limitPx": 59400.19,
"sigma": 0.42,
"impactBps": 0.31,
"builderFeeBps": 0.5,
"warnings": [],
"modelVersion": "v1.0.0",
"asOf": 1795908322917,
"expiresAt": 1795908324917,
"decisionMicros": 46,
"inputs": {
"market": "BTC",
"side": "buy",
"notionalUsd": 25000,
"urgency": "high",
"maxPriorityBps": 4,
"maxSlippageBps": 5
}
}Priority fees
GET/v1/priority/statsFee Explorer datashow
Priority fees paid across the market over the last 24 hours: totals, per-market distributions, an hour-by-weekday heatmap and the most recent priority orders. `source.coverage` says whether the numbers are complete or scaled from a sample.
Auth: public / Errors: 429
Executions
POST/v1/executionsReport an executionshow
Opt-in. The SDK and the app send one report per order after the exchange responds. Authenticate with an API key or a wallet session; the report's `wallet` must match the caller. Reports feed your History page, the network analytics and the next attestation batch.
Auth: API key (optional on the free tier) / Errors: 400, 401, 429
{
"id": "0x7c1e…a9"
}GET/v1/executionsA wallet's executionsshow
Auth: public / Errors: 400, 429
| Parameter | In | Description |
|---|---|---|
| wallet * | query | Wallet address |
| market | query | Filter by market |
| side | query | One of the listed values |
| status | query | One of the listed values |
| from | query | Earliest submit time, Unix ms |
| to | query | Latest submit time, Unix ms |
| limit | query | Page size, default 500, maximum 1000 |
| offset | query | Rows to skip |
GET/v1/analyticsNetwork and per-wallet analyticsshow
Optimized volume, average fee paid, decision latency and measured cost against the baseline arm. `costVsBaseline.sufficient` is false until each arm has the minimum sample size; clients must not present a saving before then.
Auth: public / Errors: 429
| Parameter | In | Description |
|---|---|---|
| wallet | query | Include this wallet's own analytics |
GET/v1/benchmarksExperiment resultsshow
Per-arm implementation shortfall, fill ratio, time to fill and fee paid for the randomized experiment (zero fee, fixed 1 bp, adaptive), with bootstrap 95% intervals, overall and per market.
Auth: public / Errors: 429
Attestations
GET/v1/attestationsPosted batchesshow
Auth: public / Errors: 429
GET/v1/attestations/proof/{executionId}Merkle proof for one executionshow
Returns the record, its hash, its leaf, the sibling path and the batch root. Verify it yourself, or call `ExecutionRegistry.verifyExecution(batchId, executionId, wallet, recordHash, proof)` on Elysium, which derives the leaf from the record's identity.
Auth: public / Errors: 404, 429
| Parameter | In | Description |
|---|---|---|
| executionId * | path | 32-byte execution id |
Account
GET/v1/policy/{wallet}A wallet's execution policyshow
Read from a cache of the ExecutionPolicy contract's events. `policy` is null when the wallet has never set one.
Auth: public / Errors: 400, 429
| Parameter | In | Description |
|---|---|---|
| wallet * | path | Wallet address |
GET/v1/credits/{wallet}Credit balance and usageshow
Auth: public / Errors: 400, 429
| Parameter | In | Description |
|---|---|---|
| wallet * | path | Wallet address |
GET/v1/auth/nonceStart Sign-In with Ethereumshow
Auth: public
| Parameter | In | Description |
|---|---|---|
| address * | query | Wallet address |
{
"nonce": "k3J9x1Qp7Lm2",
"issuedAt": "2026-11-28T14:03:22.000Z"
}POST/v1/auth/verifyFinish Sign-In with Ethereumshow
Send the EIP-4361 message and its signature. The message's chain id must be the Elysium chain for the engine's network and its nonce must be one issued within the last 10 minutes.
Auth: public / Errors: 400, 401
GET/v1/keysList API keysshow
Auth: session / Errors: 401
POST/v1/keysCreate an API keyshow
The full key is returned once, in `secret`. Only a hash is stored.
Auth: session / Errors: 400, 401
{
"label": "Trading bot"
}DELETE/v1/keys/{id}Revoke an API keyshow
Auth: session / Errors: 401, 404
| Parameter | In | Description |
|---|---|---|
| id * | path | Key id |
System
GET/v1/statusEngine statusshow
Auth: public
TypeScript SDK
@velocity/sdk does four things: prices an order, builds the order action, checks your on-chain policy, and signs and sends an IOC with your agent key. It never sees your main wallet’s key and cannot withdraw.
| Method | What it does |
|---|---|
quote(order) | Returns the recommendation, p, the cost curve and the limit price. Synchronous in local mode, a promise in remote mode. |
buildOrderAction(quote) | Returns the exact action that would be signed, with price and size rounded to the market’s precision, so you can inspect it first. |
executeIoc(quote) | Checks the policy and the daily spend limit, signs, sends to Hyperliquid, and returns the fill, the fee burned and slippage against arrival mid. |
policy() | Reads your ExecutionPolicy from Elysium. Cached; refreshed on demand. |
report(result) | Sends an execution report to the engine. Off unless you set reportExecutions: true. |
Local and remote mode
Local mode subscribes to Hyperliquid market data from your process and runs the fee model in it. A quote costs microseconds and adds no network hop before the order. Use it for anything latency-sensitive: every 45 ms of added latency costs the same as 1 bp of priority.
Remote mode asks the hosted engine for each quote. It is simpler to run and fine for dashboards, research and slow flow.
import { Velocity } from "@velocity/sdk";
const client = await Velocity.connect({
network: "testnet",
mode: "remote", // quotes come from the hosted API
apiKey: process.env.VELOCITY_API_KEY,
agentKey: process.env.HL_AGENT_KEY,
account: "0xYourMainWallet",
});
const quote = await client.quote({
market: "ETH",
side: "sell",
notionalUsd: 10_000,
urgency: "normal",
maxPriorityBps: 2,
maxSlippageBps: 8,
});
const action = client.buildOrderAction(quote); // inspect before signing
const result = await client.executeIoc(quote);Python SDK
A thin client: quotes over HTTP, plus one helper that adds the priority grouping and the builder field to an order you build with the official hyperliquid-python-sdk. Signing stays in the official SDK.
from hyperliquid.exchange import Exchange
from velocity import Velocity, with_priority
client = Velocity(network="testnet", api_key=API_KEY)
quote = client.quote(market="BTC", side="buy", notional_usd=25_000,
urgency="high", max_priority_bps=4, max_slippage_bps=5)
# Adds grouping {"p": N} and the builder field to an order built
# with the official Hyperliquid Python SDK.
exchange = Exchange(agent_wallet, base_url, account_address=ACCOUNT)
order = with_priority(
{"coin": "BTC", "is_buy": True, "sz": quote.size, "limit_px": quote.limit_px,
"order_type": {"limit": {"tif": "Ioc"}}, "reduce_only": False},
quote,
)
print(exchange.bulk_orders([order.request], builder=order.builder, grouping=order.grouping))How the model works
The model is one pure function. Given an order and a snapshot of the market, it computes an expected cost at each of ten fee levels and picks the lowest. Ties go to the lower fee. All costs are in bps of notional. The current version is v1.0.0.
| Term | Formula | Meaning |
|---|---|---|
| Delay | K × (CAP − min(p, CAP)) | Extra milliseconds this order waits compared with one at the cap. K = 45 ms/bp, CAP = 8 bps. |
| Fee | p × fillProb(p) | You pay only on filled notional. |
| Delay cost | u × σ × √delay | σ is realized volatility (a blend of the last 1 s and 10 s). u is the urgency coefficient: 0.15 low, 0.5 normal, 1 high. |
| Delay cost, with your edge | edge × (1 − 0.5^(delay / halfLife)) | Used instead when you supply an edge and its half-life. |
| Miss cost | P(miss) × penalty | P(miss) is a normal tail: the chance the mid moves further than the room between your fill cost and your limit, within the delay. |
| Impact | walk the book | Average cost of filling this size against the visible book. The same at every fee level. |
| Builder | constant | The builder fee on the fill. |
Fee levels evaluated: 0, 0.25, 0.5, 1, 1.5, 2, 3, 4, 6, 8 bps, dropping any above your maximum or your policy’s.
What to expect from version 1
The delay term grows with the square root of the wait, so its saving per extra basis point is smallest at low fees and largest near the cap. In calm markets that saving never reaches 1 bp per bp, and the model says pay nothing. When volatility is high enough it says pay the cap. Values in between appear mainly when your maximum fee or your slippage limit binds. That is a property of this model, stated plainly, not a flaw hidden in it.
What it does not know
- It does not model other bidders. Paying 2 bps does not help if the orders you are racing pay 3. The Fee Explorer shows what others pay.
- The 45 ms/bp slope is Hyperliquid’s published figure for mainnet. Our own measurement is shown beside it in the Fee Explorer.
- The urgency coefficients and miss penalties are priors until the calibration job has enough executions to re-fit them. A re-fitted model is promoted only if it tests better out of sample.
Modeled, not measured
Fees and credits
Three different things are paid, to three different places:
| What | Paid to | How |
|---|---|---|
| Priority fee | Nobody: it is burned | By Hyperliquid, in HYPE from your staking balance, on filled notional. VELOCITY never touches it. |
| Builder fee | VELOCITY | By Hyperliquid, on fills of orders that carry our builder code. You approve a maximum once, from your main wallet, and can revoke it at any time. Default 0.5 bp. |
| API credits | VELOCITY treasury on Elysium | Bought with HYPE on Elysium. They pay for API requests above the free tier. Credits are a purchase, not a deposit: they are not transferable and not redeemable. |
Credits never pay Hyperliquid priority fees, and priority fees never pass through an Elysium contract. The SDK’s local mode needs no credits at all.
Security model
- No custody. The server never holds, receives or signs with a trading key. There is no endpoint that places an order for you.
- Agent keys cannot withdraw. Orders are signed by a Hyperliquid agent (API) wallet, which Hyperliquid itself restricts to trading. In the app the key is generated in your browser, stored in this browser’s local storage, and can be revoked from the Execute page or from Hyperliquid at any time.
- Approvals come from your main wallet. Approving the agent and approving the builder fee are typed-data signatures you see in your wallet. Neither can move funds.
- Policies are enforced client-side. Your
ExecutionPolicylives on Elysium, and the app and SDK refuse to sign an order that breaks it. Hyperliquid does not read it. An order sent some other way is not bound by it. - Contracts hold no trading capital. The Elysium contracts store policies, sell credits and record attestation roots. Credit payments forward to the treasury at purchase.
- Attestations prove retention, not truth. A batch root shows the engine held a record at posting time and has not changed it. The Hyperliquid order id and transaction hash in each record are what tie it to a real fill.
- Hard cap. Hyperliquid accepts priority rates up to 100%. The model, the action builder and the SDK each refuse anything above 8 bps.