Binance Spot Trader
Autonomous spot trading bot for Binance. Combines technical indicators with LLM-powered market sentiment analysis to execute trades on any Binance spot pair.
Prerequisites
- - Binance account with API keys (spot trading enabled, withdrawal DISABLED)
- Anthropic API key (uses Haiku ~$0.001/eval)
- Python 3.10+
Setup
1. Install
CODEBLOCK0
2. Configure
Create .env:
CODEBLOCK1
3. Run
CODEBLOCK2
Or via cron:
CODEBLOCK3
Strategies
Momentum (default)
- - Buys when price crosses above 20-EMA with volume spike
- Sells when price crosses below 20-EMA or hits TP/SL
- Best for trending markets (BTC, ETH, SOL)
Mean Reversion
- - Buys when RSI < 30 (oversold) and price near Bollinger Band lower
- Sells when RSI > 70 (overbought) or price near upper band
- Best for range-bound markets
DCA (Dollar Cost Average)
- - Buys fixed amount at regular intervals regardless of price
- Configurable interval (hourly, daily, weekly)
- Lowest risk strategy for long-term accumulation
LLM-Enhanced (all strategies)
- - Before each trade, asks Claude Haiku for market sentiment
- Evaluates: recent news, price action, volume patterns, market structure
- Can veto a trade signal if sentiment is strongly against
Trading Parameters
| Parameter | Default | Description |
|---|
| INLINECODE1 | INLINECODE2 | Comma-separated trading pairs |
| INLINECODE3 |
momentum |
momentum,
mean_reversion, or
dca |
|
TRADE_SIZE_PCT |
5 | % of portfolio per trade |
|
MAX_POSITIONS |
5 | Max concurrent open positions |
|
TAKE_PROFIT_PCT |
5 | Take profit % |
|
STOP_LOSS_PCT |
3 | Stop loss % |
|
DCA_INTERVAL |
daily | For DCA:
hourly,
daily,
weekly |
|
DCA_AMOUNT_USDT |
50 | USDT per DCA buy |
|
USE_LLM |
true | Enable LLM sentiment filter |
Monitoring
CODEBLOCK4
⚠️ Security Considerations
- - NEVER enable withdrawal on API keys — trading only
- IP-restrict your API keys on Binance
- Use a sub-account with limited funds for bot trading
- Start with tiny amounts ($50-100) and paper trade first
- Monitor actively during first 24 hours
- Set up Binance email alerts for all trades
- API keys on disk — secure your server (SSH keys only, firewall, chmod 600)
References
- - See
references/binance-api.md for REST API docs - See
references/indicators.md for technical analysis details
Binance 现货交易机器人
适用于Binance的自主现货交易机器人。结合技术指标与LLM驱动的市场情绪分析,可在任何Binance现货交易对上执行交易。
前置条件
- - Binance账户,需拥有API密钥(已启用现货交易,禁用提现功能)
- Anthropic API密钥(使用Haiku模型,每次评估约$0.001)
- Python 3.10+
设置
1. 安装
bash
bash {baseDir}/scripts/setup.sh
2. 配置
创建.env文件:
BINANCEAPIKEY=<你的API密钥>
BINANCESECRETKEY=<你的私钥>
LLMAPIKEY=
PAIRS=BTCUSDT,ETHUSDT,SOLUSDT
STRATEGY=momentum
TRADESIZEPCT=5
MAX_POSITIONS=5
3. 运行
bash
python3 {baseDir}/scripts/trader.py
或通过cron定时任务:
/5 * cd /opt/trader && python3 trader.py >> trader.log 2>&1
策略
动量策略(默认)
- - 当价格上穿20-EMA且成交量放大时买入
- 当价格下穿20-EMA或触及止盈/止损时卖出
- 最适合趋势市场(BTC、ETH、SOL)
均值回归策略
- - 当RSI < 30(超卖)且价格接近布林带下轨时买入
- 当RSI > 70(超买)或价格接近布林带上轨时卖出
- 最适合区间震荡市场
DCA(定投策略)
- - 无论价格如何,定期定额买入固定金额
- 可配置间隔(每小时、每日、每周)
- 长期积累的最低风险策略
LLM增强(适用于所有策略)
- - 每次交易前,向Claude Haiku询问市场情绪
- 评估:近期新闻、价格走势、成交量模式、市场结构
- 若情绪强烈反对,可否决交易信号
交易参数
| 参数 | 默认值 | 描述 |
|---|
| PAIRS | BTCUSDT | 逗号分隔的交易对 |
| STRATEGY |
momentum | momentum、mean_reversion或dca |
| TRADE
SIZEPCT | 5 | 每笔交易占投资组合的百分比 |
| MAX_POSITIONS | 5 | 最大同时持仓数量 |
| TAKE
PROFITPCT | 5 | 止盈百分比 |
| STOP
LOSSPCT | 3 | 止损百分比 |
| DCA_INTERVAL | daily | DCA策略:hourly、daily、weekly |
| DCA
AMOUNTUSDT | 50 | 每次DCA买入的USDT金额 |
| USE_LLM | true | 启用LLM情绪过滤器 |
监控
bash
查看投资组合
python3 {baseDir}/scripts/portfolio.py
查看交易历史
tail -50 trades.jsonl
查看日志
tail -f trader.log
⚠️ 安全注意事项
- - 切勿在API密钥上启用提现功能 — 仅用于交易
- 在Binance上对API密钥进行IP限制
- 使用资金有限的子账户进行机器人交易
- 从小额资金(50-100美元)开始,先进行模拟交易
- 前24小时积极监控
- 为所有交易设置Binance邮件提醒
- API密钥存储在磁盘上 — 确保服务器安全(仅使用SSH密钥、防火墙、chmod 600)
参考
- - 查看references/binance-api.md获取REST API文档
- 查看references/indicators.md获取技术分析详情