Spaces:
Sleeping

legion-ai / trend_engine.py
Loading404's picture
Update trend_engine.py
9dc4124 verified
Raw History Blame Contribute Delete
706 Bytes
import json
import os
MEMORY_FILE = "/tmp/memory.json" # ✅ writable path on HF
def load_history():
if os.path.exists(MEMORY_FILE):
with open(MEMORY_FILE, "r") as f:
return json.load(f)
return []
def save_history(history):
with open(MEMORY_FILE, "w") as f:
json.dump(history, f)
def detect_trend(price):
history = load_history()
history.append(price)
history = history[-5:]
save_history(history)
if len(history) < 5:
return "⏳ Gathering..."
if price > max(history[:-1]):
return "📈 Leg Up Detected"
elif price < min(history[:-1]):
return "📉 Leg Down Forming"
else:
return "📊 Sideways"