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.

This commit is contained in:
2569718930@qq.com
2026-02-06 21:19:31 +08:00
parent 2f81c1e23b
commit 1722d4ce39
2 changed files with 31 additions and 9 deletions
+2 -9
View File
@@ -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} <b>{i}. {city} {option}</b>\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")
+29
View File
@@ -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():