Websocket
General Information
BFX uses a centrifuge scalable real-time websocket for publishing messages. We recommend using one of the client SDKs available on the official centrifuge page.
List of centrifuge websocket client SDKs
centrifuge-js – for browser, NodeJS and React Native
centrifuge-go - for Go language
centrifuge-dart - for Dart and Flutter
centrifuge-swift – for native iOS development
centrifuge-java – for native Android development and general Java
Testnet websocket endpoint: wss://api.testnet.rabbitx.io/ws
Mainnet websocket endpoint: wss://api.prod.rabbitx.io/ws
BFX offers a complete pub/sub API with table diffing over WebSocket. You may subscribe to real-time changes on any available channel. All channels require authentication.
Websocket packets may contain multiple messages separated \n
. It is recommended to split the message string before parsing the JSON.
Authentication
Before subscribing to channels, you must first authenticate using the JWT token received through onboarding. You only need to authenticate once at the beginning. To authenticate, send the following message:
jwt_token
can be retrieved by onboarding.
Once onboarded, to subscribe to a channel, send
Note: JWT tokens expire in 48hrs. If your JWT token is expired, you will need to update it. If your JWT token is expired, the connection will be disconnected and you will need to resubscribe with a new token.
Initial snapshot
The initial snapshot will send ALL information about the account. Subsequent messages will only send account change updates.
Initial messages will always be in the following format:
Updates
Subsequent messages will only send account updates.
Update messages are in the following format:
Reference implementation for channel subscription
Channels
profile_id
is retrieved by onboarding.
Websocket connections go through the following lifecycle:
Establish a websocket connection with
wss://api.testnet.rabbitx.io/ws/
Authenticate with JWT token
Subscribe to a channel with
{"subscribe": {'channel':"trade:BTC-USD", 'name':"js"}, 'id': "<counter increment>"}
Receive data from channels
Handle pings at regular intervals: Send an empty frame to the server
{}
when you get an empty message from the exchange.
Reference implementation
Python: https://github.com/rabbitx-io/rabbitx-python-client
Examples: https://github.com/rabbitx-io/rabbitx-python-client/blob/main/examples/ws.py
Example script
Last updated