diff --git a/core/biz/__pycache__/market_data.cpython-312.pyc b/core/biz/__pycache__/market_data.cpython-312.pyc index 8ab8bbe..b6b8bfc 100644 Binary files a/core/biz/__pycache__/market_data.cpython-312.pyc and b/core/biz/__pycache__/market_data.cpython-312.pyc differ diff --git a/core/biz/__pycache__/market_monitor.cpython-312.pyc b/core/biz/__pycache__/market_monitor.cpython-312.pyc index 5e3939c..deb0430 100644 Binary files a/core/biz/__pycache__/market_monitor.cpython-312.pyc and b/core/biz/__pycache__/market_monitor.cpython-312.pyc differ diff --git a/core/biz/market_monitor.py b/core/biz/market_monitor.py index dea0a1f..106fcd5 100644 --- a/core/biz/market_monitor.py +++ b/core/biz/market_monitor.py @@ -13,7 +13,8 @@ def create_metrics_report( next_bar_row: pd.Series, btc_bar_row: pd.Series, only_output_huge_volume: bool = False, - only_output_rise: bool = False + only_output_rise: bool = False, + now_datetime_str: str = None, ): """ 创建指标报告 @@ -42,11 +43,11 @@ def create_metrics_report( # fill -1 to nan row = row.fillna(1) - close = row["close"] - open = row["open"] - high = row["high"] - low = row["low"] - pct_chg = row["pct_chg"] + close = round(float(row["close"]), 10) + open = round(float(row["open"]), 10) + high = round(float(row["high"]), 10) + low = round(float(row["low"]), 10) + pct_chg = round(float(row["pct_chg"]), 4) if only_output_rise and pct_chg < 0: logging.info( f"symbol: {symbol} {bar} window_size: {window_size} date_time: {date_time} 下跌,不发送相关数据" @@ -56,16 +57,19 @@ def create_metrics_report( contents.append(f"## 交易巨量报告") else: contents.append(f"## 交易量报告") - contents.append(f"## {symbol} {bar} 滑动窗口: {window_size} 时间: {date_time}") + if now_datetime_str is not None: + contents.append(f"## {symbol} {bar} 滑动窗口: {window_size} 最新数据时间: {now_datetime_str}") + else: + contents.append(f"## {symbol} {bar} 滑动窗口: {window_size} 交易周期时间: {date_time}") contents.append(f"### 价格信息") contents.append(f"当前价格: {close}, 开盘价: {open}, 最高价: {high}, 最低价: {low}") contents.append(f"涨跌幅: {pct_chg}") - volume = row["volume"] - volCcy = row["volCcy"] - volCCyQuote = row["volCCyQuote"] - volume_ratio = row["volume_ratio"] - spike_intensity = row["spike_intensity"] + volume = round(float(row["volume"]), 4) + volCcy = round(float(row["volCcy"]), 4) + volCCyQuote = round(float(row["volCCyQuote"]), 4) + volume_ratio = round(float(row["volume_ratio"]), 4) + spike_intensity = round(float(row["spike_intensity"]), 4) close_80_high = int(row["close_80_high"]) close_20_low = int(row["close_20_low"]) close_90_high = int(row["close_90_high"]) @@ -270,10 +274,10 @@ def create_metrics_report( if next_bar_row is not None: contents.append(f"## {symbol} 与更长周期技术形态对比") - contents.extend(get_long_short_over_buy_sell(next_bar_row)) + contents.extend(get_long_short_over_buy_sell(next_bar_row, now_datetime_str)) if btc_bar_row is not None: contents.append(f"## {symbol} 与BTC相同周期技术形态对比") - contents.extend(get_long_short_over_buy_sell(btc_bar_row)) + contents.extend(get_long_short_over_buy_sell(btc_bar_row, now_datetime_str)) mark_down_text = "\n\n".join(contents) return mark_down_text @@ -281,6 +285,7 @@ def create_metrics_report( def get_long_short_over_buy_sell( row: pd.Series, + now_datetime_str: str = None, ): result = {} symbol = row["symbol"] @@ -295,7 +300,10 @@ def get_long_short_over_buy_sell( boll_signal = str(row["boll_signal"]) boll_pattern = str(row["boll_pattern"]) contents = [] - contents.append(f"### {symbol} {bar} 对比形态 {date_time}") + if now_datetime_str is not None: + contents.append(f"### {symbol} {bar} 对比形态 最新数据时间: {now_datetime_str}") + else: + contents.append(f"### {symbol} {bar} 对比形态 交易周期时间: {date_time}") if ma_long_short in ["多", "空"]: contents.append(f"均线形态: {ma_long_short}") else: diff --git a/market_monitor_main.py b/market_monitor_main.py index 9da3420..2295aef 100644 --- a/market_monitor_main.py +++ b/market_monitor_main.py @@ -95,7 +95,7 @@ class MarketMonitorMain: latest_reatime_datetime = timestamp_to_datetime(latest_realtime_timestamp) if latest_record_timestamp is not None: latest_record_timestamp = int(latest_record_timestamp) - + latest_record_datetime = timestamp_to_datetime(latest_record_timestamp) if ( latest_record_timestamp is not None @@ -106,10 +106,12 @@ class MarketMonitorMain: ) return logging.info( - f"最新市场数据时间 {latest_reatime_datetime}, 上一次记录时间 {latest_record_datetime}") + f"最新市场数据时间 {latest_reatime_datetime}, 上一次记录时间 {latest_record_datetime}" + ) else: logging.info( - f"最新市场数据时间 {latest_reatime_datetime}, 上一次记录时间为空") + f"最新市场数据时间 {latest_reatime_datetime}, 上一次记录时间为空" + ) real_time_data = self.market_data_main.add_new_columns(real_time_data) logging.info(f"开始计算技术指标: {symbol} {bar}") @@ -134,23 +136,35 @@ class MarketMonitorMain: if realtime_row["huge_volume"] == 1: logging.info(f"监控到巨量: {symbol} {bar} 窗口大小: {self.window_size}") else: - logging.info(f"监控到非巨量: {symbol} {bar} 窗口大小: {self.window_size},退出本次监控") + logging.info( + f"监控到非巨量: {symbol} {bar} 窗口大小: {self.window_size},退出本次监控" + ) return if only_output_rise: if realtime_row["pct_change"] > 0: logging.info(f"监控到上涨: {symbol} {bar} 窗口大小: {self.window_size}") else: - logging.info(f"监控到下跌: {symbol} {bar} 窗口大小: {self.window_size},退出本次监控") + logging.info( + f"监控到下跌: {symbol} {bar} 窗口大小: {self.window_size},退出本次监控" + ) return next_bar_row = self.get_other_realtime_data(symbol, bar, end_time, next=True) - if 'BTC-USDT' in symbol: + if "BTC-USDT" in symbol: btc_bar_row = None else: - btc_bar_row = self.get_other_realtime_data('BTC-USDT', bar, end_time, next=False) + btc_bar_row = self.get_other_realtime_data( + "BTC-USDT", bar, end_time, next=False + ) - - report = create_metrics_report(realtime_row, next_bar_row, btc_bar_row, only_output_huge_volume, only_output_rise) + report = create_metrics_report( + realtime_row, + next_bar_row, + btc_bar_row, + only_output_huge_volume, + only_output_rise, + now_datetime_str, + ) text_length = len(report.encode("utf-8")) logging.info(f"发送报告到企业微信,字节数: {text_length}") @@ -158,9 +172,7 @@ class MarketMonitorMain: # remove punction in latest_reatime_datetime file_datetime = re.sub(r"[\:\-\s]", "", latest_reatime_datetime) - report_file_name = ( - f"{symbol}_{bar}_{self.window_size}_{file_datetime}.md" - ) + report_file_name = f"{symbol}_{bar}_{self.window_size}_{file_datetime}.md" report_file_path = os.path.join(self.output_folder, report_file_name) with open(report_file_path, "w", encoding="utf-8") as f: f.write(report) @@ -186,7 +198,9 @@ class MarketMonitorMain: 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 get_other_realtime_data(self, symbol: str, bar: str, end_time: int, next: bool = True): + def get_other_realtime_data( + self, symbol: str, bar: str, end_time: int, next: bool = True + ): """ 获取下一个长周期实时数据 """ @@ -218,7 +232,9 @@ class MarketMonitorMain: ): for symbol in self.market_data_main.symbols: for bar in self.market_data_main.bars: - logging.info(f"开始监控: {symbol} {bar} 窗口大小: {self.window_size} 行情数据") + logging.info( + f"开始监控: {symbol} {bar} 窗口大小: {self.window_size} 行情数据" + ) try: self.monitor_realtime_market( symbol, @@ -227,7 +243,9 @@ class MarketMonitorMain: only_output_rise, ) except Exception as e: - logging.error(f"监控失败: {symbol} {bar} 窗口大小: {self.window_size} 行情数据: {e}") + logging.error( + f"监控失败: {symbol} {bar} 窗口大小: {self.window_size} 行情数据: {e}" + ) continue diff --git a/monitor_schedule.py b/monitor_schedule.py index 67c5fb5..8c6a90d 100644 --- a/monitor_schedule.py +++ b/monitor_schedule.py @@ -13,8 +13,8 @@ def monitor_schedule(): only_output_huge_volume=True, only_output_rise=False, ) - logging.info("本次循环监控结束,等待1分钟") - time.sleep(60) + logging.info("本次循环监控结束,等待30秒") + time.sleep(30) if __name__ == "__main__": monitor_schedule() \ No newline at end of file