BFX uses a centrifuge scalable real-time websocket for publishing messages. We recommend using one of the client SDKs available on the official centrifuge .
List of centrifuge websocket client SDKs
– for browser, NodeJS and React Native
- for Go language
- for Dart and Flutter
– for native iOS development
– for native Android development and general Java
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 .
Websocket packets may contain multiple messages separated \n. It is recommended to split the message string before parsing the JSON.
def on_message(self, ws: WebSocketApp, message: str):
for line in message.split('\n'):
try:
data = json.loads(line)
except Exception as e:
print(u'\u001b[31m ~~~ EXCEPTION ~~~')
print(e)
print(message, u'u\u001b[0m')
return
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:
data = {'connect': {'token':"<jwt token>", name='js'}, 'id'=1}
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: