Beastlorion’s Market Maker

Published by AVAX on

Open Source Dexalot Bot

Beastlorion’s open source market maker bot is now available for everyone! This three-part tutorial will walk you through the setup and implementation details. Set up Beastlorion’s market-making bot on a remote server and automate your trading on Dexalot.*

This tutorial assumes you are using apple os, linux, or if you are using windows, that you have a linux terminal installed like Mingw64 or WSL.
This walkthrough has three main parts. The first is setting up your wallet correctly to use with the bot. The second is setting up your remote server with AWS. The third part is getting the bot set up on your server. Check out the accompanying video above, read further and #OwnYourTrade on Dexalot.

1) Bot Wallet Setup

To begin, you’ll need to create a new evm wallet that your bot will use to make automated trades on Dexalot. I prefer to do this using the Rabby browser extension wallet, but any wallet that allows exporting the private key will do. Write down your backup phrase.

Next we’ll switch to the core.app browser extension wallet so that we can access the Dexalot subnet. Export the private key from the wallet created in the previous step and import to core.app to create a new wallet in the core.app browser extension.

  • Once you’ve made it this far, you will need to either send at least 2 avax to your new address on Avalanche c-chain to bridge over to the Dexalot Subnet, or you can switch to the Fuji Testnet and request some testnet avax from the public faucet. To do that, connect the core.app wallet on https://app.dexalot.com/trade/AVAX-USDC, making sure to select the correct wallet address. Then, under the balances tab, click the hamburger icon on the avax row and select “deposit to Dexalot”.
    This will initiate the transaction that bridges your avax to the Dexalot subnet.
  • Once it has been deposited onto Dexalot, you’ll want to purchase a few more ALOT tokens to use for gas. To do that, you’ll first need to sell 1 or more AVAX for USDC and then use the USDC to buy a few ALOT tokens.
  • Once they have been purchased, under the balances tab, add them to your gas tank.

2) Remote Server Setup

Now that the wallet is all set up to trade on Dexalot, we can begin setting up the market maker bot to automate trading for us.

To ensure that our bot is able to run 24/7 unimpeded, we are going to start by setting up a remote server. For beginners, I recommend using Amazon Web Services, but any hosting service will work. So if you don’t have an account with them yet, go ahead and sign up.

  • Once you’re logged in, navigate to the EC2 Dashboard and then to the instances page. In the top right corner, select a location for your server that is crypto friendly to run your bot in like Singapore (This is necessary to avoid issues with getting price feed data from crypto exchanges).

Click “Launch Instances” and choose a name for your server. Choose Ubuntu 22.04 LTS 64bit. Choose t2.micro for your machine. You can switch to a stronger machine if necessary later on.

Create a new Keypair. Don’t put spaces or symbols in the name. Save it to your folder of choice, I’m just going to save it to my Desktop folder.
Under Firewall settings, only allow SSH traffic from your IP or the IP which you will be connecting to your remote server from. You can update or change your firewall settings later.

Click “Launch Instance”

Return to the Instances page and refresh the page, right click your instance and select connect and go to the SSH Client tab. On your computer, open up your Linux terminal and navigate to the folder that you saved your key file in. If you saved it in Home or Desktop, you can navigate there by running “cd ~” or “cd Desktop.”

  • Once you have navigated to that folder, copy and paste the Chmod command from the AWS instructions in #3. If that doesn’t give you any error, it should have worked. Then copy and paste the example connect code into your terminal, make sure it is connecting to Ubuntu and not root, and run it.
  • Once you are connected to your server, you will need to start setting up the build environment. To do that run “sudo apt-get install build-essentials”, accept, and then run “sudo apt-get update”. Then run “sudo apt install npm”. This can take a minute.
  • Once that is finished run “sudo npm install -g yarn”. Then, to install nvm, run “curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash”
    Next, you’ll want to disconnect from your server by pressing ctr+d and then reconnect using the connect command again, which can easily be found by pressing the up arrow key to get the last command you ran from that instance of terminal which should be the connect script. Otherwise, you’ll need to get the example connect script from AWS again. Finally, run “nvm install 20.9.0”.

If you’ve made it this far, your build environment should be complete and we can move onto setting up the bot.

3) Bot Setup

Now that your build environment is set up we can move onto getting the bot installed and running. To do this you’ll need to clone the bot code repository from github. You can do this by running “git clone https://github.com/Beastlorion/dexalot_samplebot.git".

  • Once that is done, run “cd dexalot_samplebot” to enter the directory of the bot.
  • Once you are inside the dexalot_samplebot directory, run “yarn install”.

