量化工具棧:Binance API + Grafana + 自動化告警全套配置

跑一個量化策略需要的不只是策略本身——還需要一套支撐它執行、監控它狀態、在出問題時及時告警的工具鏈。這篇文章分享我的完整工具棧,從策略執行到告警通知。 整體架構 策略層(Python) ↓ 交易指令 Binance API ↓ 執行結果 狀態檔案 / CF KV ↓ 指標 Prometheus + node_exporter ↓ 儲存 Grafana 視覺化 ↓ 告警規則 Alertmanager → Telegram 策略執行層 技術棧 語言:Python 3.11 Binance SDK:python-binance 定時任務:APScheduler 或系統 cron 依賴管理:requirements.txt + venv 目錄結構 quant/ ├── strategy/ │ ├── main.py # 主策略邏輯(訊號生成 + 下單) │ ├── signals.py # 指標計算(技術指標庫) │ └── risk.py # 倉位管理、止損邏輯 ├── exchange/ │ └── binance_client.py # Binance API 封裝 ├── monitor/ │ └── exporter.py # 狀態指標寫入 Prometheus 格式 ├── config/ │ └── settings.py # 配置(從環境變數讀取) └── run.py # 入口 關鍵程式碼:狀態指標暴露 策略執行時,把關鍵指標寫成 Prometheus textfile 格式,供 node_exporter 抓取: ...

2026-04-15 · 3 min · 520 words · 磐石

Prometheus + Grafana 監控 VPS:從零搭建伺服器監控系統

跑著量化策略和代理節點的伺服器,沒有監控是非常危險的。凌晨記憶體爆了、磁碟滿了、策略掛了——如果沒有告警,可能幾個小時後才發現。 這篇文章從零開始,搭建一套完整的監控系統:被監控機器上跑 Node Exporter 採集指標,Prometheus 收集儲存,Grafana 視覺化展示,加上 Telegram 告警。 架構說明 被監控 VPS(N臺) 監控中心 VPS(1臺) ┌──────────────┐ ┌─────────────────────┐ │ Node Exporter │ ──9100→ │ Prometheus(採集) │ │ Node Exporter │ ──9100→ │ Grafana(展示) │ │ Node Exporter │ ──9100→ │ Alertmanager(告警) │ └──────────────┘ └─────────────────────┘ 我的做法:一臺小 VPS(1核1G 足夠)作為監控中心,其他機器裝 Node Exporter 暴露指標。 第一步:在被監控機器上安裝 Node Exporter 每臺要監控的 VPS 都要做這一步。 # 下載 Node Exporter(確認最新版本號) cd /tmp wget https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gz tar xzf node_exporter-1.8.2.linux-amd64.tar.gz mv node_exporter-1.8.2.linux-amd64/node_exporter /usr/local/bin/ 建立 systemd 服務: ...

2026-04-10 · 4 min · 718 words · 磐石