WebSocket reference
Finazon offers a dynamic financial data platform powered by WebSocket technology. Developers gain instant access to real-time data streams for stocks, ETFs, cryptocurrencies, and more, enabling seamless integration and immersive user experiences. With WebSocket, bidirectional communication channels facilitate continuous updates and responsive applications, amplifying how financial data is utilized.
Usage
pip install websocket-client rel
python finazon_ws_example.py
import json
import rel
import websocket
dataset = 'sip_non_pro'
tickers = ['AAPL']
api_key = 'your_api_key'
def on_message(wsapp, message):
print(f'Message: {message}')
def on_error(wsapp, error):
print(f'Error: {error}')
def on_close(wsapp, close_status_code, close_msg):
print('Connection is closed')
def on_open(wsapp):
print('Connection is opened')
subscribe(wsapp, dataset, tickers)
def subscribe(wsapp, dataset, tickers):
sub_request = {
'event': 'subscribe',
'dataset': dataset,
'tickers': tickers,
'channel': 'bars',
'frequency': '1s',
'aggregation': '1m'
}
wsapp.send(json.dumps(sub_request))
if __name__ == '__main__':
# Open ws connection
ws = websocket.WebSocketApp(f'wss://ws.finazon.io/v1?apikey={api_key}',
on_open=on_open,
on_message=on_message,
on_error=on_error)
# Start event loop
ws.run_forever(
# Set dispatcher to automatic reconnection, 5 second reconnect delay if connection closed unexpectedly
dispatcher=rel, reconnect=5,
# Sending ping with specified interval to prevent disconnecting
ping_interval=30, ping_timeout=10,
)
# Handle Keyboard Interrupt event
rel.signal(2, rel.abort)
rel.dispatch()
Subscribe
Subscribe to 1min candle updates within a minute (time_series). Make similar changes to other endpoints:
dataset
string
required
Filter by Finazon's dataset code
Example: sip_non_pro
tickers
array
required
Subscribe to an array of ticker symbols. Possible options: see sip_non_pro ticker list
Example: AAPL
, TSLA
frequency
string
required
Accepts 1s
, 10s
, and 1m
options. Data will stream at 1-second, 10-second, or 1-minute intervals accordingly.
aggregation
string
required
Accepts 1m
option. Data will stream 1-minute bars.
channel
string
required
Accepts bars
option. Data will stream as bars (candles).
request_id
string | number
Request id returned with the response.
Subscribe
event
stringsubscribe
status
stringsuccess
, error
code
stringSUCCESS_SUBSCRIPTION
data
array of stringAAPL, TSLA
request_id
string | numberCandle update
d
stringsip_non_pro
p
stringsip
ch
stringbars
f
string1s
aggr
string1m
s
stringAAPL
t
number1699540020
o
float220.06
h
float220.13
l
float219.92
c
float219.96
v
number4572
{
"event": "subscribe",
"dataset": "sip_non_pro",
"tickers": [ "AAPL", "TSLA" ],
"channel": "bars",
"frequency": "1s",
"aggregation": "1m",
"request_id": 106
}
{
"status": "success",
"code": "SUCCESS_SUBSCRIPTION",
"data": [ "AAPL", "TSLA" ],
"request_id": 106
}
Unsubscribe
To unsubscribe from a channel, you can use the following configuration:
dataset
string
required
Filter by Finazon's dataset code
Example: sip_non_pro
tickers
array
required
An array of ticker symbols to unsubscribe. Possible options: see sip_non_pro ticker list
Example: AAPL
, TSLA
frequency
string
required
Accepts 1s
, 10s
, and 1m
options. Data will stream at 1-second, 10-second, or 1-minute intervals accordingly.
aggregation
string
required
Accepts 1m
option. Data will stream 1-minute bars.
channel
string
required
Accepts bars
option. Data will stream as bars (candles).
request_id
string | number
Request id returned with the response.
event
stringunsubscribe
status
stringsuccess
, error
code
stringSUCCESS_UNSUBSCRIPTION
data
array of stringAAPL, TSLA
request_id
string | numberHeartbeat
To check if the connection is still alive, you can use the following configuration:
request_id
string | number
Request id returned with the response.
event
stringheartbeat
status
stringsuccess
request_id
string | numberReset
To reset all active subscriptions, you can use the following configuration. Server doesn't reply to this message.
request_id
string | number
Request id returned with the response.
event
stringreset
status
stringsuccess
request_id
string | number