support price abnormal monitor

This commit is contained in:
blade 2025-08-21 15:19:41 +08:00
parent 43bd225cfa
commit d397986bad
4 changed files with 38 additions and 13 deletions

View File

@ -56,7 +56,12 @@ def create_metrics_report(
return
volume_ratio = round(float(row["volume_ratio"]), 4)
change = "" if pct_chg > 0 else ""
brief = f"{symbol} {bar} 量率: {volume_ratio} {change}: {pct_chg}%"
price_anomaly = row["price_anomaly"]
if price_anomaly:
brief = f"{symbol} {bar} 量率: {volume_ratio} {change}: {pct_chg}% 异动 价: {close}"
else:
brief = f"{symbol} {bar} 量率: {volume_ratio} {change}: {pct_chg}% 价: {close}"
if huge_volume == 1:
contents.append(f"## {brief} 交易巨量报告")
else:

View File

@ -131,7 +131,7 @@ class MarketMonitorMain:
)
return
realtime_row = real_time_data.iloc[-1]
real_time_data = self.calculate_price_anomaly(real_time_data, realtime_row)
if only_output_huge_volume:
if realtime_row["huge_volume"] == 1:
logger.info(f"监控到巨量: {symbol} {bar} 窗口大小: {self.window_size}")
@ -212,6 +212,22 @@ class MarketMonitorMain:
self.latest_record[symbol][bar]["timestamp"] = latest_realtime_timestamp
with open(self.latest_record_file_path, "w", encoding="utf-8") as f:
json.dump(self.latest_record, f, ensure_ascii=False, indent=4)
def calculate_price_anomaly(self, data: pd.DataFrame, realtime_row: pd.Series):
k = 2
# 计算均值和标准差
data = data.copy()[0:-1]
pct_chg = realtime_row["pct_chg"]
pct_chg_mean = data['pct_chg'].mean()
pct_chg_std = data['pct_chg'].std()
pct_chg_upper_bound = pct_chg_mean + k * pct_chg_std
pct_chg_lower_bound = pct_chg_mean - k * pct_chg_std
if pct_chg > pct_chg_upper_bound or pct_chg < pct_chg_lower_bound:
realtime_row["price_anomaly"] = True
else:
realtime_row["price_anomaly"] = False
return realtime_row
def get_other_realtime_data(
self, symbol: str, bar: str, end_time: int, next: bool = True
@ -270,7 +286,7 @@ if __name__ == "__main__":
market_monitor_main = MarketMonitorMain()
market_monitor_main.monitor_realtime_market(
symbol="PUMP-USDT",
bar="15m",
bar="5m",
only_output_huge_volume=False,
only_output_rise=False,
)

View File

@ -1,24 +1,27 @@
select * from crypto_market_monitor;
select * from crypto_market_monitor
order by date_time desc;
select date_time, open, high, low, close, k_shape from crypto_market_data
WHERE symbol='DOGE-USDT' and bar='5m' and date_time > '2025-08-04 15:00:00'
order by timestamp ;
select symbol, bar, date_time, close,
pct_chg, kdj_k, kdj_d, kdj_k, kdj_pattern,
rsi_14, rsi_signal,
boll_upper, boll_middle, boll_lower, boll_pattern, boll_signal
from crypto_market_data
WHERE close > boll_upper
order by timestamp desc;
select symbol, bar, window_size, date_time, close,
volume, volume_ratio, huge_volume,
close_20_low, low_20_low, close_10_low, low_10_low,
close_80_high, close_90_high, high_80_high, high_90_high
from crypto_huge_volume
WHERE symbol='BTC-USDT' and bar='5m' and window_size=100# and low_10_low=1
order by timestamp;
WHERE symbol='XCH-USDT' and bar='5m' and window_size=120# and low_10_low=1
order by timestamp desc;
select * from crypto_huge_volume
WHERE symbol='XCH-USDT' and bar='5m' #and date_time > '2025-08-04 15:00:00'
order by timestamp asc;
WHERE symbol='BTC-USDT' and bar='5m' #and date_time > '2025-08-04 15:00:00'
order by timestamp DESC;
delete FROM crypto_market_data where symbol != 'XCH-USDT';
select * from crypto_trade_data
where symbol='XCH-USDT'
order by ts desc;
@ -38,4 +41,5 @@ WHERE symbol='BTC-USDT' and bar='5m'
order by timestamp desc
limit 10;
SHOW VARIABLES LIKE 'max_connections';