| Demo 2 Phút — Bot Python Lấy Binance OHLCV & Tính RSI (Preview Buổi 03 Khóa Vibe Code)

Được viết bởi thanhdt vào ngày 14/06/2026 lúc 20:15 | 35 lượt xem

Đây là demo preview Buổi 03 khóa Vibe Code Python Bot Auto Trading (khai giảng 07/2026): từ zero đến bot lấy giá Binance, tính RSI, in tín hiệu — không khoe lời nhuận, chỉ minh họa pipeline chuẩn.

Pipeline buổi học:

Thu thập dữ liệu → Tính chỉ báo → Sinh tín hiệu → (sau này) Risk → Execution


Kết quả chạy thử (minh họa)

=======================================================
  Demo: Binance OHLCV → RSI | BTCUSDT 1h
=======================================================

[2026-06-14 12:00 UTC]
  Close : 67,xxx.xx USDT
  RSI(14): 52.34
  Signal: NEUTRAL

  (Minh họa giáo dục — không phải khuyến nghị giao dịch)

Số liệu thay đổi theo thời điểm chạy script — đây là dữ liệu thị trường thật, không phải backtest lợi nhuận.


Bước 1 — Lấy OHLCV từ Binance (public API)

Endpoint GET /api/v3/klines không cần API key cho dữ liệu công khai.

import pandas as pd
import requests

def fetch_ohlcv(symbol="BTCUSDT", interval="1h", limit=100):
    url = "https://api.binance.com/api/v3/klines"
    params = {"symbol": symbol, "interval": interval, "limit": limit}
    rows = requests.get(url, params=params, timeout=15).json()
    df = pd.DataFrame(rows, columns=[
        "open_time", "open", "high", "low", "close", "volume",
        "close_time", "quote_volume", "trades",
        "taker_buy_base", "taker_buy_quote", "ignore",
    ])
    df["open_time"] = pd.to_datetime(df["open_time"], unit="ms", utc=True)
    for col in ("open", "high", "low", "close", "volume"):
        df[col] = df[col].astype(float)
    return df

Buổi 03 mở rộng: WebSocket realtime, rate limit, .env bảo mật API key khi đặt lệnh.


Bước 2 — Tính RSI(14)

def calc_rsi(close, period=14):
    delta = close.diff()
    gain = delta.clip(lower=0)
    loss = -delta.clip(upper=0)
    avg_gain = gain.ewm(alpha=1/period, min_periods=period, adjust=False).mean()
    avg_loss = loss.ewm(alpha=1/period, min_periods=period, adjust=False).mean()
    rs = avg_gain / avg_loss.replace(0, pd.NA)
    return 100 - (100 / (1 + rs))

Khóa học cũng dạy tự code MA, MACD — không phụ thuộc TradingView.


Bước 3 — Log tín hiệu (chưa đặt lệnh)

def signal_from_rsi(rsi, oversold=30, overbought=70):
    if rsi < oversold:
        return "OVERSOLD (watchlist)"
    if rsi > overbought:
        return "OVERBOUGHT (watchlist)"
    return "NEUTRAL"

df = fetch_ohlcv()
df["rsi"] = calc_rsi(df["close"])
last = df.iloc[-1]
print(last["close"], last["rsi"], signal_from_rsi(last["rsi"]))

⚠️ Tín hiệu RSI ≠ lệnh mua/bán. Buổi 08 dạy position sizing; Buổi 10 backtest trước khi live.


Chạy full script trên máy bạn

Yêu cầu: Python 3.9+ · pip install requests pandas

File demo: 16. Website/demo_binance_ohlcv_rsi.py

python demo_binance_ohlcv_rsi.py

Output: giá đóng cửa, RSI, tín hiệu + bảng 5 nến gần nhất.


Demo này nằm ở đâu trong Roadmap 19 buổi?

Buổi Nội dung liên quan
03 API Binance · OHLCV · bot lấy data realtime
04 MA, RSI, MACD — chỉ báo tự code
06 Bot RSI oversold/overbought có filter
10 Backtest — đánh giá chiến lược trên lịch sử

📖 Roadmap 19 buổi chi tiết


Webinar miễn phí — cùng chủ đề (45 phút)

Khóa sẽ có webinar live Buổi 3: “Từ zero đến bot lấy data Binance” — mở rộng demo này thành vòng lặp bot + Q&A.

Outline: pain point trade tay → REST API → live code OHLCV → log realtime → CTA syllabus 24 buổi.


Lưu ý minh bạch

  • Demo dùng dữ liệu công khai — không cam kết lợi nhuận.
  • Khóa không bán tín hiệu — dạy hệ thống: Signal → Execution → Risk → Monitoring.
  • API key chỉ cần khi đặt lệnh thật — học viên dùng testnet/demo trước.

Đăng ký tư vấn — Khai giảng 07/2026

👉 Khóa Vibe Code Python Bot Auto Trading

💬 Comment PYTHON hoặc API — nhận syllabus + file demo.

📖 Xem thêm: FAQ 10 câu · 5 ưu điểm khóa

Trung tâm Hướng Nghiệp Dữ Liệu — Đào tạo Bot Auto Trading · Quant · Vibe Code thực chiến.