feat(news): 6h cache, politics-only, max 5/cycle, 2s sleep between calls
CI/CD / build-and-push (push) Successful in 1m32s
CI/CD / build-and-push (push) Successful in 1m32s
- CACHE_TTL: 4h → 6h (≤36 req/day with ≤9 politics markets) - GNews only called for is_politics markets (BTC/F&G cover crypto/macro) - MAX_NEWS_QUERIES_PER_CYCLE=5: BayesianStrategy.reset_cycle() called each iteration; counter increments only on actual API call (cache hits free) - 2s asyncio.sleep in news.py finally block after each real HTTP request - main.py sorts markets: politics first by end_date ascending, so soonest- resolving markets consume the 5-query budget before others Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+18
-1
@@ -1,11 +1,12 @@
|
||||
"""
|
||||
Polymarket Trading Bot — Main Entry Point
|
||||
# ci-test: 2026-04-13
|
||||
# ci-test: 2026-04-14
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
from contextlib import asynccontextmanager
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from bot.data.polymarket import PolymarketClient
|
||||
from bot.data.external import ExternalDataClient
|
||||
@@ -42,6 +43,19 @@ async def run_trading_loop(
|
||||
# 1. Fetch active crypto/finance markets
|
||||
markets = await poly.get_active_markets()
|
||||
log.info("Found %d active markets", len(markets))
|
||||
|
||||
# Sort: politics markets first (soonest-resolving → highest GNews priority),
|
||||
# then all others. This ensures the 5-query-per-cycle cap hits the most
|
||||
# time-sensitive political markets before the budget runs out.
|
||||
def _sort_key(m):
|
||||
is_pol = m.category == "politics"
|
||||
try:
|
||||
dt = datetime.fromisoformat(m.end_date.replace("Z", "+00:00"))
|
||||
except Exception:
|
||||
dt = datetime(9999, 12, 31, tzinfo=timezone.utc)
|
||||
return (0 if is_pol else 1, dt)
|
||||
|
||||
markets = sorted(markets, key=_sort_key)
|
||||
for _m in markets:
|
||||
log.info(" [market] %s | ends: %s | yes_price: %.3f",
|
||||
_m.question, _m.end_date, _m.yes_price)
|
||||
@@ -49,6 +63,9 @@ async def run_trading_loop(
|
||||
# 2. Get external signals
|
||||
ext_data = await external.get_all_signals()
|
||||
|
||||
# Reset per-cycle GNews counter so the limit applies fresh each cycle
|
||||
strategy.reset_cycle()
|
||||
|
||||
for market in markets:
|
||||
# 3. Estimate true probability
|
||||
signal = await strategy.evaluate(market, ext_data)
|
||||
|
||||
Reference in New Issue
Block a user