- ChanPivotClassifier: 提取 calc_duration/contraction/shift 为 @staticmethod,新增 compute_features() - ChanPivotMonitor: 实时追踪当前中枢,bi_count 增长时重新计算 shift/contraction/duration - bsp_monitor/fetcher: 改用 data_provider HTTP API 替代直连 CCXT - bsp_monitor/notify: 新增 send_telegram_message() 通用推送 - bsp_monitor/main: 集成 ChanPivotMonitor,有新笔或 BSP 时推送到 Telegram Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
40 lines
1.0 KiB
Python
40 lines
1.0 KiB
Python
"""
|
|
fetcher.py - 从 data_provider HTTP API 拉取 K 线数据。
|
|
"""
|
|
|
|
import requests
|
|
import pandas as pd
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
SYMBOL = "BTC/USDT:USDT"
|
|
TIMEFRAME = "1m"
|
|
PROVIDER_URL = "http://103.179.242.166"
|
|
FETCH_LIMIT = 1000
|
|
|
|
|
|
def fetch_ohlcv() -> pd.DataFrame:
|
|
"""从 data_provider API 拉取最近 FETCH_LIMIT 根 1m K 线。"""
|
|
url = f"{PROVIDER_URL}/api/candles"
|
|
params = {
|
|
"symbol": SYMBOL,
|
|
"tf": TIMEFRAME,
|
|
"limit": FETCH_LIMIT,
|
|
}
|
|
resp = requests.get(url, params=params, timeout=30)
|
|
resp.raise_for_status()
|
|
data = resp.json()
|
|
|
|
if not data:
|
|
logger.warning("API 返回空数据")
|
|
return pd.DataFrame()
|
|
|
|
df = pd.DataFrame(data)
|
|
df["timestamp"] = pd.to_datetime(df["timestamp"], unit="ms", utc=True)
|
|
df["date"] = df["timestamp"]
|
|
|
|
df = df.drop_duplicates(subset="timestamp").sort_values("timestamp").reset_index(drop=True)
|
|
logger.info(f"拉取 {len(df)} 根 {TIMEFRAME} K 线 from {PROVIDER_URL}")
|
|
return df
|