chrisleekr / binance-trading-bot
- понедельник, 26 апреля 2021 г. в 00:30:19
Automated Binance trading bot - Buy low/Sell high with stop loss limit/Trade multiple cryptocurrencies
Automated Binance trading bot with trailing buy/sell strategy
This is a test project. I am just testing my code.
I cannot guarantee whether you can make money or not.
So use it at your own risk! I have no responsibility for any loss or hardship incurred directly or indirectly by using this code.
Before updating the bot, make sure to record the last buy price in the note. It may lose the configuration or last buy price records.
As I introduce a new feature, I did lots of refactoring the code including
settings. If the bot version is lower than the version 0.0.57
, then the update
will cause lost your settings and the last buy price records. You must write
down settings and the last buy price records and re-configure after the upgrade.
If experiences any issue, simply delete all docker volumes/images and re-launch the bot.
This bot is using the concept of trailing buy/sell order which allows following the price fall/rise.
The bot will continuously monitor the lowest value for the period of the candles. Once the current price reaches the lowest price, then the bot will place a STOP-LOSS-LIMIT order to buy. If the current price continuously falls, then the bot will cancel the previous order and re-place the new STOP-LOSS-LIMIT order with the new price.
Let say, if the buy configurations are set as below:
And the market is as below:
Then the bot will not place an order because the trigger price ($100.5) is less than the current price ($101).
In the next tick, the market changes as below:
The bot will place new STOP-LOSS-LIMIT order for buying because the current price ($100) is less than the trigger price ($100.5). For the simple calculation, I do not take an account for the commission. In real trading, the quantity may be different. The new buy order will be placed as below:
In the next tick, the market changes as below:
As the open order's stop price ($101) is higher than the current limit price ($100.089), the bot will cancel the open order and place new STOP-LOSS-LIMIT order as below:
If the price continuously falls, then the new buy order will be placed with the new price.
And if the market changes as below in the next tick:
Then the current price reaches the stop price ($99.99); hence, the order will be executed with the limit price ($100.089).
If there is enough balance for selling and the last buy price is recorded in the bot, then the bot will start monitoring the sell signal. Once the current price reaches the trigger price, then the bot will place a STOP-LOSS-LIMIT order to sell. If the current price continuously rises, then the bot will cancel the previous order and re-place the new STOP-LOSS-LIMIT order with the new price.
Let say, if the sell configurations are set as below:
And the market is as below:
Then the bot will not place an order because the trigger price ($105) is higher than the current price ($100).
If the price is continuously falling, then the bot will keep monitoring until the price reaches the trigger price.
In the next tick, the market changes as below:
The bot will place new STOP-LOSS-LIMIT order for selling because the current price ($105) is higher or equal than the trigger price ($105). For the simple calculation, I do not take an account for the commission. In real trading, the quantity may be different. The new sell order will be placed as below:
In the next tick, the market changes as below:
As the open order's stop price ($102.29) is less than the current limit price ($103.774), the bot will cancel the open order and place new STOP-LOSS-LIMIT order as below:
If the price continuously rises, then the new sell order will be placed with the new price.
And if the market changes as below in the next tick:
The the current price reaches the stop price ($103.88); hence, the order will be executed with the limit price ($103.774).
React.js based frontend communicating via Web Socket:
Use environment parameters to adjust parameters. Check
/config/custom-environment-variables.json
to see list of available environment
parameters.
Or use the frontend to adjust configurations after launching the application.
Create .env
file based on .env.dist
.
Environment Key | Description | Sample Value |
---|---|---|
BINANCE_LIVE_API_KEY | Binance API key for live | (from Binance) |
BINANCE_LIVE_SECRET_KEY | Binance API secret for live | (from Binance) |
BINANCE_TEST_API_KEY | Binance API key for test | (from Binance) |
BINANCE_TEST_SECRET_KEY | Binance API secret for test | (from Binance) |
BINANCE_SLACK_WEBHOOK_URL | Slack webhook URL | (from Slack) |
BINANCE_SLACK_CHANNEL | Slack channel | "#binance" |
BINANCE_SLACK_USERNAME | Slack username | Chris |
BINANCE_LOCAL_TUNNEL_SUBDOMAIN | Local tunnel public URL subdomain | binance |
Check docker-compose.yml
for BINANCE_MODE
environment parameter
Launch the application with docker-compose
git pull
docker-compose up -d
or using the latest build image from DockerHub
git pull
docker-compose -f docker-compose.server.yml pull
docker-compose -f docker-compose.server.yml up -d
or if using Raspberry Pi 32bit. Must build again for Raspberry Pi.
git pull
docker build . --build-arg NODE_ENV=production --target production-stage -t chrisleekr/binance-trading-bot:latest
docker-compose -f docker-compose.rpi.yml up -d
Open browser http://0.0.0.0:8080
to see the frontend
In Portainer create new Stack
Copy content of docker-stack.yml
or upload the file
Set environment keys for binance-bot
in the docker-stack.yml
Launch and open browser http://0.0.0.0:8080
to see the frontend
Frontend Mobile | Setting |
---|---|
Frontend Desktop |
---|
Chart | Buy Orders | Sell Orders |
---|---|---|
Trade History | PNL Analysis |
---|---|
Please refer CHANGELOG.md to view the past changes.
chrisleekr |
Romuald R. |
hipposen |
thamlth |