Client libraries
Simplify your work with Finazon official client libraries. Always up-to-date. All functions mirror REST API reference. Fast gRPC protocol.
View all client librariesWebSocket reference
Usage
pip install websocket-client rel
python finazon_ws_example.py
import json
import rel
import websocket
dataset = 'binance'
tickers = ['BTC/USDT']
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
To subscribe to 1min candle updates within a minute (time_series), you can use the following configuration:
dataset
string
required
Filter by Finazon's dataset code
Example: binance
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
stringTSLA
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: binance
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