You’ll need to set up your environment variables file. To do this run “vi .env.production” or if you are using the testnet, run “vi .env.fuji”.

  • Once you are in the vim editor, type “set: paste” and hit enter, then press “i” to enter the paste insert mode.

Copy the text from the readme on github repository page and then right click and paste it into the vim editor. Use the arrow keys to navigate to the private_key value and inside the quotes, remove the X’s and paste your private key. Then, below that, remove the X’s for account_no and paste in your public address. To save and exit, press the escape key to exit insert mode and then type “:wq” to write the file and quit the editor.

Your bot is all set up now! You can run it with “yarn marketMakerLists-prod — pair=’AVAX/USDC’” or if you are using fuji testnet, “yarn marketMakerLists-prod — pair=’AVAX/USDC’”.

If it’s working, it should pause for a moment and then print the current best bid and best ask from the orderbook. Then it will tell you that you have no price data, that’s the next step!

Press ctr+c to initiate the stop procedure for the bot. Once it says SHUTTING DOWN it is finished.

Run “cd ~” to return to the home directory. To get price feeds, we’re going to clone the price feed script I made for this bot. You can do that by running “git clone https://github.com/Beastlorion/dexalotBot_price_feeds.git"

Before we enter that directory, we’re going to utilize the screen command to enter a new process called a “screen” so that we can have the price feeds script running at the same time as our market maker. We can create it by running “screen -S ‘price_feed’”. This will create the screen called “price_feed” and enter into it. Now, let’s enter the new directory we cloned by running “cd dexalotBot_price_feeds”. Now run “npm install” to install the dependencies, and finally “node index.js” to start the price feeds bot and we should start to see the prices printed.

Now that the price_feeds bot is running, we can use ctr+a and then ctr+d to exit that screen instance and return to our initial ssh process. The price feeds bot is still running as a background process. We can list the active screens by running “screen -ls”. You can reconnect to it at any time by running “screen -r ‘price_feed’”

Let’s make a new screen for our bot and enter it by running “screen -S ‘avax_usdc’”. Enter the samplebot directory by running “cd dexalot_samplebot” and now let’s start the bot back up by running “yarn marketMakerLists-prod — pair=’AVAX/USDC’” again.

If you’ve funded the bot wallet on the subnet already and followed the instructions in this guide correctly, it should start placing orders with the funds you have available in your wallet.

You can see the orders showing up on the dexalot UI at https://app.dexalot.com/trade/AVAX-USDC.

You can stop the script by pressing ctr+c, or leave it running and disconnect from the screen by pressing ctr+a and then ctr+d.

You can adjust the settings for the bot in the .env.production file that we set up earlier by navigating back into the dexalot_samplebot directory and then running “vi .env.production” and changing the values in the file by pressing “i” to enter insert mode and then make changes.

When you are finished press the escape key and type “:wq” to save and quit or if you want to exit without saving changes you can type “:q!”

If you want to trade another market with this bot like BTC.b/USDC, you’ll need to paste another configuration object in the .env.production file below the AVAX/USDC configuration object. You can copy the “AVAX/USDC” object and paste it directly below, and then change the name to “BTC.b/USDC” since that is the name of the pair on Dexalot. Save and quit, create a new screen for the pair, and then run “yarn marketMakerLists-prod — pair=’BTC.b/USDC’”

Links:

Core app: https://core.app/

Dexalot: https://app.dexalot.com/trade/AVAX-USDC

AWS: https://aws.amazon.com/

Bot Repository: https://github.com/Beastlorion/dexalo…

Price_feed repository: https://github.com/Beastlorion/dexalo…

Please note that this is a community contribution, not a Dexalot product. Dexalot would like the community to know about this wonderful open source offering. Do your own research and use at your own risk.

Author: Beastlorion

Editor: Brad McFall

Graphics: Can Toygar

About Dexalot:

Dexalot is a revolutionary decentralized exchange bringing the traditional centralized exchange look and feel to a decentralized on-chain application. Its mission is to bring a truly inclusive and transparent environment where Dexalot users can trade crypto securely and efficiently, with no slippage or custody risk. It is built on Avalanche, the fastest smart contracts platform in the blockchain industry.

Website | Twitter | Telegram | Medium |Discord


Beastlorion’s Market Maker was originally published in Dexalot on Medium, where people are continuing the conversation by highlighting and responding to this story.

Source

Categories: DEFI_NEWS