Spreads and tickers are pushed over Socket.IO as soon as they change. You subscribe with the same filters as webhooks and REST (WebhookFilters) and get updates only for the spreads that match.
The stream is available when your plan includes it. Otherwise the connection is refused. The plan's limits (exchanges, data delay) are fixed when you connect: after a plan change, reconnect.
Connect
| Host | https://b2b.api.arbitragescanner.io |
| Socket.IO path | /api/screener-v3/socket.io/ |
| Transport | websocket only |
| Key | X-API-KEY: <your key> header of the connection request |
The key goes in a request header, which browsers cannot set on WebSockets. Connect from your server.
Node.js (socket.io-client 4)
socket.io-client 4)import { io } from "socket.io-client";
const socket = io("https://b2b.api.arbitragescanner.io", {
path: "/api/screener-v3/socket.io/",
transports: ["websocket"],
extraHeaders: { "X-API-KEY": process.env.ARB_API_KEY },
});
socket.on("connect", async () => {
const ack = await socket.timeout(10_000).emitWithAck("subscribe", {
strategies: ["perp-perp", "spot-perp"],
minSpreadPct: 0.5,
minEntryUsd: 100,
batch: true,
throttleMs: 1000,
});
if (!ack.ok) console.error("subscribe refused:", ack.error, ack.message);
});
// with batch: true every event comes inside "batch"
socket.on("batch", (items) => {
for (const { event, data } of items) handle(event, data);
});
socket.on("credits", (c) => console.log("credits left:", c.remaining));
socket.on("error", (e) => console.error("closed by the server:", e.error, e.message));
socket.on("connect_error", (err) => console.error("cannot connect:", err.message));
function handle(event, data) {
if (event === "spread") upsert(data.key, data);
else if (event === "spread.closed") remove(data.key);
else if (event === "ticker") onTicker(data);
}Python (python-socketio 5, asyncio)
python-socketio 5, asyncio)import asyncio, os
import socketio
sio = socketio.AsyncClient()
@sio.event
async def connect():
ack = await sio.call("subscribe", {
"strategies": ["perp-perp", "spot-perp"],
"minSpreadPct": 0.5,
"minEntryUsd": 100,
"batch": True,
"throttleMs": 1000,
}, timeout=10)
if not ack.get("ok"):
print("subscribe refused:", ack)
@sio.on("batch")
async def batch(items):
for item in items:
handle(item["event"], item["data"])
@sio.on("credits")
async def credits(c):
print("credits left:", c["remaining"])
@sio.on("error")
async def error(e):
print("closed by the server:", e)
async def main():
await sio.connect(
"https://b2b.api.arbitragescanner.io",
socketio_path="/api/screener-v3/socket.io",
transports=["websocket"],
headers={"X-API-KEY": os.environ["ARB_API_KEY"]},
)
await sio.wait()
asyncio.run(main())Use the asyncio client (AsyncClient). The threaded socketio.Client reads and writes one TLS connection from two threads and sometimes drops the connection right after subscribe.
Subscribe
Emit subscribe with an acknowledgement callback. A new subscribe replaces the previous one. unsubscribe stops everything and acks {"ok": true}.
| Field | |
|---|---|
| Filters | Any fields of WebhookFilters (see the API reference). Examples: strategies, assets, excludeAssets, exchanges, buyExchanges, sellExchanges, minSpreadPct, minNetSpreadPct, minEntryUsd, minProfitPct with profit: "entry", minFundingPct, networks, requireTransfer, minOpenSec. Empty lists match all. profit: "deal" is REST only. |
batch | true: events come packed in one batch event (up to 256 per packet) instead of one event each. Recommended. |
throttleMs | At most one update of a spread per that many ms: rounded up to whole seconds, up to 60 s. Your plan's data delay applies anyway. |
tickers | {assets: ["BTC", …], exchanges?: […], markets?: ["spot" | "perpetual"]}: also stream tickers of these assets. assets is required. |
Acknowledgement:
{
"ok": true,
"filters": { "strategies": ["perp-perp", "spot-perp"], "minSpreadPct": 0.5, "minEntryUsd": 100, "includeSuspect": false },
"batch": true,
"throttleMs": 1000,
"tickers": null
}throttleMsis the effective interval: the larger of yours and your plan's delay.- Tickers refused: if the ticker part is refused, the ack has
tickersErrorwith the reason, and the spreads still stream. - Bad filter:
{"ok": false, "error": "bad_filters", "message": "…"}. Nothing changes.
A wide filter (all strategies, minSpreadPct near 0) produces hundreds of updates a second. Filter on the server side rather than in your code.
Events
| Event | Data |
|---|---|
spread | A spread that matches your filters, every time it changes. The schema is StreamSpread in the API reference, the same object as a webhook's data. Key it by key. |
spread.closed | A spread you received has closed (open: false). Remove it. |
ticker | A ticker of the subscribed assets (the Ticker row of /v1/markets/tickers), at most once a second per instrument. |
credits | {"remaining": 399978, "cost": 10, "per": "minute"}: sent after each minute is charged. |
batch | [{"event": "spread", "data": {…}}, …] when you subscribed with batch: true. |
error | {"error": "<code>", "message": "…"}. The server disconnects right after. |
spread.closed comes only when the spread itself closes. A spread that stops matching your filters, for example because its spread fell below minSpreadPct, simply stops updating. If you keep a board, drop rows that have not updated for a while, or refresh it over REST.
Example spread (shortened):
{
"key": "ARIA/USDT|bitget:perpetual:ARIAUSDT>mexc:perpetual:ARIA_USDT",
"asset": "ARIA", "quote": "USDT", "strategy": "perp-perp",
"buy": { "exchange": "bitget", "market": "perpetual", "symbol": "ARIAUSDT", "bestPrice": 0.308, "avgPrice": 0.30837, "slippagePct": 0.12, "takerFee": 0.0006,
"funding": { "rate": 0.00005, "intervalHours": 4, "nextFundingTsMs": 1795536000000 }, "url": "https://www.bitget.com/futures/usdt/ARIAUSDT" },
"sell": { "exchange": "mexc", "market": "perpetual", "symbol": "ARIA_USDT", "bestPrice": 0.30925, "avgPrice": 0.30912, "slippagePct": 0.04, "takerFee": 0.0004 },
"spreadPct": 0.406, "netSpreadPct": 0.305,
"entryNotionalNet": 3620.28, "bestEntryCost": 3620.28, "bestEntryProfit": 5.15, "depthExhausted": true,
"lifetimes": [ { "thresholdPct": 0.3, "aboveForMs": 2233, "runs": 512, "avgMs": 1557, "medianMs": 526 } ],
"match": "contract", "open": true, "openForMs": 529041, "computedMs": 1795533744279
}Errors
| When | What you get |
|---|---|
| The plan has no stream | The connection is refused: connect_error. |
| Credits run out during the session | error {"error": "credits_exhausted"}, then disconnect. |
| The subscription ends or the account runs out of credits | error {"error": "account_stopped"}, then disconnect. |
| A bad filter | The subscribe ack is {"ok": false, "error": "bad_filters"}. The connection stays. |
After a disconnect with error, do not reconnect in a loop: fix the cause first. Network drops reconnect automatically: both clients above do it with backoff, and you subscribe again in connect.
Credits
- Connection: a connected minute costs 10 credits, charged at connect and then every minute.
- Tickers: a ticker subscription adds 10 credits a minute.
- No charge per message.
- Balance: the
creditsevent reports the balance after each charge. - Out of credits: when the balance cannot cover the next minute, the server sends
errorcredits_exhaustedand disconnects.
