Aller au contenu

Streaming WebSocket

Abonnez-vous à vos symboles et recevez les mises à jour poussées en temps réel par le serveur.

Connexion

ItemDescription
Endpointwss://api.itick.dev/{market}, where market is one of stock, forex, crypto, indices, future, fund
AuthenticationThe token request header, or the ?token= query parameter (browsers cannot set headers)
ConnectionsConcurrent connections per API key per market are limited by your plan
SubscriptionsSymbols per connection are limited by your plan
HeartbeatSend a ping at least every 30 seconds
Symbol formatCODE$REGION, such as AAPL$US, 700$HK, BTCUSDT$BA

After connecting you first receive Connected Successfully and authenticated messages. The free plan does not include WebSocket by default, so the handshake returns 403.

Format des messages

Subscribe, heartbeat and pushes
// Subscribe / unsubscribe. types: tick, quote, depth, kline@1
{"ac":"subscribe","params":"AAPL$US,700$HK","types":"quote,tick"}
{"ac":"unsubscribe","params":"AAPL$US","types":"quote"}

// Heartbeat
{"ac":"ping","params":"1731688569840"}

// Pushed message
{"code":1,"data":{"s":"BTCUSDT","r":"BA","ld":83988.54,"v":0.00019,"type":"tick"}}

types can be tick, quote, depth or kline@1; whether kline@1 is available depends on your plan. Going over the subscription limit returns exceeding the maximum subscription limit.

Exemple JavaScript

JavaScript
const ws = new WebSocket("wss://api.itick.dev/crypto?token=YOUR_API_KEY");

ws.onopen = () => {
  ws.send(JSON.stringify({ ac: "subscribe", params: "BTCUSDT$BA", types: "quote,tick" }));
  // Send a heartbeat at least every 30 seconds
  setInterval(() => ws.send(JSON.stringify({ ac: "ping", params: String(Date.now()) })), 25000);
};

ws.onmessage = (event) => console.log(event.data);

Bon à savoir

  • When a token is disabled, reset or expires, its open connections are closed by the server. Reconnect and subscribe again after a disconnect.
  • The WebSocket handshake counts toward the per-minute request limit.
  • Several connections can subscribe to the same symbol without affecting each other.