feat: 5-coin fleet (DOGE/SOL/ETH/XRP/BTC), enriched context (multi-TF trend, orderbook depth, BTC corr, WR history, regime), memory system (learned patterns), self-adapting overrides, fleet dashboard with per-coin RSI/mom
This commit is contained in:
34
bot.py
34
bot.py
@@ -276,6 +276,14 @@ def enriched_context(cfg, price, mom, mom_score, conn):
|
||||
if "fee_fast" in ix:
|
||||
lines.append(f"mempool fast fee: {ix['fee_fast']} sat/vB")
|
||||
|
||||
# Learned patterns from past bets
|
||||
learnings = conn.execute("SELECT v FROM kv WHERE k='learnings'").fetchone()
|
||||
if learnings:
|
||||
try:
|
||||
for l in json.loads(learnings[0])[-5:]:
|
||||
lines.append(f"LEARNED: {l}")
|
||||
except Exception: pass
|
||||
|
||||
lines.append("")
|
||||
lines.append("You trade 15-minute crypto up/down binary contracts by FADING spikes:")
|
||||
lines.append("- Sharp UP move → bet DOWN (mean reversion)")
|
||||
@@ -284,6 +292,8 @@ def enriched_context(cfg, price, mom, mom_score, conn):
|
||||
lines.append("- Consider: RSI extremes (>80 or <20 = high-prob fade), 24h range position, BTC macro direction")
|
||||
lines.append("Reply with ONLY JSON: {\"vote\":\"UP\"|\"DOWN\"|\"SKIP\",\"conf\":0.0-1.0,\"why\":\"<10 words>\"}")
|
||||
return "\n".join(lines)
|
||||
|
||||
def llm_vote(cfg, price, mom, mom_score, conn):
|
||||
"""Two-tier: qwen3.5 (fast gate, 0.4s on MacBook) → ornith (deep verify on RTX 3070).
|
||||
Gate handles clear signals; borderline calls escalate to ornith for final verdict."""
|
||||
coin = cfg.get("coin","BTC")
|
||||
@@ -495,6 +505,30 @@ def adapt_controls(conn, cfg):
|
||||
conn.commit()
|
||||
LOG.info(f"🔧 self-adapt: {ov.get('reason')} — override={json.dumps({k:v for k,v in ov.items() if k!='reason'})}")
|
||||
_last_adapt_ts = time.time()
|
||||
# extract learnings from resolved bets
|
||||
lp = (
|
||||
f"Recent trades: {json.dumps([{'side':r[0],'pnl':r[1],'price':r[2]} for r in resolved[:10]])}. "
|
||||
"Extract 1-2 actionable trading patterns. Reply with ONLY JSON array of strings, e.g.: "
|
||||
'["RSI < 20 UP bets won 3/4 times","DOGE fades after 0.1% spike lose 60%"]'
|
||||
)
|
||||
try:
|
||||
r3 = requests.post(fast_url+"/api/generate",
|
||||
json={"model": cfg.get("fast_llm_model","qwen3.5:4b"), "prompt": lp,
|
||||
"stream": False, "think": False, "options": {"temperature": 0.1, "num_predict": 60}},
|
||||
timeout=10)
|
||||
txt3 = r3.json().get("response","")
|
||||
s3, e3 = txt3.find("["), txt3.rfind("]")+1
|
||||
new_learnings = json.loads(txt3[s3:e3]) if s3 >= 0 else []
|
||||
if new_learnings:
|
||||
existing = conn.execute("SELECT v FROM kv WHERE k='learnings'").fetchone()
|
||||
old = json.loads(existing[0]) if existing else []
|
||||
old.extend(new_learnings)
|
||||
conn.execute("INSERT OR REPLACE INTO kv(k,v) VALUES ('learnings',?)",
|
||||
(json.dumps(old[-20:]),)) # keep last 20
|
||||
conn.commit()
|
||||
LOG.info(f"🧠 learned: {new_learnings}")
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass # silently skip on failure
|
||||
|
||||
|
||||
Reference in New Issue
Block a user