WebSocket API
Connect to the KITE 2.0 WebSocket for real-time news streaming. News items are pushed to your client the moment they appear, with optional server-side filtering so you only receive what matters.
Connection URL
wss://kite-api.gtdigital.dev/api/ws?key=YOUR_API_KEYAuthentication
WebSocket connections require a valid API key passed as a key query parameter.
To get a key, create an account and generate one from your Account → API Keys page.
const ws = new WebSocket('wss://kite-api.gtdigital.dev/api/ws?key=kite_your_key_here');Connections without a valid key are rejected with a 401 HTTP response before the WebSocket upgrade completes.
Connection Lifecycle
Open a WebSocket connection to the endpoint.
The server sends a connected message.
Send a subscribe message with your filter preferences. Without this, you receive all items.
The server pushes news messages as items are created, updated, or deleted.
Send periodic ping messages to maintain the connection.
Client → Server Messages
Server → Client Messages
Filter Options
Filters use AND logic between groups and OR logic within each group. For example, setting both sources and keywords means an item must match at least one source AND at least one keyword.
| Parameter | Type | Default | Description |
|---|---|---|---|
sources | string[] | -- | Filter by source names (e.g. ["BBC News", "CNBC"]) |
categories | string[] | -- | Filter by category IDs: financial_news, central_banks, regulators |
keywords | string[] | -- | Match against title, description, tickers, and tags |
tickers | string[] | -- | Filter by ticker symbols (e.g. ["AAPL", "BTC"]) |
companies | string[] | -- | Match company names against title and description (e.g. ["Apple", "Tesla"]) |
Code Examples
JavaScript / Node.js
const ws = new WebSocket('wss://kite-api.gtdigital.dev/api/ws?key=kite_your_key_here');
ws.onopen = () => {
console.log('Connected to KITE 2.0');
// Subscribe to central bank news about interest rates
ws.send(JSON.stringify({
type: 'subscribe',
filters: {
categories: ['central_banks'],
keywords: ['interest rates', 'inflation']
}
}));
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
switch (data.type) {
case 'news':
console.log(`[${data.action}] ${data.item.title}`);
console.log(` Source: ${data.item.source}`);
console.log(` Tickers: ${data.item.tickers.join(', ')}`);
break;
case 'connected':
console.log(data.message);
break;
case 'subscribed':
console.log('Filters applied:', data.filters);
break;
case 'pong':
break;
}
};
ws.onerror = (err) => console.error('WebSocket error:', err);
ws.onclose = () => console.log('Disconnected');
// Keep-alive every 30 seconds
setInterval(() => {
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({ type: 'ping' }));
}
}, 30000);Python
import asyncio
import websockets
import json
async def listen():
async with websockets.connect('wss://kite-api.gtdigital.dev/api/ws?key=kite_your_key_here') as ws:
# Subscribe to crypto news
await ws.send(json.dumps({
'type': 'subscribe',
'filters': {
'categories': ['financial_news'],
'keywords': ['Bitcoin', 'Ethereum', 'crypto'],
'sources': ['CoinDesk', 'CoinTelegraph', 'Decrypt']
}
}))
async for message in ws:
data = json.loads(message)
if data['type'] == 'news':
item = data['item']
print(f"[{data['action']}] {item['title']}")
print(f" Source: {item['source']}")
if item.get('tickers'):
print(f" Tickers: {', '.join(item['tickers'])}")
print()
asyncio.run(listen())curl (WebSocket)
# Using websocat (install: cargo install websocat)
echo '{"type":"subscribe","filters":{"categories":["central_banks"]}}' | \
websocat 'wss://kite-api.gtdigital.dev/api/ws?key=kite_your_key_here'
# Using wscat (install: npm install -g wscat)
wscat -c 'wss://kite-api.gtdigital.dev/api/ws?key=kite_your_key_here'
# Then type: {"type":"subscribe","filters":{"keywords":["Bitcoin"]}}Updating Filters
You can change your filters at any time by sending a new subscribe message.
The new filters completely replace the previous ones.
// Start with broad filters
ws.send(JSON.stringify({
type: 'subscribe',
filters: { categories: ['financial_news'] }
}));
// Later, narrow down to specific sources
ws.send(JSON.stringify({
type: 'subscribe',
filters: {
sources: ['Bloomberg Markets', 'CNBC'],
tickers: ['AAPL', 'GOOGL', 'MSFT']
}
}));
// Clear all filters (receive everything)
ws.send(JSON.stringify({ type: 'unsubscribe' }));Reconnection
The WebSocket server does not implement automatic reconnection. If the connection drops, your client should implement exponential backoff reconnection logic:
function connect(retryMs = 1000) {
const ws = new WebSocket('wss://kite-api.gtdigital.dev/api/ws?key=kite_your_key_here');
ws.onopen = () => {
console.log('Connected');
retryMs = 1000; // Reset backoff on success
// Re-send your subscribe message here
};
ws.onclose = () => {
console.log(`Reconnecting in ${retryMs}ms...`);
setTimeout(() => connect(Math.min(retryMs * 2, 30000)), retryMs);
};
return ws;
}
connect();