Order stream
Stream your orders in full, one frame each time one is created or changes.
On this page
Write a small program that subscribes to `order.order` on Grvt {environment} {using}, checks sequence numbers and re-subscribes on a gap.
Target environment: {environment} (chain ID {chainId}). Recorded signing cases keep their original environment.
{executionGuidance}
Read this first: {origin}/bundle/reference/streams/order.md (~68 KB, plain Markdown: this page plus the AGENTS.md rules, Authentication and sessions, WebSocket, Python SDK, Environments).
Fetch other pages from the index at {origin}/llms.txt only as you need them. {origin}/downloads/contract.json is a machine-readable contract for tools, not for reading.
Rules: follow AGENTS.md; do not send requests without the user asking you to; read credentials from environment variables; never retry writes automatically; show me the code and how to run it. URLs and generated code samples on this page: Testnet (chain ID 326). Other code on this page doesn't change: it stays on testnet until you switch it in your code. Tutorials, signing cases and live tools always use testnet.
Payload: An order: what to trade (its legs), how long it stays open, and the signature that authorises it. The same object is used for order book, RFQ and liquidation orders.
Every field except order_id, metadata and state is part of the signed message and enforced on chain, so Grvt cannot change it.
| SDK | client. |
|---|---|
| Channel | v1.order on wss:/, or /ws/lite for lite names (the SDKs' default) |
| Selector | <sub_account_id>[-<instrument>] |
| Auth | Session required on the WebSocket upgrade (Authentication) |
| Kind | event. Each frame is one event (an update to one object). |
| Sequenced | Yes: the first update's prev_sequence_number is at or below the subscribe reply's latest_sequence_number, then each one equals the last sequence_number (rules). On a gap, re-subscribe, then fetch current state over HTTP (open_orders, order_history) for what you missed. |
| Contract id | order.order (StreamOrderV1) |
Selector
Grammar <sub_account_id>[-<instrument>], e.g. <sub_account_id>-BTC_USDT_Perp. Parts:
- The sub-account ID to filter by
- The instrument filter to apply.
Frame
Type WSOrderFeedDataV1.
- The stream this frame belongs to, e.g.
v1.order. - The selector this frame is for, as you subscribed with it.
- This frame's number, an unsigned 64-bit integer sent as a decimal string: compare it as an integer.
"0"on the snapshot sent right after subscribing.- With
use_global_sequence_number: true(recommended), the number is unique across the exchange. One exchange event can produce several frames, so the number isevent number × 10^5 + a counterthat tells them apart. - With
false, it counts up by one per frame of this stream and starts again when the server you are connected to restarts.
- With
- The order object being created or updated
12 fields of
Order- Set by the server. The exchange's 128-bit id for the order. The reply to
create_orderorbulk_orderscomes before the id is assigned, so it is zero there; the order stream andget_ordercarry it. Every replace creates a new order with a neworder_id. - The sub-account placing the order.
- True for a market order. A market order has no limit price, never rests on the book and fills at the prices of the resting orders it meets.
On STABLE_PERP a slippage bound is mandatory:
limit_pricemust carry the signed bound (reference price ± the chosen slippage), or the order is rejected (STABLE_PERP_REQUIRES_PRICE_BOUND). There,is_market= false with a limit price behaves the same; the flag only records intent. - How long the order stays open and whether it may fill partly. The order book takes
GOOD_TILL_TIME,IMMEDIATE_OR_CANCEL,FILL_OR_KILLandRETAIL_PRICE_IMPROVEMENT. An RFQ maker quote usesGOOD_TILL_TIMEorALL_OR_NONE; an RFQ taker usesIMMEDIATE_OR_CANCELorFILL_OR_KILL.5 values
- If true, the order must rest on the book as a maker order: if it would match at once, it is rejected (
FAIL_POST_ONLY). A market,IMMEDIATE_OR_CANCELorFILL_OR_KILLorder cannot be post-only.If false, the order may take or make liquidity. Such orders can be held for a short speed bump before matching, so they meet up-to-date quotes; the exchange sets the delay, and it can differ per instrument.
- If true, the order may only reduce your position; the part that would increase it is cancelled.
- What to trade. Send exactly one leg: the order book rejects orders with more than one (
MULTI_LEGGED_ORDER).4 fields of
OrderLeg- The instrument to trade, e.g.
BTC_USDT_Perp. - How much to trade, in the base asset. Decimal string, e.g. "0.01"; up to the instrument's base_decimals and a multiple of its minimum size. Scaled to an integer only inside the signature.
- The worst price you accept, in the quote currency per unit. Decimal string, e.g. "65000.5"; up to 9 decimals and a multiple of the instrument's tick size. Scaled to an integer only inside the signature.
Leave it out (or
"0") on a market order. Exception: a STABLE_PERP market order must carry the signed slippage bound (reference price ± the chosen slippage) here. - True to buy, false to sell.
- The EIP-712 signature that authorises this order. The SDKs fill it in; the Signing guide shows how to build it yourself.
7 fields of
Signature- The address of the wallet that signed (
0x+ 40 hex characters). That wallet must be allowed to act for the account; for an order, to trade for the sub-account. - The signature's
r, as0x+ 64 hex characters. Without the0xthe signature fails to verify. - The signature's
s, as0x+ 64 hex characters. Without the0xthe signature fails to verify. - The signature's
v, 27 or 28. - When the signature stops being valid, in unix nanoseconds, measured on the exchange's clock. At most 30 days ahead (take-profit and stop-loss orders may be accepted up to 180 days ahead); one already past fails with
2001. On an order it is also the order's lifetime: an order still open then is cancelled with reasonEXPIRED. The SDKs use now + 24 hours. - A number you choose, 0 to 4,294,967,295 (uint32), so that two otherwise identical requests have different signatures. Use a new random one for each request you sign.
A transfer whose signed fields (nonce and expiration included) exactly repeat an earlier one is rejected, not ignored: it fails with
4007.Orders are different. An exact resend of a signed order can be accepted and rest on the book, but the exchange counts fills per signed order, so all copies together never fill more than the signed size, and a resent
IMMEDIATE_OR_CANCELorder whose first copy already filled is rejected. An order signed again (new nonce or expiration) is a new order and can fill in full again. - The chain id in the signed EIP-712 domain, as a string. Testnet 326, production 325;
"0"means the environment's chain id.
- Unsigned data the exchange uses but the chain never sees, such as your
client_order_id.9 fields of
OrderMetadata- Your own id for the order, to find or cancel it later. Any non-zero uint64 (
0fails with2011) that none of the sub-account's open orders uses, take-profit and stop-loss orders waiting for their price included: a duplicate fails with2012(or is rejected withOVERLAPPING_CLIENT_ORDER_ID), and repeating the sub-account's last client order id fails with2013. After an order closes, its id is accepted again, so use a new id for each order.The Grvt web app picks ids below 2^63, so ids from 2^63 up never clash with orders placed there. That is a convention, not a rule the exchange checks. The SDKs set one for you when you leave it out. Not signed and not sent on chain.
- Set by the server. When the exchange received the order, in unix nanoseconds.
- Trigger fields are used to support any type of trigger order such as TP/SL
2 fields of
TriggerOrderMetadata- Type of the trigger order. eg: Take Profit, Stop Loss, etc
3 values
- Contains metadata for Take Profit (TP) and Stop Loss (SL) trigger orders. Fields: see TPSLOrderMetadata.
- Specifies the broker who brokered the order
4 values
- Marks an ECN order, eligible for market maker last look. Only on STABLE_PERP instruments, for qualified market makers.
- Maximum slippage from the mark price for an
IMMEDIATE_OR_CANCELlimit order, in basis points (800 = 8%). Only valid on IOC limit orders; 0 means no slippage protection. - Binds this order to an RFQ (see ApiCreateRfqRequest and the
v1.rfq/v1.quotestreams). Optional.As a taker acceptance: unlocks that RFQ's private quote pool, so the order matches across the private pool merged with the public book (firm resting liquidity + public quotes). The acceptance must be a single-leg order with time_in_force = IOC or FOK. Setting
rfq_idon a non-ECN GTT order is rejected. If the referenced RFQ has expired, been cancelled, or is unknown, the order is rejected.As a maker quote (is_ecn = true): identifies which RFQ the quote is responding to.
Omit
rfq_idto match the public book only — private RFQ liquidity requires an RFQ. - Maker quotes only. true = a private quote delivered to a single RFQ's taker (appears only on that taker's
v1.quotebook); false = a public quote resting on the order book, visible to all. When true,rfq_idis required. - The algo order that placed this order as a sub-order; zero for an ordinary order.
- Set by the server. The order's status, filled size and average fill price; not signed.
6 fields of
OrderState- The order's status.
FILLED,REJECTEDandCANCELLEDare final.5 values
- Why the order was rejected or cancelled.
UNSPECIFIEDwhile it is not.76 values
UNSPECIFIED,CLIENT_CANCEL,CLIENT_BULK_CANCEL,CLIENT_SESSION_END,MARKET_CANCEL,IOC_CANCEL,AON_CANCEL,FOK_CANCEL,EXPIRED,FAIL_POST_ONLY,FAIL_REDUCE_ONLY,MM_PROTECTION,SELF_TRADE_PROTECTION,SELF_MATCHED_SUBACCOUNT,OVERLAPPING_CLIENT_ORDER_ID,BELOW_MARGIN,LIQUIDATION,INSTRUMENT_INVALID,INSTRUMENT_DEACTIVATED,SYSTEM_FAILOVER,UNAUTHORISED,SESSION_KEY_EXPIRED,SUB_ACCOUNT_NOT_FOUND,NO_TRADE_PERMISSION,UNSUPPORTED_TIME_IN_FORCE,MULTI_LEGGED_ORDER,EXCEED_MAX_POSITION_SIZE,EXCEED_MAX_SIGNATURE_EXPIRATION,MARKET_ORDER_WITH_LIMIT_PRICE,CLIENT_CANCEL_ON_DISCONNECT_TRIGGERED,OCO_COUNTER_PART_TRIGGERED,REDUCE_ONLY_LIMIT,CLIENT_REPLACE,DERISK_MUST_BE_IOC,DERISK_MUST_BE_REDUCE_ONLY,DERISK_NOT_SUPPORTED,INVALID_ORDER_TYPE,CURRENCY_NOT_DEFINED,INVALID_CHAIN_ID,BUILDER_ORDER_FEE_EXCEED,BUILDER_ORDER_FEE_NEGATIVE,BUILDER_ORDER_BUILDER_NOT_AUTHORIZED,BUILDER_ORDER_BUILDER_NOT_EXIST,TRADE_PRICE_WORSE_THAN_BANKRUPTCY_PRICE,TOO_MANY_MAKER_ORDERS,REDUCE_ONLY_NOT_SUPPORTED_FOR_SPOT_ORDER,TPSL_NOT_SUPPORTED_FOR_SPOT_ORDER,SPOT_ORDER_NOT_SUPPORTED,INSUFFICIENT_BALANCE,SPOT_TRADING_BLOCKED_DURING_SOCIALIZED_LOSS,BELOW_MARGIN_WITH_PENALTY_DEVIATION,CORPORATE_ACTION,NOT_QUALIFIED_MAKER,PRIVATE_QUOTE_REQUIRES_RFQ,STABLE_PERP_REQUIRES_PRICE_BOUND,UNSUPPORTED_TRIGGER_BY,RFQ_NOT_FOUND,RESTING_ORDER_WOULD_CROSS,SESSION_CLOSED,RFQ_TERMINATED,STABLE_PERP_REQUIRES_MULTI_ASSET_MODE,BORROW_LIMIT_EXCEEDED_AFTER_TRADE,UNDEPLOYED_LOAN_AUTO_EXCHANGE,LIQUIDATION_AUTO_EXCHANGE,USDC_COLLATERAL_DISABLED,SFP_POST_ONLY_NOT_ALLOWED,VAULT_NON_QUOTE_INVESTMENT_CURRENCY,RFQ_ID_REQUIRES_STABLE_PERP,RFQ_PRIVATE_POOL_NOT_SUPPORTED,RFQ_REQUIRES_IOC,RFQ_MISMATCH,RFQ_ALREADY_BOUND,RFQ_MAKER_MUST_BE_ECN,FOK_NOT_SUPPORTED,MARKET_ORDER_NOT_SUPPORTED,STABLE_PERP_ORDER_NOT_SUPPORTED(details). - The size still open to fill, per leg (same order as
legs), in the base asset. - The size filled so far, per leg (same order as
legs), in the base asset. - When the order last changed, in unix nanoseconds.
- The average price of the fills so far, per leg (same order as
legs); 0 before the first fill.
- The main account id of a builder (a third party that routes your order and charges a fee on it). Leave it out unless you trade through a builder: setting it switches the signature to
OrderWithBuilderFee. - The builder's fee for this order, as a percentage:
"0.001"means 0.001%. Only withbuilder.
- The
sequence_numberof the frame before this one on this selector. If it doesn't match the last frame you accepted, you missed frames.
Errors
Subscribe errors arrive as a JSON-RPC error object {code, message} (lite {c, m}). Codes this stream can return (all error codes):
1101InvalidFeedFormat400- Feed Format must be in the format of <primary>@<secondary>
1102PrimarySelectorParts400- Wrong number of primary selectors
1103SecondarySelectorParts400- Wrong number of secondary selectors
3000InvalidInstrument400- Instrument is invalid
3020InvalidSubAccountID400- Sub account ID must be an uint64 integer
Example
Example code
import asyncio
import os
from grvt import AsyncGrvt
async def main():
async with AsyncGrvt(env=os.environ.get("GRVT_ENV", "testnet"), api_key=os.environ["GRVT_API_KEY"]) as client:
async with client.order_stream(instrument="BTC_USDT_Perp", sub_account_id=os.environ["GRVT_SUB_ACCOUNT_ID"]) as sub:
async for frame in sub:
print(frame.sequence_number, frame.feed)
asyncio.run(main())
Raw WebSocket: connect to wss://trades.testnet.grvt.io/ws/full (/ws/lite for lite names) with the Cookie: gravity=... and X-Grvt-Account-Id headers and send:
With full field names:
{
"jsonrpc": "2.0",
"method": "subscribe",
"params": {
"stream": "v1.order",
"selectors": ["$GRVT_SUB_ACCOUNT_ID-BTC_USDT_Perp"],
"use_global_sequence_number": true
},
"id": 1
}With lite field names:
{
"j": "2.0",
"m": "subscribe",
"p": {
"s": "v1.order",
"s1": ["$GRVT_SUB_ACCOUNT_ID-BTC_USDT_Perp"],
"ug": true
},
"i": 1
}The reply's result is a WSSubscribeResult (subs, num_snapshots, latest_sequence_number); then frames arrive in the shape under Frame above, with no JSON-RPC envelope.
Build subscription
v1.order is on the trading gateway and needs a logged-in session (Cookie: gravity=… and X-Grvt-Account-Id on the WebSocket upgrade). The docs only build the subscription and never open the socket. Log in with the SDK or follow Authentication, then subscribe with the selector <sub_account_id>-BTC_USDT_Perp.