This trading bot is designed to function with the DLMM SDK to buy and sell a specific asset in a recurring loop as set by the initiator. The bot is designed to be run on a server and will run until the loop raised to its power is ended or it errors out for any reason.
The Bot is funded from a main account passed via the PRIVATE_KEY in the .env file (without the 0x) which funds other generated wallets to be used for trading. The bot will then use the generated wallets to trade the asset in the loop.
The bot will buy the asset and sell it at the market price. The bot will also check the balance of the asset in the wallet and trade it within the margin of the balance to set amount.
In the case of an error, all trading wallets aree defunded and the bot will stop trading. If in the course of defunding, there is an error, the script creates an error log file with that set time/date in UNIX format, detailing the cause of the error and indicating the private keys yet to be defunded for manual action.
As a prerequisite, you need to have the following installed on your machine:
- Node.js
- npm
To install the dependencies, run the following command in the root directory of the project:
npm install
-- 查看数据库
SHOW DATABASES;
-- 使用数据库
USE trading_bot;
-- 查看表
SHOW TABLES;
-- 查看表结构
DESCRIBE traders;
DESCRIBE transactions;
The bot is written in TypeScript and needs to be compiled down to JavaScript to run it
the source files are in the src folder and the compiled files are in the dist folder
The const values in the const.ts file are the parameters that need to be set for the bot to run. The parameters are as follows:
assetParamswhich is an object with two keys.WBNBandTOKEN/USDCWBNB/TOKENwhich is an object with the following keys:minminimum amount of the asset to be traded.minmust be greater than or equal to 0.01maxmaximum amount of the asset to be traded and initially funded.maxmust be greater thanmin
wallets_countthis variable is the number of wallets to be generated for trading
No other variable in the const.ts file needs to be changed for the bot to run properly
Now, there are 3 main commands and files in the project that you need to be aware of:
init.tsis the opening file to starting the bot. It handles the generation, funding, router approval and storage of the wallet addresses or traders. It is required that this file is run before the bot can be run:- To run the file, use the following command:
npm run init
- To run the file, use the following command:
bot.tsis the file that starts the bot. It handles the trading of the asset in a 10 count loop. It is required that theinit.tsfile is run before this file can be run:- To run the file, use the following command:
npm run bot
- To run the file, use the following command:
stop.tsis the file that stops the bot. It handles the defunding of the wallets:- To run the file, use the following command:
npm run stop
- To run the file, use the following command:
startA command that runs all 3 commands in a sequence:- To run the file, use the following command:
npm run start
- To run the file, use the following command:
This project is licensed under the MIT License - see the LICENSE file for details