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 hardshipincurred directly or indirectly by using this code. Readdisclaimer before 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.
This bot is using the concept of trailing buy/sell order which allows following the price fall/rise.
Trailing Stop OrdersAbout Trailing Stop Orders Concept you can find at Binance Official document
TL;DRPlace orders at a fixed value or percentage when the price changes. Using this feature you can buy at the lowest possible price when buying down and sell at the highest possible price when selling up.
The bot will continuously monitor the coin based on the grid trade configuration.
For grid trade #1, the bot will place a STOP-LOSS-LIMIT order to buy when the current price reaches the lowest price. 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.
After grid trade #1, the bot will monitor the COIN based on the last buy price.
Let say, if the buy grid trade configurations are set as below:
No# | Trigger Percentage | Stop Price Percentage | Limit price percentage | USDT |
---|---|---|---|---|
1 | 1 | 1.05 | 1.051 | 50 |
2 | 0.8 | 1.03 | 1.031 | 100 |
To make it easier to understand, I will use $
as a USDT symbol. For the simple calculation, I do not take an account for the commission. In real trading, the quantity may be different.
Your 1st grid trading for buying is configured as below:
And the market is as below:
When the current price is falling to the lowest price ($100) and lower than ATH(All-Time High) restricted price if enabled, the bot will place new STOP-LOSS-LIMIT order for buying.
Let's assume the market changes as below:
Then the bot will follow the price fall and place new STOP-LOSS-LIMIT order as below:
Let's assume the market changes as below:
Then the bot will execute 1st purchase for the coin. The last buy price will be recorded as $99.845
. The purchased quantity will be 0.5
.
Once the coin is purchased, the bot will start monitoring the sell signal and at the same time, monitor the next grid trading for buying.
Your 2nd grid trading for buying is configured as below:
And if the current price is continuously falling to $79.876
(20% lower), then the bot will place new STOP-LOSS-LIMIT order for the 2nd grid trading for the coin.
Let's assume the market changes as below:
Then the bot will follow the price fall and place new STOP-LOSS-LIMT order as below:
Let's assume the market changes as below:
Then the bot will execute 2nd purchase for the coin. The last buy price will be automatically re-calculated as below:
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 of the grid trade #1. Once the current price reaches the trigger price of the grid trade #1, 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 grid trade configurations are set as below:
No# | Trigger Percentage | Stop Price Percentage | Limit price percentage | Sell Quantity Percentage |
---|---|---|---|---|
1st | 1.05 | 0.97 | 0.969 | 0.5 |
2nd | 1.08 | 0.95 | 0.949 | 1 |
Unlike buy, the sell configuration will use the percentage of a quantity. If you want to sell all of your coin quantity, then simply configure it as 1
(100%).
From the last buy actions, you now have the following balances:
Your 1st grid trading for selling is configured as below:
Let's assume the market changes as below:
As the current price is higher than the sell trigger price($87.99), then the bot will place new STOP-LOSS-LIMIT order for selling.
Let's assume the market changes as below:
Then the bot will follow the price rise and place new STOP-LOSS-LIMIT order as below:
Let's assume the market changes as below:
Then the bot will execute 1st sell for the coin. Then the bot will now wait for 2nd selling trigger price ($83.80 * 1.08 = $90.504).
Let's assume the market changes as below:
Then the current price($91) is higher than 2nd selling trigger price ($90.504), the bot will place new STOP-LOSS-LIMIT order as below:
Let's assume the market changes as below:
Then the bot will follow the price rise and place new STOP-LOSS-LIMT order as below:
Let's assume the market changes as below:
Then the bot will execute 2nd sell for the coin.
The final profit would be
Let say, if the sell Stop-Loss configurations are set as below:
And the market is as below:
Then the bot will not place a Stop-Loss order because the Stop-Loss price ($90) is less than the current price ($95).
If the price is continuously falling, then the bot will keep monitoring until the price reaches the Stop-Loss price.
In the next tick, the market changes as below:
The bot will place new MARKET order for selling because the current price ($90) is less or equal than the Stop-Loss price ($90). In real trading, the quantity may be different.
The bot will also set the symbol to be temporarily disabled for 60 minutes to avoid buying/sell continuously. In the frontend, the action will display the pause icon and how long left to be enabled again. The symbol can be enabled by clicking the play icon.
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 Spot Test Network) |
BINANCE_TEST_SECRET_KEY | Binance API secret for test | (from Binance Spot Test Network) |
BINANCE_SLACK_ENABLED | Slack enable/disable | true |
BINANCE_SLACK_WEBHOOK_URL | Slack webhook URL | (from Slack) |
BINANCE_SLACK_CHANNEL | Slack channel | "#binance" |
BINANCE_SLACK_USERNAME | Slack username | Chris |
BINANCE_LOCAL_TUNNEL_ENABLED | Enable/Disable local tunnel | true |
BINANCE_LOCAL_TUNNEL_SUBDOMAIN | Local tunnel public URL subdomain | binance |
BINANCE_AUTHENTICATION_ENABLED | Enable/Disable frontend authentication | true |
BINANCE_AUTHENTICATION_PASSWORD | Frontend password | 123456 |
BINANCE_LOG_LEVEL | Logging level. Possible values described on bunyan docs. |
ERROR |
A local tunnel makes the bot accessible from the outside. Please set the subdomain of the local tunnel as a subdomain that only you can remember.You must change the authentication password; otherwise, it will be configured as the default password.
Launch/Update the bot with docker-compose
Pull latest code first:
git pull
If want production/live mode, then use the latest build image from DockerHub:
docker-compose -f docker-compose.server.yml pull
docker-compose -f docker-compose.server.yml up -d
Or if want development/test mode, then run below commands:
docker-compose up -d --build
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
Password Protected | Frontend Mobile |
---|---|
Setting | Manual Trade |
---|---|
Frontend Desktop | Closed Trades |
---|---|
Chart | Buy Orders | Sell Orders |
---|---|---|
Please referCHANGELOG.mdto view the past changes.
If you find this project helpful, feel free to make a smalldonationto the developer.
Thanks to all contributors
I give no warranty and accepts no responsibility or liability for the accuracy or the completeness of the information and materials contained in this project. Under no circumstances will I be held responsible or liable in any way for any claims, damages, losses, expenses, costs or liabilities whatsoever (including, without limitation, any direct or indirect damages for loss of profits, business interruption or loss of information) resulting from or arising directly or indirectly from your use of or inability to use this code or any code linked to it, or from your reliance on the information and material on this code, even if I have been advised of the possibility of such damages in advance.
So use it at your own risk!
相关资料: 这是一个C++ based的画图工具,效率应该能保证crypto_monitor 这是一个交易框架,应该比较全面,看这个2.4K的星星 Krypto-trading-bot 关于AS模型的介绍,我之前写过一篇博客,链接在这里: 量化投资模型——高频交易AS模型相关(Avellaneda & Stoikov’s) 一个C++实现的模型:CamCapital 另一个实现的模型:gamma-
binance Node.js connector for the Binance APIs and WebSockets, with TypeScript & browser support. Heavy integration testing with real API calls to support implementation stability. Support REST APIs f
Crypto Trading Bot Deprecation Notice Firstly, I'd like to thank everyone who's shown an interest in this repo. I'd also like to apologize for my lack of support overthe last few years - I received no
self reminder: patience is the mother of science *** REFUGEES WELCOME! *** *** FATAL ROUTES? *** K is a very low latency market making trading bot with a fully featured web interface. It can pla
go-binance A Golang SDK for binance API. All the REST APIs listed in binance API document are implemented, as well as the websocket APIs. For best compatibility, please use Go >= 1.8. Make sure you ha
Binance Trader (RC 2) This is an experimental bot for auto trading the binance.com exchange. @yasinkuyu Configuration Signup for Binance Enable Two-factor Authentication Go API Center, Create New Api
Deep Trading Agent Deep Reinforcement Learning based Trading Agent for Bitcoin using DeepSense Network for Q function approximation. For complete details of the dataset, preprocessing, network archite