Integrate Meilisearch + Redis deeply for cache, locks, searchable decisions/insights, and health telemetry
This commit is contained in:
30
bot.py
30
bot.py
@@ -21,6 +21,7 @@ from services import (
|
||||
redis_set_json,
|
||||
redis_get_json,
|
||||
redis_lock,
|
||||
meili_index_doc,
|
||||
)
|
||||
|
||||
scheduler = BackgroundScheduler(timezone=settings.timezone)
|
||||
@@ -39,6 +40,14 @@ def curate_cycle():
|
||||
summary = summarize_news_with_ollama(symbol, news)
|
||||
row = CuratedInsight(symbol=symbol, summary=summary, sources=json.dumps(news)[:60000])
|
||||
db.add(row)
|
||||
meili_index_doc('insights', {
|
||||
'id': f"ins-{int(datetime.utcnow().timestamp())}-{symbol}",
|
||||
'ts': datetime.utcnow().isoformat(),
|
||||
'symbol': symbol,
|
||||
'summary': summary,
|
||||
'sources': json.dumps(news)[:2000],
|
||||
'kind': 'insight'
|
||||
})
|
||||
db.commit()
|
||||
finally:
|
||||
db.close()
|
||||
@@ -118,6 +127,17 @@ def run_cycle():
|
||||
db.add(drow)
|
||||
db.commit()
|
||||
db.refresh(drow)
|
||||
meili_index_doc('decisions', {
|
||||
'id': f"dec-{drow.id}",
|
||||
'ts': drow.ts.isoformat() if drow.ts else datetime.utcnow().isoformat(),
|
||||
'symbol': drow.symbol,
|
||||
'action': drow.action,
|
||||
'confidence': drow.confidence,
|
||||
'status': drow.status,
|
||||
'reason': drow.reason[:500],
|
||||
'order_usd': drow.order_usd,
|
||||
'kind': 'decision'
|
||||
})
|
||||
|
||||
should_trade = decision["action"] in {"buy", "sell"} and decision["confidence"] >= settings.min_confidence
|
||||
|
||||
@@ -145,6 +165,16 @@ def run_cycle():
|
||||
raw=json.dumps({"decision": decision, "strategy": strat, "memory": memory_hits, "broker": res})[:60000],
|
||||
)
|
||||
db.add(trade)
|
||||
db.flush()
|
||||
meili_index_doc('trades', {
|
||||
'id': f"tr-{trade.id}",
|
||||
'ts': trade.ts.isoformat() if trade.ts else datetime.utcnow().isoformat(),
|
||||
'symbol': trade.symbol,
|
||||
'side': trade.side,
|
||||
'notional': trade.notional,
|
||||
'order_id': trade.alpaca_order_id,
|
||||
'kind': 'trade'
|
||||
})
|
||||
db.commit()
|
||||
|
||||
# learning memory + notes + orchestration signal
|
||||
|
||||
Reference in New Issue
Block a user