
Subscribe to Websocket Channels
In this episode, you’ll build a module that can manage websocket channel connections through the SX Bet API.
Websocket channels provide realtime update feeds for markets, trades, orders and more.

Sample module available on GitHub
Step 1: Generate Your API Key
Subscribing to websocket channels requires you to have an API key.
Visit the verification page and complete basic and enhanced verification for your SX Bet account
Visit your account page and generate your API key. Save it somewhere secure.

Step 2: Build a Program to Subscribe to Order Book Updates
Note: Adapt this to any other websocket channel by adjusting the details of ‘File 2’ in the prompt to match your desired channel, and including the relevant sections of the Websocket API documentation.
Send the prompt in a new conversation:
Step 3: Create Websocket Folder
1) Create a New Folder In Your Project Directory. Name the folder websocket. Then, create three files inside the websocket folder:
-
websocket.js
-
index.js
-
.env
Important: Make sure your folders match the naming of your files.

2) Add the code to each file
Paste the code from Claude into each respective file you have created, saving them as you go:
-
Windows/Linux: Ctrl + s
-
Mac: Cmd + s
Add your API key to the .env file template.

3) Install Required Dependencies
Open the terminal and run the following command
Step 4: Subscribe to a Websocket Channel
1) Fetch any market hash
2) Run the Script in the Terminal
Open the terminal and navigate to your post-order folder by running the following command.
3) Run the program
Select the option to subscribe to a channel and paste the market hash on your clipboard.

Look for a file named “websocket_logs” within your websocket folder. Select it to view the websocket updates.
