잠시 욕망에 빠져서 비트코인 자동매매 봇을 만들었다.
업비트 API 붙이고 RSI / 볼린저밴드 기반으로 자동매매.
프로젝트.
0027-bitcoin-trading-bot
구조.
src/core/config.py
src/core/exchange.py
src/core/logger.py
src/strategies/rsi_bb.py
src/strategies/ma_cross.py
src/backtesting/backtest.py
src/trading/bot.py
src/trading/order.py
src/trading/risk.py
src/trading/limit_enforcer.py
src/core/prometheus_exporter.py
전략.
RSI + 볼린저밴드.
매수 조건.
RSI(14) < 30
현재가 < 볼린저밴드 하단
보유 비트코인 없음
일일 손실 < 3,000원
매도 조건.
수익률 >= +1.0%
손실률 <= -0.5%
실행.
pip install -r requirements.txt
python src/main.py --mode backtest --days 90
python src/main.py --mode live
Docker 실행.
cd docker
docker-compose up -d
Prometheus exporter 추가.
src/core/prometheus_exporter.py
from prometheus_client import Gauge, start_http_server, CollectorRegistry
realized_profit_gauge = Gauge('bitcoin_realized_profit_krw', 'Realized Profit KRW (거래 수익)', registry=global_registry)
unrealized_profit_gauge = Gauge('bitcoin_unrealized_profit_krw', 'Unrealized Profit KRW (보유 평가손익)', registry=global_registry)
profit_gauge = Gauge('bitcoin_profit_krw', 'Total Profit KRW (실현+미실현)', registry=global_registry)
profit_pct_gauge = Gauge('bitcoin_profit_pct', 'Total Profit Percentage', registry=global_registry)
realized_profit_pct_gauge = Gauge('bitcoin_realized_profit_pct', 'Realized Profit Percentage', registry=global_registry)
unrealized_profit_pct_gauge = Gauge('bitcoin_unrealized_profit_pct', 'Unrealized Profit Percentage', registry=global_registry)
win_rate_gauge = Gauge('bitcoin_win_rate', 'Win Rate Percentage', registry=global_registry)
rsi_btc = Gauge('bitcoin_rsi_btc', 'BTC Current RSI', registry=global_registry)
rsi_eth = Gauge('bitcoin_rsi_eth', 'ETH Current RSI', registry=global_registry)
price_btc = Gauge('bitcoin_price_btc', 'BTC Current Price', registry=global_registry)
price_eth = Gauge('bitcoin_price_eth', 'ETH Current Price', registry=global_registry)
balance_krw = Gauge('bitcoin_balance_krw', 'Current KRW Balance', registry=global_registry)
balance_btc = Gauge('bitcoin_balance_btc', 'Current BTC Balance', registry=global_registry)
balance_eth = Gauge('bitcoin_balance_eth', 'Current ETH Balance', registry=global_registry)
total_asset = Gauge('bitcoin_total_asset', 'Total Asset Value (KRW)', registry=global_registry)
asset_value_btc = Gauge('bitcoin_asset_value_btc', 'BTC Asset Value (KRW)', registry=global_registry)
asset_value_eth = Gauge('bitcoin_asset_value_eth', 'ETH Asset Value (KRW)', registry=global_registry)
invested_btc = Gauge('bitcoin_invested_btc', 'BTC Invested Amount (KRW)', registry=global_registry)
invested_eth = Gauge('bitcoin_invested_eth', 'ETH Invested Amount (KRW)', registry=global_registry)
initial_capital = Gauge('bitcoin_initial_capital', 'Initial Capital (KRW)', registry=global_registry)
last_update = Gauge('bitcoin_last_update_timestamp', 'Last Update Unix Timestamp', registry=global_registry)
main.py에서 exporter 실행.
from src.core.prometheus_exporter import start_exporter, refresh_metrics
Grafana 대시보드 구성.
총자산
원 잔액
비트코인 평가금액
이더리움 평가금액
총손익
승률
BTC RSI
ETH RSI
자산 구성 추이
RSI 추이
누적 손익 추이
수익률 추이
갱신 주기.
30초.
당시 상태.
총자산:
49.84만원
원 잔액:
29.60만원
비트코인:
0.00만원
이더리움:
20.24만원
손익:
+0.05만원
수익률:
+0.22%
승률:
50%
현재 보유:
이더리움
RSI 예시.
BTC:
47.3 -> 29.9 -> 25.7 -> 38.9 -> 35.3
ETH:
43.3 -> 35.1 -> 33.3 -> 41.5 -> 37.1
Git 기록.
2026-02-21 13:13
손익 추적 및 일일/월간 리포트 시스템 추가
2026-02-21 13:21
BTC/ETH 코인별 통계 추가
2026-02-21 14:05
Prometheus 메트릭 익스포터 추가
2026-02-21 14:25
현재 자산 정보 Prometheus 메트릭 추가
나중에 운영 중단.
2026-02-28
비트코인 봇 운영 중단
최종 결과는 별로였음.
그래도 Prometheus / Grafana 붙여서 봇 상태를 보는 구조는 만들었다.