-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_btc_bot.py
More file actions
95 lines (76 loc) · 2.82 KB
/
run_btc_bot.py
File metadata and controls
95 lines (76 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""
Eagle BTC Bot — Entry Point
============================
Run this script to start the real-time Bitcoin trading bot.
Usage:
python run_btc_bot.py
python run_btc_bot.py --capital 5000 # start with $5,000 paper capital
The bot will:
• Fetch 200 historical 1-minute candles from Binance (no API key needed)
• Connect to Binance's live WebSocket stream for BTC/USDT
• Compute RSI, MACD, Bollinger Bands, and EMA indicators in real time
• Run 4 strategies and aggregate their signals into a single recommendation
• Paper-trade the best signal automatically
• Display a live dashboard in your terminal
Press Ctrl+C to stop cleanly.
"""
from __future__ import annotations
import argparse
import asyncio
import logging
import sys
# Force UTF-8 on Windows so Rich emoji render correctly
if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
if hasattr(sys.stderr, "reconfigure"):
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
def _parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
prog="run_btc_bot",
description="Eagle real-time BTC/USDT paper trading bot",
)
parser.add_argument(
"--capital",
type=float,
default=10_000.0,
metavar="USD",
help="Starting paper capital in USD (default: 10000)",
)
parser.add_argument(
"--log-level",
default="WARNING",
choices=["DEBUG", "INFO", "WARNING", "ERROR"],
help="Log level (default: WARNING — keeps terminal clean)",
)
parser.add_argument(
"--log-file",
default="logs/eagle_btc.log",
metavar="PATH",
help="Write logs to this file (default: logs/eagle_btc.log)",
)
return parser.parse_args()
def _setup_logging(level: str, log_file: str) -> None:
import os
os.makedirs(os.path.dirname(log_file), exist_ok=True)
fmt = "%(asctime)s %(levelname)-8s %(name)s — %(message)s"
handlers: list[logging.Handler] = [logging.FileHandler(log_file, encoding="utf-8")]
# Only add console handler for DEBUG — dashboard takes over the screen
if level == "DEBUG":
handlers.append(logging.StreamHandler(sys.stdout))
logging.basicConfig(level=level, format=fmt, handlers=handlers)
async def _main(capital: float) -> None:
from eagle.btc_bot import BTCBot
bot = BTCBot(initial_cash=capital, refresh_rate=2.0)
try:
await bot.run()
except KeyboardInterrupt:
pass
if __name__ == "__main__":
args = _parse_args()
_setup_logging(args.log_level, args.log_file)
print(f"\n Starting Eagle BTC Bot | capital: ${args.capital:,.0f} USD")
print(" Press Ctrl+C to stop\n")
try:
asyncio.run(_main(args.capital))
except KeyboardInterrupt:
print("\n\n Bot stopped. Goodbye.\n")