binance-futures-signal-bot
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBinance Futures Signal Bot
Binance Futures 信号交易机器人
Skill by ara.so — Daily 2026 Skills collection.
Automated trading bot for Binance, Bybit, and OKX Futures markets. Receives signals from Telegram channels, TradingView webhooks, or custom APIs, then executes trades with configurable leverage, dynamic position sizing, trailing stop-loss, and a real-time P&L terminal dashboard.
由ara.so提供的Skill — 2026年度Skill合集。
面向Binance、Bybit和OKX Futures市场的自动化交易机器人,可从Telegram频道、TradingView webhook或自定义API接收信号,随后执行交易,支持可配置杠杆、动态仓位调整、追踪止损以及实时P&L终端仪表盘。
Installation
安装
bash
git clone https://github.com/Whit1985/Binance-Futures-Signal-Bot.git
cd Binance-Futures-Signal-Bot
pip install -r requirements.txtOr via the interactive menu:
bash
python main.py # choose option 1 → Install DependenciesRequired Python: 3.10+
Key dependencies:
| Package | Purpose |
|---|---|
| Terminal UI / dashboards |
| Binance REST & WebSocket |
| Unified multi-exchange interface |
| OHLCV data & indicators |
| Technical analysis (RSI, MACD, BB, EMA) |
| Real-time market streams |
| Secure key storage |
bash
git clone https://github.com/Whit1985/Binance-Futures-Signal-Bot.git
cd Binance-Futures-Signal-Bot
pip install -r requirements.txt或通过交互菜单安装:
bash
python main.py # choose option 1 → Install Dependencies要求Python版本:3.10+
核心依赖:
| 包名 | 用途 |
|---|---|
| 终端UI / 仪表盘 |
| Binance REST & WebSocket 对接 |
| 统一多交易所接口 |
| OHLCV数据与指标计算 |
| 技术分析(RSI, MACD, BB, EMA) |
| 实时市场数据流 |
| 密钥安全存储 |
Quick Start
快速开始
bash
python main.pyInteractive menu options:
1 → Install Dependencies
2 → Settings (API keys, exchange, leverage)
3 → About
4 → Connect Signal Source (Telegram / TradingView / API)
5 → Start Auto Trading
6 → Strategy Configuration
7 → Position Manager (view & close positions)
8 → P&L Dashboard
0 → ExitWindows:
batch
run.batLinux / macOS:
bash
chmod +x run.sh && ./run.shbash
python main.py交互菜单选项:
1 → 安装依赖
2 → 设置(API密钥、交易所、杠杆)
3 → 关于
4 → 连接信号源(Telegram / TradingView / API)
5 → 启动自动交易
6 → 策略配置
7 → 仓位管理器(查看与平仓)
8 → P&L仪表盘
0 → 退出Windows系统:
batch
run.batLinux / macOS系统:
bash
chmod +x run.sh && ./run.shConfiguration
配置
config.json (full reference)
config.json(完整参考)
json
{
"exchange": "binance",
"api_key": "",
"api_secret": "",
"testnet": false,
"leverage": 10,
"max_position_pct": 5.0,
"trailing_stop_pct": 1.5,
"signal_source": "telegram",
"telegram_bot_token": "",
"telegram_channel_id": "-100XXXXXXXXXX",
"tradingview_webhook_port": 8080,
"strategies": {
"ema_crossover": {"enabled": true, "fast": 9, "slow": 21},
"rsi_divergence": {"enabled": true, "period": 14, "overbought": 70, "oversold": 30},
"bollinger_breakout":{"enabled": false, "period": 20, "std_dev": 2.0},
"macd_momentum": {"enabled": true, "fast": 12, "slow": 26, "signal": 9}
},
"pairs": ["BTCUSDT", "ETHUSDT", "SOLUSDT"],
"risk_management": {
"max_open_positions": 5,
"max_daily_loss_pct": 3.0,
"stop_loss_pct": 2.0,
"take_profit_pct": 4.0
}
}json
{
"exchange": "binance",
"api_key": "",
"api_secret": "",
"testnet": false,
"leverage": 10,
"max_position_pct": 5.0,
"trailing_stop_pct": 1.5,
"signal_source": "telegram",
"telegram_bot_token": "",
"telegram_channel_id": "-100XXXXXXXXXX",
"tradingview_webhook_port": 8080,
"strategies": {
"ema_crossover": {"enabled": true, "fast": 9, "slow": 21},
"rsi_divergence": {"enabled": true, "period": 14, "overbought": 70, "oversold": 30},
"bollinger_breakout":{"enabled": false, "period": 20, "std_dev": 2.0},
"macd_momentum": {"enabled": true, "fast": 12, "slow": 26, "signal": 9}
},
"pairs": ["BTCUSDT", "ETHUSDT", "SOLUSDT"],
"risk_management": {
"max_open_positions": 5,
"max_daily_loss_pct": 3.0,
"stop_loss_pct": 2.0,
"take_profit_pct": 4.0
}
}Environment Variables (preferred for secrets)
环境变量(机密信息推荐使用)
bash
export BINANCE_API_KEY="your_api_key_here"
export BINANCE_API_SECRET="your_api_secret_here"
export BYBIT_API_KEY="your_bybit_key"
export BYBIT_API_SECRET="your_bybit_secret"
export OKX_API_KEY="your_okx_key"
export OKX_API_SECRET="your_okx_secret"
export OKX_PASSPHRASE="your_okx_passphrase"
export TELEGRAM_BOT_TOKEN="your_telegram_bot_token"Never commit with real keys — it is d by default.
config.json.gitignorebash
export BINANCE_API_KEY="your_api_key_here"
export BINANCE_API_SECRET="your_api_secret_here"
export BYBIT_API_KEY="your_bybit_key"
export BYBIT_API_SECRET="your_bybit_secret"
export OKX_API_KEY="your_okx_key"
export OKX_API_SECRET="your_okx_secret"
export OKX_PASSPHRASE="your_okx_passphrase"
export TELEGRAM_BOT_TOKEN="your_telegram_bot_token"切勿提交包含真实密钥的——默认已将该文件加入。
config.json.gitignoreExchange Setup
交易所设置
Binance Futures
Binance Futures
python
undefinedpython
undefinedconfig.py usage pattern
config.py usage pattern
import os
import json
config = {
"exchange": "binance",
"api_key": os.environ.get("BINANCE_API_KEY"),
"api_secret": os.environ.get("BINANCE_API_SECRET"),
"testnet": True, # always test first
"leverage": 5,
"pairs": ["BTCUSDT", "ETHUSDT"]
}
with open("config.json", "w") as f:
json.dump(config, f, indent=2)
undefinedimport os
import json
config = {
"exchange": "binance",
"api_key": os.environ.get("BINANCE_API_KEY"),
"api_secret": os.environ.get("BINANCE_API_SECRET"),
"testnet": True, # always test first
"leverage": 5,
"pairs": ["BTCUSDT", "ETHUSDT"]
}
with open("config.json", "w") as f:
json.dump(config, f, indent=2)
undefinedBybit Perpetual
Bybit 永续合约
json
{
"exchange": "bybit",
"api_key": "",
"api_secret": "",
"leverage": 5,
"pairs": ["BTCUSDT", "ETHUSDT"]
}json
{
"exchange": "bybit",
"api_key": "",
"api_secret": "",
"leverage": 5,
"pairs": ["BTCUSDT", "ETHUSDT"]
}OKX Perpetual Swap
OKX 永续合约
json
{
"exchange": "okx",
"api_key": "",
"api_secret": "",
"okx_passphrase": "",
"leverage": 5,
"pairs": ["BTC-USDT-SWAP", "ETH-USDT-SWAP"]
}json
{
"exchange": "okx",
"api_key": "",
"api_secret": "",
"okx_passphrase": "",
"leverage": 5,
"pairs": ["BTC-USDT-SWAP", "ETH-USDT-SWAP"]
}Signal Sources
信号源
1. Telegram Channel
1. Telegram 频道
python
undefinedpython
undefinedSetup steps:
设置步骤:
1. Create bot at https://t.me/BotFather → get token
1. 在https://t.me/BotFather 创建机器人获取token
2. Add bot to signal channel as admin
2. 将机器人作为管理员添加到信号频道
3. Get channel ID (negative number starting with -100)
3. 获取频道ID(以-100开头的负数)
config_snippet = {
"signal_source": "telegram",
"telegram_bot_token": os.environ.get("TELEGRAM_BOT_TOKEN"),
"telegram_channel_id": "-1001234567890"
}
undefinedconfig_snippet = {
"signal_source": "telegram",
"telegram_bot_token": os.environ.get("TELEGRAM_BOT_TOKEN"),
"telegram_channel_id": "-1001234567890"
}
undefined2. TradingView Webhook
2. TradingView Webhook
json
{
"signal_source": "tradingview",
"tradingview_webhook_port": 8080
}TradingView alert message format (JSON):
json
{
"symbol": "BTCUSDT",
"side": "BUY",
"leverage": 10,
"price": "{{close}}",
"strategy": "ema_crossover"
}Point your TradingView alert webhook URL to:
http://YOUR_SERVER_IP:8080/webhookjson
{
"signal_source": "tradingview",
"tradingview_webhook_port": 8080
}TradingView告警消息格式(JSON):
json
{
"symbol": "BTCUSDT",
"side": "BUY",
"leverage": 10,
"price": "{{close}}",
"strategy": "ema_crossover"
}将你的TradingView告警webhook URL设置为:
http://YOUR_SERVER_IP:8080/webhook3. Custom API Signal Source
3. 自定义API信号源
json
{
"signal_source": "api",
"custom_api_url": "https://your-signal-provider.com/signals",
"custom_api_key": ""
}json
{
"signal_source": "api",
"custom_api_url": "https://your-signal-provider.com/signals",
"custom_api_key": ""
}Strategies
策略
EMA Crossover
EMA Crossover
json
{
"ema_crossover": {
"enabled": true,
"fast": 9,
"slow": 21
}
}- LONG: fast EMA crosses above slow EMA
- SHORT: fast EMA crosses below slow EMA
- Best timeframes: 15m, 1h, 4h
json
{
"ema_crossover": {
"enabled": true,
"fast": 9,
"slow": 21
}
}- 做多:快速EMA上穿慢速EMA
- 做空:快速EMA下穿慢速EMA
- 最佳时间周期:15m, 1h, 4h
RSI Divergence
RSI Divergence
json
{
"rsi_divergence": {
"enabled": true,
"period": 14,
"overbought": 70,
"oversold": 30
}
}- Bullish: price lower lows + RSI higher lows → LONG
- Bearish: price higher highs + RSI lower highs → SHORT
json
{
"rsi_divergence": {
"enabled": true,
"period": 14,
"overbought": 70,
"oversold": 30
}
}- 看涨:价格新低 + RSI更高低点 → 做多
- 看跌:价格新高 + RSI更低高点 → 做空
Bollinger Band Breakout
Bollinger Band Breakout
json
{
"bollinger_breakout": {
"enabled": true,
"period": 20,
"std_dev": 2.0
}
}- LONG: close above upper band
- SHORT: close below lower band
json
{
"bollinger_breakout": {
"enabled": true,
"period": 20,
"std_dev": 2.0
}
}- 做多:收盘价上穿布林带上轨
- 做空:收盘价下穿布林带下轨
MACD Momentum
MACD Momentum
json
{
"macd_momentum": {
"enabled": true,
"fast": 12,
"slow": 26,
"signal": 9
}
}- Trades histogram crossovers with signal line confirmation
- Zero-line acts as trend filter
json
{
"macd_momentum": {
"enabled": true,
"fast": 12,
"slow": 26,
"signal": 9
}
}- 根据直方图与信号线交叉确认交易信号
- 零轴作为趋势过滤器
Running Multiple Strategies
运行多策略
All enabled strategies run per candle. The bot takes the highest-confidence signal and filters conflicts:
json
{
"strategies": {
"ema_crossover": {"enabled": true, "fast": 9, "slow": 21},
"rsi_divergence": {"enabled": true, "period": 14},
"bollinger_breakout": {"enabled": false},
"macd_momentum": {"enabled": true}
}
}所有启用的策略会按K线周期运行,机器人会选取置信度最高的信号并过滤冲突信号:
json
{
"strategies": {
"ema_crossover": {"enabled": true, "fast": 9, "slow": 21},
"rsi_divergence": {"enabled": true, "period": 14},
"bollinger_breakout": {"enabled": false},
"macd_momentum": {"enabled": true}
}
}Risk Management
风险管理
json
{
"leverage": 10,
"max_position_pct": 5.0,
"trailing_stop_pct": 1.5,
"risk_management": {
"max_open_positions": 5,
"max_daily_loss_pct": 3.0,
"stop_loss_pct": 2.0,
"take_profit_pct": 4.0
}
}| Parameter | Description |
|---|---|
| 1x–125x (start with 2–5x) |
| % of account balance per trade |
| Trailing SL activates after price moves this % in profit |
| Hard cap on concurrent open trades |
| Bot halts trading if daily loss exceeds this |
| Fixed stop-loss distance from entry |
| Fixed take-profit distance from entry |
Trailing stop-loss behavior: Once position is in profit by , the stop follows the peak price. Position closes automatically on reversal of that distance.
trailing_stop_pctjson
{
"leverage": 10,
"max_position_pct": 5.0,
"trailing_stop_pct": 1.5,
"risk_management": {
"max_open_positions": 5,
"max_daily_loss_pct": 3.0,
"stop_loss_pct": 2.0,
"take_profit_pct": 4.0
}
}| 参数 | 说明 |
|---|---|
| 1x–125x(建议初始使用2–5x) |
| 单次交易占账户余额的百分比 |
| 价格盈利达到该百分比后激活追踪止损 |
| 同时持仓的最大数量上限 |
| 当日亏损超过该值后机器人停止交易 |
| 固定止损距离入场价的百分比 |
| 固定止盈距离入场价的百分比 |
追踪止损规则: 当仓位盈利达到后,止损价会跟随最高价调整,当价格回落达到该百分比时仓位自动平仓。
trailing_stop_pctTestnet Mode
测试网模式
Always validate on testnet before live trading:
json
{
"testnet": true,
"exchange": "binance"
}实盘交易前务必先在测试网验证:
json
{
"testnet": true,
"exchange": "binance"
}Project Structure
项目结构
Binance-Futures-Signal-Bot/
├── main.py # Entry point — interactive menu
├── bot_actions.py # Core trading action handlers
├── config.py # Configuration loader (JSON + env vars)
├── requirements.txt
├── run.bat / run.sh # Platform launchers
├── actions/
│ ├── about.py # Feature display
│ ├── install.py # Dependency installer
│ └── settings.py # Configuration UI
├── utils/
│ ├── __init__.py # Environment bootstrap
│ ├── compat.py # Platform compatibility
│ ├── ui.py # Rich terminal interface
│ ├── http.py # HTTP client
│ ├── integrity.py # Data integrity checks
│ └── bootstrap.py # Runtime initialization
└── release/
└── README.md # Pre-compiled binary infoBinance-Futures-Signal-Bot/
├── main.py # 入口文件——交互菜单
├── bot_actions.py # 核心交易操作处理器
├── config.py # 配置加载器(JSON + 环境变量)
├── requirements.txt
├── run.bat / run.sh # 各平台启动脚本
├── actions/
│ ├── about.py # 功能展示
│ ├── install.py # 依赖安装器
│ └── settings.py # 配置UI
├── utils/
│ ├── __init__.py # 环境初始化
│ ├── compat.py # 平台兼容性处理
│ ├── ui.py # Rich终端界面
│ ├── http.py # HTTP客户端
│ ├── integrity.py # 数据完整性校验
│ └── bootstrap.py # 运行时初始化
└── release/
└── README.md # 预编译二进制文件说明Common Patterns
常用用法
Load Config Programmatically
程序式加载配置
python
import json
import os
def load_config(path="config.json"):
with open(path) as f:
cfg = json.load(f)
# Override with env vars if set
cfg["api_key"] = os.environ.get("BINANCE_API_KEY", cfg.get("api_key", ""))
cfg["api_secret"] = os.environ.get("BINANCE_API_SECRET", cfg.get("api_secret", ""))
return cfg
config = load_config()python
import json
import os
def load_config(path="config.json"):
with open(path) as f:
cfg = json.load(f)
# Override with env vars if set
cfg["api_key"] = os.environ.get("BINANCE_API_KEY", cfg.get("api_key", ""))
cfg["api_secret"] = os.environ.get("BINANCE_API_SECRET", cfg.get("api_secret", ""))
return cfg
config = load_config()Minimal Safe Config for Testing
测试用最小安全配置
python
import json
safe_config = {
"exchange": "binance",
"api_key": "", # set via env var BINANCE_API_KEY
"api_secret": "", # set via env var BINANCE_API_SECRET
"testnet": True,
"leverage": 2,
"max_position_pct": 1.0,
"signal_source": "telegram",
"telegram_bot_token": "", # set via env var TELEGRAM_BOT_TOKEN
"telegram_channel_id": "",
"strategies": {
"ema_crossover": {"enabled": True, "fast": 9, "slow": 21},
"rsi_divergence": {"enabled": False},
"bollinger_breakout": {"enabled": False},
"macd_momentum": {"enabled": False}
},
"pairs": ["BTCUSDT"],
"risk_management": {
"max_open_positions": 1,
"max_daily_loss_pct": 1.0,
"stop_loss_pct": 1.5,
"take_profit_pct": 3.0
}
}
with open("config.json", "w") as f:
json.dump(safe_config, f, indent=2)python
import json
safe_config = {
"exchange": "binance",
"api_key": "", # set via env var BINANCE_API_KEY
"api_secret": "", # set via env var BINANCE_API_SECRET
"testnet": True,
"leverage": 2,
"max_position_pct": 1.0,
"signal_source": "telegram",
"telegram_bot_token": "", # set via env var TELEGRAM_BOT_TOKEN
"telegram_channel_id": "",
"strategies": {
"ema_crossover": {"enabled": True, "fast": 9, "slow": 21},
"rsi_divergence": {"enabled": False},
"bollinger_breakout": {"enabled": False},
"macd_momentum": {"enabled": False}
},
"pairs": ["BTCUSDT"],
"risk_management": {
"max_open_positions": 1,
"max_daily_loss_pct": 1.0,
"stop_loss_pct": 1.5,
"take_profit_pct": 3.0
}
}
with open("config.json", "w") as f:
json.dump(safe_config, f, indent=2)Verify Installation
验证安装
python
undefinedpython
undefinedQuick dependency check
Quick dependency check
required = ["rich", "binance", "ccxt", "pandas", "ta", "websockets", "cryptography"]
import importlib
for pkg in required:
try:
importlib.import_module(pkg)
print(f"✓ {pkg}")
except ImportError:
print(f"✗ {pkg} — run: pip install {pkg}")
---required = ["rich", "binance", "ccxt", "pandas", "ta", "websockets", "cryptography"]
import importlib
for pkg in required:
try:
importlib.import_module(pkg)
print(f"✓ {pkg}")
except ImportError:
print(f"✗ {pkg} — run: pip install {pkg}")
---Troubleshooting
问题排查
Bot won't connect to exchange
机器人无法连接交易所
bash
undefinedbash
undefinedCheck API key permissions — must have:
检查API密钥权限——必须开启:
Binance: Enable Futures, Enable Reading, Enable Spot & Margin Trading
Binance:启用期货、启用读取权限、启用现货与杠杆交易
Bybit: Unified Trading, Read/Write
Bybit:统一交易、读写权限
OKX: Trade, Read
OKX:交易、读取权限
Test connectivity
测试连接
python -c "
import ccxt, os
exchange = ccxt.binance({
'apiKey': os.environ['BINANCE_API_KEY'],
'secret': os.environ['BINANCE_API_SECRET'],
'options': {'defaultType': 'future'}
})
print(exchange.fetch_balance())
"
undefinedpython -c "
import ccxt, os
exchange = ccxt.binance({
'apiKey': os.environ['BINANCE_API_KEY'],
'secret': os.environ['BINANCE_API_SECRET'],
'options': {'defaultType': 'future'}
})
print(exchange.fetch_balance())
"
undefinedTelegram signals not received
收不到Telegram信号
- Confirm bot is admin in the channel
- Verify starts with
telegram_channel_id-100 - Send a test message to the channel after adding the bot
- Check bot token with:
https://api.telegram.org/bot<TOKEN>/getMe
- 确认机器人是频道的管理员
- 验证以
telegram_channel_id开头-100 - 添加机器人后向频道发送一条测试消息
- 通过该链接校验bot token:
https://api.telegram.org/bot<TOKEN>/getMe
TradingView webhook not triggering
TradingView webhook不触发
bash
undefinedbash
undefinedEnsure port 8080 is open and accessible
确保8080端口开放可访问
Check firewall rules
检查防火墙规则
sudo ufw allow 8080/tcp
sudo ufw allow 8080/tcp
Test webhook endpoint locally
本地测试webhook端点
curl -X POST http://localhost:8080/webhook
-H "Content-Type: application/json"
-d '{"symbol":"BTCUSDT","side":"BUY","leverage":5}'
-H "Content-Type: application/json"
-d '{"symbol":"BTCUSDT","side":"BUY","leverage":5}'
undefinedcurl -X POST http://localhost:8080/webhook
-H "Content-Type: application/json"
-d '{"symbol":"BTCUSDT","side":"BUY","leverage":5}'
-H "Content-Type: application/json"
-d '{"symbol":"BTCUSDT","side":"BUY","leverage":5}'
undefinedLeverage rejected by exchange
交易所拒绝杠杆设置
- Binance max leverage varies per symbol (BTC: 125x, altcoins: lower)
- Bybit requires setting leverage per symbol before trading
- Start with and increase carefully
"leverage": 5
- Binance不同币种的最大杠杆不同(BTC: 125x,山寨币更低)
- Bybit要求交易前为每个币种单独设置杠杆
- 初始使用,后续谨慎调高
"leverage": 5
ImportError on startup
启动时出现ImportError
bash
pip install --upgrade -r requirements.txtbash
pip install --upgrade -r requirements.txtor individually:
或单独安装:
pip install rich>=13.0.0 python-binance>=1.0.19 ccxt>=4.2.0 pandas>=2.1.0 ta>=0.10.2 websockets>=12.0 cryptography
undefinedpip install rich>=13.0.0 python-binance>=1.0.19 ccxt>=4.2.0 pandas>=2.1.0 ta>=0.10.2 websockets>=12.0 cryptography
undefinedPosition not closing at stop-loss
仓位未在止损价平仓
- Ensure is set in
stop_loss_pctrisk_management - Trailing stop only activates after initial profit threshold ()
trailing_stop_pct - Check exchange order type support — some altcoin pairs have restrictions
- 确认中已设置
risk_managementstop_loss_pct - 追踪止损仅在初始盈利达到阈值后激活
trailing_stop_pct - 检查交易所订单类型支持——部分山寨币交易对有限制
Safety Checklist
安全检查清单
- Always run first
"testnet": true - Start with or
"leverage": 23 - Set ≤ 3.0
max_daily_loss_pct - Keep ≤ 3 initially
max_open_positions - Never commit with real API keys
config.json - Use environment variables for all secrets
- Keep API key IP-restricted on exchange side
- Enable only one strategy initially; add more after validation
- 务必先开启运行测试
"testnet": true - 初始使用或
"leverage": 23 - 设置≤ 3.0
max_daily_loss_pct - 初期保持≤ 3
max_open_positions - 切勿提交包含真实API密钥的
config.json - 所有机密信息使用环境变量存储
- 在交易所侧为API密钥设置IP白名单
- 初始仅启用一个策略,验证通过后再添加更多
Disclaimer
免责声明
This software is for educational and research purposes only. Cryptocurrency futures trading involves substantial risk of loss including full account liquidation. The authors bear no responsibility for financial losses from use of this software.
本软件仅用于教育和研究目的。加密货币期货交易存在巨大亏损风险,包括账户全额爆仓。开发者不对使用本软件造成的任何财务损失承担责任。