top of page

The Official Blog

of SX Bet

Building a Betting Bot: Module 4

Post and Cancel Orders

In this episode, you’ll first build a module that can post new orders to the exchange (maker offers that a taker can fill) and add the ability to cancel orders.

Step 1: Set up your SX Bet account

If you haven’t already, sign up for SX Bet and complete the following

1) Sign up for SX Bet

2) Fund your wallet with USDC 

3) Place a “Market Order”

4) Complete enhanced verification

52-min.png

Step 2: Access Your Private Key

To interact with the API, you must use your private key—a cryptographic key that authorizes transactions from your wallet. It allows the API to verify that bets are being placed by the wallet’s owner.

⚠️ Critical Security Notice

Your private key grants full control over your wallet and funds. Never share your private key with anyone, including individuals claiming to represent SX Bet support. If someone gains access to your private key, they can place bets, withdraw funds, or fully compromise your wallet.

 

Private key access varies by signup method: MetaMask or Email.

Open the MetaMask extension and click the account name (e.g., “Account 1”).

pkmm1.png
pkmm2.png

Select Show private key, enter your password, and copy the key.

pkmm3.png

Click the three dots (⋯) > Account details.

Step 3: Create Program to Post Orders

A handful of constants need to be included in an API request to post an order. These include:

1) MakerAddress = [Your Wallet Address]

2) BaseToken (USDC) = 0x6629Ce1Cf35Cc1329ebB4F63202F3f197b3F050B

3) Executor Address = 0x52adf738AAD93c31f798a30b2C74D658e1E9a562

Copy your wallet address — On SX Bet, click your username in the top right corner, then copy your wallet address to your clipboard. 

Add your wallet address and send the prompt in a new conversation.

Claude should respond with something like this:

createfilestructure (1).png

Step 4: Create Post Orders Folder

1) Create a new folder in your project directory.

Name the folder post-order. Then, create four files inside the post-order folder:

 

  1. orderPoster.js

  2. oddsUtils.js

  3. index.js

  4. .env

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 private key to the .env file template.

addprivatekey.png

2) Install Required Dependencies 

Open the terminal and run the following command:

Step 5: Place an Order

1) Fetch any market hash and run the script in the terminal.

Open the terminal and navigate to your post-order folder by running the following command

2) Run the program

3) Enter your market hash and order details to post the order

postorderapiresponse.png

If successful, you should see the API response with your order details in the terminal. Double-check that the offer exists in your offered bets.

Step 6: Create Program to Cancel Orders

Send the following prompt in your existing conversation.

Claude should respond with something like this:

claudecancelresponse.png

Step 7: Create Cancel Order Files

1) Create a file named orderCanceller.js inside the post-order folder.

createcancelfile.png

Add the orderCanceller.js code Claude sent to the orderCanceller.js file. Check important statement file names match.

2) Install Required Dependencies 

Open the terminal and run the following command:

Step 8: Cancel an Order

1) Open the terminal and navigate to your post-order folder by running the following command

2) Run the program

Select the option to post an order on any market and copy the order hash from the terminal after your order has been posted.

copyorderhash.png

3) Run the script again with the following command

Select the option to cancel an order and paste your order hash when prompted.

Double-check that the offer no longer exists in your offered bets.

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