Skip to content

EntySquare/trading-bot-script

 
 

Repository files navigation

Trading Bot Script

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.

Getting Started

As a prerequisite, you need to have the following installed on your machine:

  • Node.js
  • npm

Installation

To install the dependencies, run the following command in the root directory of the project:

npm install

mysql


-- 查看数据库
SHOW DATABASES;

-- 使用数据库
USE trading_bot;

-- 查看表
SHOW TABLES;

-- 查看表结构
DESCRIBE traders;
DESCRIBE transactions;

Overview

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:

  • assetParams which is an object with two keys. WBNB and TOKEN/USDC
    • WBNB/TOKEN which is an object with the following keys:
      • min minimum amount of the asset to be traded. min must be greater than or equal to 0.01
      • max maximum amount of the asset to be traded and initially funded. max must be greater than min
  • wallets_count this 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

Running the script

Now, there are 3 main commands and files in the project that you need to be aware of:

  • init.ts is 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
  • bot.ts is the file that starts the bot. It handles the trading of the asset in a 10 count loop. It is required that the init.ts file is run before this file can be run:
    • To run the file, use the following command:
      npm run bot
  • stop.ts is the file that stops the bot. It handles the defunding of the wallets:
    • To run the file, use the following command:
      npm run stop
  • start A command that runs all 3 commands in a sequence:
    • To run the file, use the following command:
      npm run start

License

This project is licensed under the MIT License - see the LICENSE file for details

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 98.8%
  • JavaScript 1.2%