Algo order stream
Stream your algo orders, one frame each time one is created or updated.
On this page
Write a small program that subscribes to `algo_order.algo_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/algo_order.md (~64 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 algo order: a parent order that the exchange works for you by placing and managing sub-orders, until it is filled, cancelled or expires. It does not rest on the book itself.
Algo trading must be enabled for the sub-account first (algo_trading_enabled in the sub-account summary). You don't sign an algo order; the exchange signs and places its sub-orders. Follow the algo order on the v1.algo.order stream. Its sub-orders can also show up on the v1.order and v1.state streams, in open orders and in order history, marked by metadata.algo_order_id.
type picks the strategy. Only CHASE is supported.
CHASE: a post-only limit order that follows the market. It is placed at the best bid (buy) or best ask (sell) and re-priced from time to time to keep up, until it is filled, cancelled or expires. Being post-only, it only ever adds liquidity and never trades as a taker. Its settings are in metadata.chase.
- With a
trigger, it waits until the trigger price is crossed; without one, it starts at once. - A partial fill doesn't stop it: the rest keeps being re-priced.
Its status is PENDING while it waits for its trigger, OPEN while it chases (also while held at its maximum distance), and FILLED, CANCELLED or REJECTED once it ends.
| SDK | client. |
|---|---|
| Channel | v1.algo.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_algo_orders, algo_order_history) for what you missed. |
| Contract id | algo_order. (StreamAlgoOrderV1) |
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 WSAlgoOrderFeedDataV1.
- The stream this frame belongs to, e.g.
v1.algo.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 algo order object being created or updated
10 fields of
AlgoOrder- Set by the server. The exchange's 128-bit id for the algo order.
- The sub-account initiating the algo order
- The type of the algo order
1 value
CHASE(details). - If True, every sub-order must be a maker order. Chase orders are always post-only
- If True, every sub-order must reduce the position size, or be cancelled
- The single leg traded by this algo order
3 fields of
AlgoOrderLeg- The instrument to trade
- The total number of assets to trade across all sub-orders. Decimal string, e.g. "0.01"; up to the instrument's base_decimals.
- Specifies if the algo order is a buy or sell
- Algo order metadata, including the type-specific parameters
6 fields of
AlgoOrderMetadata- Your own id for the algo order, unique among the sub-account's open algo orders. You can cancel the algo order by it.
- Set by the server. Time at which the algo order was received by Grvt in unix nanoseconds
- Trigger fields. If set, the algo order stays pending until the trigger price is crossed
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 algo order
4 values
- Time at which the algo order expires, expressed in unix nanoseconds. Defaults to and must be capped at 90 days
- Chase order parameters. Set only when the algo order type is CHASE
3 fields of
ChaseAlgoOrderMetadata- How the chase price is determined at each re-price tick
1 value
BEST_BID_ASK(details). - The maximum distance the chase price can move away from the reference price, as an absolute price distance in quote currency units. Decimal string, e.g. "65000.5"; up to 9 decimals. Always absolute: when the user picks a percentage, the client converts it and sends the result here.
- The max distance as a percentage in basis points (1 bp = 0.01%, 100% = 10000), as the user entered it.
0if the user entered an absolute distance. Informational only, for display and history.maxDistanceis what is enforced.
- Set by the server. The current state of the algo order
8 fields of
AlgoOrderState- The status of the algo order
5 values
- The reason for rejection or cancellation
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 total number of assets traded across all sub-orders
- The average fill price across all sub-orders
- Time at which the algo order was triggered in unix nanoseconds, 0 if not triggered yet
- Time at which the algo order was updated by Grvt in unix nanoseconds
- Chase order state. Set only when the algo order type is CHASE
1 field of
ChaseOrderState- The number of successful re-prices of this algo order's sub-orders
- The latest sub-order placed for this algo order, 0 until the first sub-order is placed
- The main account ID of the builder
- Builder fee charged for every sub-order, expressed as a percentage (e.g., 0.001 means 0.001%).
- 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
Plus 5 errors any call can return
1000Unauthorized401- You need to authenticate prior to using this functionality
1001Forbidden403- You are not authorized to access this functionality
1002InternalServer500- Internal Server Error
1008IPNotWhitelisted401- Your IP has not been whitelisted for access
1015ServiceUnavailable503retryable- Upstream data service is temporarily unavailable, please try again
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.algo_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.algo.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.algo.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.algo.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.