top of page

The Official Blog

of SX Bet

Building a Betting Bot: Module 3

Fetch Orders & Trades

In this episode, you’ll build a module that can fetch a snapshot of the active orders on a specific market from the SX Bet API. Additionally, you will create a utility module that works alongside the order-fetching module to make useful calculations and conversions.

 

To test the module, you will also create an entry point file that will:

 

  1. Allow you to enter the market hash of a market you would like to retrieve orders from

  2. Display the active orders on each outcome of the market from the perspective of the taker

 

The purpose of this is to ensure your module can retrieve maker orders and derive the odds and liquidity available to a taker based on the active maker orders.

Sample module available on GitHub

51-min.png

Step 1: Create A Program to Fetch Active Orders

The first step is to create a comprehensive prompt:

Claude will respond with an updated program; copy that to your clipboard.

clauderesponseorders.png

Important: Note the naming conventions of the files. You will need this for later.

Step 2: Create Fetch Active Orders Folder

1) Create a new folder in your project directory.

newfolder.png

Name the folder fetch-order. Then, create three new files inside the folder. Make sure the folder names match the names of the code in the previous step. 

 

  1. index.js

  2. utils.js

  3. orderFetcher.js

createfilestructure.png

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

The index.js file imports functions from both the utility and order-fetching files. Make sure the file names in your import line match the names of the files you created.

Screenshot 2025-04-07 at 7.04.56 PM.png

Step 3: Fetch Active Orders

1) Fetch any market hash 

Head to the popular page on SX Bet, then open developer tools with the following keyboard shortcut:

  • Windows/Linux: Ctrl + Shift + i

  • Mac: Cmd + Option + i

 

  1. Select the network tab from the developer tools window, and select market from the popular page

  2. Look for a network request beginning with orders?marketHashes= and select it

  3. Select the payload tab of the request

  4. Highlight and copy the first market hash to your clipboard

getmarkethash.png

2) Run the script in the Terminal

Open the terminal and navigate to your fetch-orders folder by running the following command:

Then run the program by entering the following command in the terminal.

When prompted, paste the market hash on your clipboard.

entermarkethash (1).png

You should see the orders on your selected market in the terminal.

ordersresponse.png

Step 4: Create Program to Fetch Active Trades

1) The first step is to create a comprehensive prompt:

Claude should respond with something like this:

Step 5: Create Fetch Active Trades Folders

1) Create a new folder in your project directory.

newfolder (1).png

Name the folder fetch--trades. Then, create three new files inside the folder. Make sure the folder names match the names of the code in the previous step. 

 

  1. index.js

  2. utils.js

  3. tradeFetcher.js

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

Copy the code from the utils.js file you created in the fetch-orders folder, and paste it into the utils.js file you created in the fetch-trades folder.

*The index.js entry point file imports functions from both the utility file and trade fetching file; you may need to edit your import statements at the top of the index.js file to align with the file names you have used.

Step 6: Fetch Active Trades

Claude will provide instructions for how to run the application with different query parameters.

Available Parameters 

  • --bettor [address]: Filter trades by bettor wallet address

  • --market [marketHash]: Filter trades by market hash

  • --chain [SXR|SXN]: Filter trades by chain version

  • --token [address]: Filter trades by base token address

  • --records [number]: Number of records to retrieve (default: 100)

  • --hours [number]: Only fetch trades from the last X hours

1) Open the terminal in Visual Studio Code

  • Windows/Linux: Ctrl + Shift + ~

  • Mac: Ctrl + Shift + ~

Navigate to your fetch-trades folder by running the following command

2)  Visit SX Lab, select any tipster from the list and copy their wallet address to your clipboard.

Screenshot 2025-04-07 at 8.10.16 PM.png

Then, run a query to fetch:

 

  • Up to 50 trades

  • Only trades made by 0x80Aa1454d7a62296Fd326fBCc715479fDE9022a3

  • Only trades made within the last 8 hours

  • Only trades made on SX Rollup network (SXR)

 

By sending the following command in your terminal

You should see the trades matching your query in the terminal.

3-min.png
3-min.png
50-min.png
51-min.png
52-min.png
53-min.png
54-min.png
bottom of page