Vantafin's WebSocket API streams real-time market events - live quotes, news, SEC filings, and trading halts - so your app reacts the moment something happens instead of polling. WebSocket streaming is an Ultimate-plan feature. This guide covers how to connect and subscribe; the channel reference is in the WebSocket docs.
Connect
Open a connection to the stocks stream and authenticate with your API key:
wss://socket.vantafin.com/v1/stocks?apiKey=vf-live-YOUR_KEY
After connecting, you subscribe to the channels and symbols you care about (see the docs for the exact message format).
Available streams
| Stream | Delivers |
|---|---|
| Live quotes | Second- and minute-level price updates |
| News | Breaking headlines |
| SEC filings | New filings as they post |
| Trading halts | Halt and resume events |
A minimal Python client
import os
import json
import websocket # pip install websocket-client
API_KEY = os.environ["VANTAFIN_API_KEY"]
URL = f"wss://socket.vantafin.com/v1/stocks?apiKey={API_KEY}"
def on_message(ws, message):
event = json.loads(message)
print(event)
def on_open(ws):
# Subscribe to the channels/symbols you want (see the docs for the schema).
ws.send(json.dumps({"action": "subscribe", "params": "..."}))
ws = websocket.WebSocketApp(URL, on_open=on_open, on_message=on_message)
ws.run_forever()
Adapt the subscribe payload to the schema documented in the WebSocket reference.
Design a resilient stream
Real-time clients should:
- Reconnect automatically with backoff if the connection drops.
- Resubscribe to your channels after reconnecting.
- Buffer and process messages off the socket thread so you never block reads.
When to use WebSocket vs REST vs alerts
| Need | Use |
|---|---|
| Build your own real-time app | WebSocket |
| Pull data on demand | REST API |
| Get notified without code | Alerts |