WebSocket /route/subscribe
This page is also Markdown, for agents: /dex-aggregator/reference/subscribe.md, and /llms.txt lists every page.
wss://router.intear.tech/route/subscribeA WebSocket that sends quotes for a request and keeps sending new ones as pools change, and answers with the outcome of a quote’s transactions. See Live quotes and Swapping for walkthroughs.
Connection
Section titled “Connection”All messages are JSON in text frames. Non-text frames from the client are ignored. Add ?key=<api key> to the URL to lift the rate limit.
The server never sends a WebSocket close frame, so clients see every close, including one they start, as abnormal (code 1006). Don’t use the close code to tell why a connection ended.
Client messages
Section titled “Client messages”A route request:
{ "id": 1, "query": "token_in=near&token_out=nep141:usdt.tether-token.near&amount_in=1000000000000000000000000&slippage_type=Fixed&slippage=0.01&trader_account_id=alice.near", "fees_in_next_steps": true }An outcome request:
{ "id": 2, "outcome": { "quote_id": 4611686, "tx_hashes": ["9FtHUFBQsZ2MG77K3x3MJ9wjX3UT8zE1TczCrhZEcG8U"] } }| Field | Type | Description |
|---|---|---|
id |
unsigned integer | Your ID for this message, sent back with each update of it |
query |
string, optional | Same query string as GET /route |
fees_in_next_steps |
boolean, optional | false by default. With true, the quotes leave out their fee transactions, and each has a quote_id to ask for the outcome of its transactions with. Needs trader_account_id in query |
outcome |
object, optional | Asks for the outcome of a quote’s transactions |
A message with outcome is an outcome request, and the route request goes on. Any other message replaces the route request: a new query starts a new one, and a message without query stops it. A message that isn’t valid JSON of this shape, including one whose id is negative, fractional, a string or missing, makes the server drop the connection.
Outcomes
Section titled “Outcomes”| Field | Type | Description |
|---|---|---|
quote_id |
integer | The quote_id of a quote of a route request with fees_in_next_steps, on this connection or any other |
tx_hashes |
array of strings | Hashes of the quote’s transactions that the trader executed, 1 to 20 of them, each once, all signed by its trader_account_id |
wait_until |
string, optional | When to answer: executed, the default, or swap, as for /route/outcome |
The server answers once the transactions executed, like GET /route/outcome does, with the quote’s token_in, token_out, trader_account_id and fee_amount. Once the swap went through, the outcome’s next_steps also pay the quote’s fee transactions, then its quote improvement fee, if Intear DEX didn’t take it in the swap. Closing the connection cancels the outcome requests that haven’t been answered. Asking again for the same quote, like after an answer at the swap, works.
Server messages
Section titled “Server messages”Quotes for a route request:
{ "id": 1, "routes": [ ... ] }routes is an array of quote objects, best first, same as GET /route, with a quote_id each with fees_in_next_steps. The first update is sent after the first round of routing, with an empty routes array if no DEX found a route. After that, one is sent each time pools update and the quotes change.
The outcome of a quote’s transactions:
{ "id": 2, "outcome": { "charge_fee": true, "amount_in": "1000000000000000000000000", "amount_out": "4880007", ... } }outcome is the /route/outcome response, with quote_improvement_fee when its next_steps pay one.
An error:
{ "id": 1, "error": "Slippage must be between 0.00 and 1.00", "status": 400 }Sent instead of quotes or an outcome. The connection stays open. status is the HTTP status of the error, which tells whether asking again can help: a 4xx other than 429 means the request is wrong, 429 is the rate limit, and a 5xx is a failure of the router or of reading the chain.
Validation errors of a query have the same text and status as for GET /route, and the errors of an outcome the same as for /route/outcome. Errors in parsing the query string are 400, without the Failed to deserialize query string: prefix and the parameter name, like missing field `token_in` or Empty dex id. Other errors:
| Status | Message | Cause |
|---|---|---|
400 |
fees_in_next_steps needs trader_account_id |
A route request with fees_in_next_steps has no trader_account_id |
500 |
Failed to store the quotes: <reason> |
The quotes of a request with fees_in_next_steps couldn’t be stored. The route request stops |
404 |
Quote <id> doesn't exist |
No quote has the quote_id of an outcome request |
500 |
Failed to read quote <id>: <reason>, Quote <id> is invalid: <reason> |
The quote of an outcome request couldn’t be read |
500 |
Failed to record the outcome of quote <id>: <reason> |
The outcome was found, but couldn’t be stored with the quote |
Timing
Section titled “Timing”After each round of routing, the server waits until about 10× the routing time has passed since the round started, at most 3 seconds. Then it routes again as soon as any pool has changed since the round started. In practice this means an update every block or every few blocks while the pools are active.