From 1722d4ce3913f3a2503d476a8a452645a511782a Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Fri, 6 Feb 2026 21:19:31 +0800 Subject: [PATCH] feat: Implement price trend tracking and calculation, increase the number of displayed markets to five, and simplify market message output by removing volume and local time. --- bot_listener.py | 11 ++--------- main.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/bot_listener.py b/bot_listener.py index c7d0daa7..93ab8ee2 100644 --- a/bot_listener.py +++ b/bot_listener.py @@ -98,7 +98,7 @@ def start_bot(): return max_price / 2 # 远离锁定 earliest_markets.sort(key=opportunity_score, reverse=True) - top_markets = earliest_markets[:3] + top_markets = earliest_markets[:5] # 构建消息 msg_lines = [ @@ -170,17 +170,10 @@ def start_bot(): lock_status = "⚖️均衡" confidence = "📊" - # 成交量显示 - vol_text = f"${volume/1000:.1f}K" if volume >= 1000 else f"${volume:.0f}" - - # 当地时间 - local_time = s.get("local_time", "") - time_only = local_time.split(" ")[1] if " " in local_time else local_time - msg_lines.append( f"{confidence} {i}. {city} {option}\n" f" 💡 {analysis}\n" - f" 📊 {direction} | {lock_status} | 量:{vol_text} | 🕒{time_only}\n" + f" 📊 {direction} | {lock_status}\n" ) bot.send_message(message.chat.id, "\n".join(msg_lines), parse_mode="HTML") diff --git a/main.py b/main.py index e0197fde..58284b0a 100644 --- a/main.py +++ b/main.py @@ -63,6 +63,16 @@ def main(): location_cache = {} + # 价格历史追踪(用于计算趋势) + PRICE_HISTORY_FILE = "data/price_history.json" + price_history = {} + if os.path.exists(PRICE_HISTORY_FILE): + try: + with open(PRICE_HISTORY_FILE, "r", encoding="utf-8") as f: + price_history = json.load(f) + except: + price_history = {} + try: while True: logger.info("--- 开启新一轮全量动态监控 (自动搜寻所有天气市场) ---") @@ -262,6 +272,20 @@ def main(): .get("local_time") ) + # 计算价格趋势 + prev_data = price_history.get(market_id, {}) + prev_price = prev_data.get("price", current_price) + if prev_price > 0: + price_change_pct = ((current_price - prev_price) / prev_price) * 100 + else: + price_change_pct = 0 + + # 更新价格历史 + price_history[market_id] = { + "price": current_price, + "timestamp": datetime.now().isoformat() + } + cache_entry = { "city": city, "full_title": event_title, @@ -275,6 +299,7 @@ def main(): "target_date": target_date, "score": 0, "rationale": "ACTIVE", + "trend": round(price_change_pct, 1), } if buy_yes_price <= 0.01 or buy_yes_price >= 0.99: @@ -458,6 +483,10 @@ def main(): with open("data/pushed_signals.json", "w", encoding="utf-8") as f: json.dump(pushed_signals, f, ensure_ascii=False) + # 3.5 保存价格历史(用于趋势计算) + with open(PRICE_HISTORY_FILE, "w", encoding="utf-8") as f: + json.dump(price_history, f, ensure_ascii=False) + # --- 4. 更新模拟仓位盈亏 --- price_snapshot = {} for mid, entry in all_markets_cache.items():