README
ΒΆ
Binance Trade Bot
Features
- Bull Trade β Buy-low-sell-high strategy for uptrending markets
- Bear Trade β Sell-high-buy-low strategy for downtrending markets
- AI Multi-Agent System β Concurrent analysis from OpenAI, DeepSeek, and Claude with weighted consensus
- Sentiment Analysis β Real-time news headlines and Fear & Greed Index integrated into AI decisions
- Trailing Stop-Loss β Dynamically locks in profits as price moves favorably
- Advanced Indicators β RSI, MACD, DEMA, Bollinger Bands, ADX, ATR, VWAP, and volume confirmation
- Full OHLCV Analysis β Uses complete candlestick data instead of close-only prices
Download
Download Precompiled Binary
You can download the precompiled binary from the repository's release artifacts.
- Visit the Releases page of the repository.
- Download the appropriate binary for your operating system (e.g., Linux, macOS, Windows).
- Make the binary executable (if required):
- On Linux or macOS:
chmod +x binance-bot
- On Linux or macOS:
- Move the binary to a directory in your
$PATHfor global access:- On Linux
sudo mv binance-bot /usr/local/bin/
Usage
β οΈ Warning: This bot is provided as-is. Use it at your own risk. Trading involves financial risks, and you may incur significant losses. Always test in a safe environment (e.g., a testnet and/or with small amounts) before deploying in live markets. The author is not responsible for any financial outcomes.
Prerequisites
Before using the Binance Trade Bot, you need to configure your environment with the Binance API client credentials. These credentials allow the bot to interact securely with your Binance account. Follow these steps to set up:
-
Obtain your Binance API Key and Secret
- Log in to your Binance account.
- Navigate to the API Management section.
- Create a new API key, choosing HMAC type and providing any label (e.g.,
CLI_Bot). - Save the API Key and Secret Key securely. You will not be able to view the secret again after closing the page.
-
Set Environment Variables Export the API credentials as environment variables in your terminal before executing the binance-bot cli:
export BINANCE_API_KEY=<your-api-key> export BINANCE_SECRET_KEY=<your-secret-key> -
Set AI Provider API Keys (optional) To enable the AI multi-agent system, export one or more of the following API keys. The system works with any combination β you can use 1, 2, or all 3 providers:
export OPENAI_API_KEY=<your-openai-api-key> export DEEPSEEK_API_KEY=<your-deepseek-api-key> export ANTHROPIC_API_KEY=<your-anthropic-api-key>Variable Provider Default Model OPENAI_API_KEYOpenAI gpt-4o-miniDEEPSEEK_API_KEYDeepSeek deepseek-chatANTHROPIC_API_KEYClaude claude-3-5-haiku-20241022If no AI keys are set, the bot runs entirely on technical indicators β AI is fully optional.
-
Create a config file You can specify a custom configuration file to adjust the bot's parameters of trading indicators.
See the sample configuration file.
Now you're ready to use the Binance Trade Bot! π
Run the Bot
Bull Trade (uptrending markets)
binance-bot -f binance-config.yml bull-trade -t "XRP/USDT" -a 50 -sl 1.5 -tp 2.0 -b 0.9998 -s 1.0003 -rp 4 -ra 0
This example:
- Trades the pair
XRP/USDTwith an amount of50. - Sets a stop-loss of
1.5%and a take-profit of2%. - Adjusts buy and sell factors for the LIMIT order target price.
- Rounds the price to 4 decimals and the amount to 0 decimals.
Bear Trade (downtrending markets)
binance-bot -f binance-config.yml bear-trade -t "BTC/USDT" -a 0.001 -sl 2.0 -tp 3.0 -b 0.9998 -s 1.0003 -rp 2 -ra 5
This example:
- Sells
0.001 BTCwhen bearish signals are detected. - Sets a stop-loss of
2%(price rises above entry) and take-profit of3%(price drops below entry). - Buys back at a lower price to capture the difference as profit.
Modify these parameters based on your specific trading requirements.
Explanation of Command Arguments
These arguments apply to both bull-trade and bear-trade commands:
| Option | Short | Description | Default |
|---|---|---|---|
--ticker |
-t |
The trading pair ticker in the format ABC/USD (e.g., BTC/USDT). |
Required |
--amount |
-a |
Amount to trade. | Required |
--stop-loss |
-sl |
Stop-loss percentage (e.g., 1.5 for 1.5%). |
3 |
--take-profit |
-tp |
Take-profit percentage (e.g., 3.0 for 3%). |
2.5 |
--buy-factor |
-b |
Factor to determine the target price for a LIMIT buy order. | 0.9999 |
--sell-factor |
-s |
Factor to determine the target price for a LIMIT sell order. | 1.0001 |
--round-price |
-rp |
Decimal precision for rounding price values. | Required |
--round-amount |
-ra |
Decimal precision for rounding amount values. | Required |
--operations |
-o |
Number of operations to execute during the trading session. | 100 |
--help |
-h |
Show help for the command. | - |
Help Commands
-
For general help on the bot:
binance-bot --helpOutput:
NAME: binance-bot - A program bot to trade in Binance USAGE: binance-bot [global options] command <command args> VERSION: v0.0.5 AUTHOR: Walter Ferreira <wferreirauy@gmail.com> COMMANDS: bull-trade, bt Start a bull trade run bear-trade, brt Start a bear trade run (sell high, buy back low) help, h Shows a list of commands or help for one command GLOBAL OPTIONS: --config-file FILE, -f FILE Load configuration from FILE (default: $HOME/binance-config.yml) --help, -h show help --version, -v print the version -
For help with the
bull-tradecommand:binance-bot bull-trade --help -
For help with the
bear-tradecommand:binance-bot bear-trade --help
Configuration
The bot is configured through a YAML file. See sample-binance-config.yml for a complete example.
Indicators Configuration
historical-prices:
period: 100 # number of candlesticks to fetch
interval: "1m" # candlestick interval (1m, 3m, 5m, 15m, 1h, etc.)
tendency:
interval: "3m" # interval for tendency calculation
direction: "up" # expected direction for bull-trade
indicators:
rsi:
interval: "5m"
length: 14
upper-limit: 70 # overbought threshold
middle-limit: 50
lower-limit: 30 # oversold threshold
dema:
length: 9
macd:
fast-length: 12
slow-length: 26
signal-length: 9
bollinger-bands:
length: 20
multiplier: 2.0
atr:
period: 14 # Average True Range for volatility
adx:
period: 14
threshold: 25 # minimum ADX value to confirm trend strength
volume:
ma-period: 20 # volume moving average period
Trailing Stop Configuration
The trailing stop-loss dynamically adjusts to lock in profits as the price moves favorably:
trailing-stop:
enabled: true
activation-pct: 1.5 # activate after price moves 1.5% in your favor
trailing-pct: 1.0 # trail by 1.0% from the peak/trough
- For bull trades: once the price rises by
activation-pctabove buy price, the stop tracks from the highest price and triggers if the price dropstrailing-pctfrom that peak. - For bear trades: once the price drops by
activation-pctbelow sell price, the stop tracks from the lowest price and triggers if the price risestrailing-pctfrom that trough.
AI Configuration
The AI multi-agent system is optional. When enabled, it queries multiple LLM providers concurrently with technical indicators and market sentiment data to produce a consensus trading signal.
ai:
enabled: true
providers:
openai:
model: "gpt-4o-mini"
deepseek:
model: "deepseek-chat"
claude:
model: "claude-3-5-haiku-20241022"
min-confidence: 0.5 # minimum consensus confidence to act (0.0 - 1.0)
How it works:
- Each configured provider receives a structured prompt with all technical indicators plus real-time sentiment data.
- Providers are queried concurrently for speed.
- Each agent returns a signal (
BUY,SELL, orHOLD), a confidence score (0.0-1.0), and reasoning. - A weighted consensus algorithm aggregates all votes to produce a final decision.
- The AI must approve (or at least not contradict) technical signals before trades are executed.
Sentiment sources (free, no API key required):
- CryptoCompare β latest news headlines for the traded coin
- Alternative.me Fear & Greed Index β overall crypto market mood
Set
ai.enabled: falseor omit all provider API keys to disable AI and run on technical indicators only.
Trading Strategy Logic
Bull-Trade
The bull-trade command is designed to operate during bull market trends, leveraging upward momentum to execute profitable trades.
Buy Conditions
The bot will place a buy order when all of these conditions are met:
- RSI: Value is below the configured
upper-limit(default 70), indicating the market is not overbought. - MACD Crossover: The MACD line crosses above the Signal line, suggesting upward momentum.
- Tendency Confirmation: The trend direction matches the configured direction (DEMA above EMA = "up").
- DEMA Proximity to Bollinger Bands: The current DEMA is closer to the Lower Band than the Upper Band, suggesting a potential reversal from oversold conditions.
- ADX Trend Strength (if configured): ADX is above the threshold (default 25), confirming a strong trend.
- Volume Confirmation (if configured): Current volume exceeds its moving average, avoiding false breakouts.
- AI Consensus (if enabled): The multi-agent system approves the entry or does not contradict it.
Sell Conditions
The bot will exit a position through one of three mechanisms:
- Trailing Stop-Loss (if enabled): After the price rises by
activation-pctabove buy price, the stop trails from the highest price. Triggers when price drops bytrailing-pctfrom the peak. - Fixed Stop-Loss: The price drops to the stop-loss percentage below buy price. Executes immediately (no AI delay on protective exits).
- Take Profit: The price reaches the take-profit percentage AND the RSI turns downward AND the AI supports the exit (if enabled).
Bear-Trade
The bear-trade command is designed to operate during bear market trends, profiting from downward price movement by selling high and buying back low.
Sell Entry Conditions
The bot will open a short position (sell) when all of these conditions are met:
- RSI: Value is above the configured
lower-limit(default 30), indicating the market is not oversold. - MACD Crossover: The MACD line crosses below the Signal line, suggesting downward momentum.
- Tendency: The trend direction is "down" (DEMA below EMA).
- DEMA Proximity to Bollinger Bands: The current DEMA is closer to the Upper Band than the Lower Band, suggesting a potential reversal from overbought conditions.
- ADX Trend Strength (if configured): ADX confirms the trend has strength.
- Volume Confirmation (if configured): Current volume exceeds its moving average.
- AI Consensus (if enabled): The multi-agent system approves the entry.
Buy-Back Exit Conditions
The bot will exit the bear position (buy back) through one of three mechanisms:
- Trailing Stop (if enabled): After the price drops by
activation-pctbelow sell price, the stop trails from the lowest price. Triggers when price rises bytrailing-pctfrom the trough. - Fixed Stop-Loss: The price rises to the stop-loss percentage above sell price. Executes immediately.
- Take Profit: The price drops to the take-profit percentage AND the RSI turns upward AND the AI supports the exit (if enabled).
AI Multi-Agent Decision Flow
When AI is enabled, the decision flow operates as follows:
Technical Indicators βββ
βββ> AI Agents (concurrent) ββ> Weighted Consensus ββ> Trade Decision
Sentiment Data βββββββββ β β β
OpenAI DeepSeek Claude
- Entry signals: Technical conditions must pass first, then AI must approve (or at least HOLD).
- Stop-loss / trailing-stop exits: Execute immediately without waiting for AI β safety first.
- Take-profit exits: Require AI confirmation to avoid exiting too early in strong trends.
β οΈ Note: Always test the bot in a safe environment (e.g., testnet or small amounts) before live trading. Ensure you understand the risks and implications of using automated trading strategies.
Build from Source
To build the binance-bot from the source code, ensure you have the following prerequisites installed:
Prerequisites
-
Go (Golang):
- Install Go from the official website.
- Ensure your Go version is at least 1.19 by running:
go version
-
Git:
- Clone the repository using Git. Install Git from here if you don't already have it.
Steps to Build
-
Clone the repository:
git clone https://github.com/wferreirauy/binance-bot.git cd binance-bot -
Build the project:
go build -o binance-bot -
Verify the executable:
./binance-bot --help
If the build succeeds, you should see the general help menu displayed, indicating that the bot has been built successfully.
References
Binance API documentation
https://binance-docs.github.io/apidocs/spot/en/#general-info
Binance GO library
https://github.com/binance/binance-connector-go
AI Provider APIs
Sentiment Data Sources
- CryptoCompare News API β Free, no API key required
- Alternative.me Fear & Greed Index β Free, no API key required
Documentation
ΒΆ
There is no documentation for this package.