📊 비트코인 자동매매 시스템 — Full Guide
📌 1. 개요
이 시스템은 단순 매매 봇이 아니라
데이터 기반 의사결정 + 자동 실행 + 모니터링까지 포함된 플랫폼이다.
핵심 목표:
- 자동화된 의사결정
- 리스크 최소화
- 실시간 상태 가시화
- 안정적인 실행 구조
🧱 2. 전체 아키텍처
code snippet
graph TD
A[Price Writer] --> B[Stage2 Technical]
B --> C[Stage3 News]
C --> D[Stage4 Decision]
D --> E[Order Sender]
E --> F[Exchange API]
F --> G[Positions DB]
⚙️ 3. 데이터 수집 (Stage1)
code snippet
import ccxt
import time
exchange = ccxt.upbit()
def fetch_price(symbol="BTC/KRW"):
ticker = exchange.fetch_ticker(symbol)
return {
"price": ticker["last"],
"volume": ticker["baseVolume"],
"timestamp": ticker["timestamp"]
}
while True:
data = fetch_price()
print(data)
time.sleep(60)
📈 4. 기술 분석 (Stage2)
주요 지표
- EMA (20, 50)
- RSI
- Volume Spike
code snippet
import pandas as pd
def compute_indicators(df):
df["ema20"] = df["close"].ewm(span=20).mean()
df["ema50"] = df["close"].ewm(span=50).mean()
delta = df["close"].diff()
gain = delta.clip(lower=0).rolling(14).mean()
loss = -delta.clip(upper=0).rolling(14).mean()
rs = gain / loss
df["rsi"] = 100 - (100 / (1 + rs))
return df
📰 5. 뉴스 분석 (Stage3)
code snippet
def analyze_news(news_list):
score = 0
for news in news_list:
if "hack" in news.lower():
score -= 2
elif "etf" in news.lower():
score += 2
return score
🧠 6. 최종 의사결정 (Stage4)
code snippet
function calculateFinalScore(stage2, stage3) {
return stage2.score * 0.7 + stage3.score * 0.3;
}
function decide(score) {
if (score > 3) return "BUY";
if (score < -3) return "SELL";
return "HOLD";
}
🛡️ 7. 리스크 관리
| 항목 | 값 |
|---|---|
| 최대 포지션 | 50% |
| 손절 | -3% |
| 익절 | +5% |
| 슬리피지 | 0.1% |
code snippet
def risk_check(pnl_pct):
if pnl_pct < -3:
return "STOP_LOSS"
elif pnl_pct > 5:
return "TAKE_PROFIT"
return "HOLD"
🧾 8. 주문 실행
code snippet
def send_order(side, amount):
print(f"[ORDER] {side} {amount}")
# 실제 API 호출 부분
📊 9. 대시보드 구성
- CPU / Memory / Disk
- 현재 포지션
- PnL
- 파이프라인 상태
- 뉴스 영향
🔍 10. 로그 & 모니터링
code snippet
pm2 logs homepage
pm2 list
🚀 11. 배포 및 운영
code snippet
npm run build
pm2 restart homepage
📌 12. 결론
이 시스템은 단순 봇이 아니라
자동화된 트레이딩 플랫폼이다.
향후 개선 방향:
- AI 의사결정
- 자동 포지션 sizing
- 고급 리스크 관리
