fix: H1 bias calculate on first loop + add filter config infrastructure

**H1 Bias Fix:**
- Fixed cache check to ensure loop_count=1 always calculates H1 bias
- Changed exception log from DEBUG to WARNING for visibility
- Added log on first calculation (loop==1) in addition to every 4 loops
- Result: H1 bias now correctly calculated from first candle

**Filter Config Infrastructure (WIP):**
- Added FilterConfigManager (src/filter_config.py) for dynamic filter control
- Added data/filter_config.json with 11 entry filters (flash_crash, regime, risk, session, spread, h1_bias, ml_confidence, signal_combination, cooldown, time_filter, market_close)
- Added API endpoints: GET/POST /api/filters/config
- Note: Bot integration pending — requires wrapper around all filter checks

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
GifariKemal
2026-02-09 08:09:01 +07:00
co-authored by Claude Opus 4.6
parent 71b9bcc472
commit 85161b4965
3 changed files with 267 additions and 0 deletions
+59
View File
@@ -34,6 +34,7 @@ app.add_middleware(
# Status file path (mounted as volume in Docker)
STATUS_FILE = Path("/app/data/bot_status.json")
MODEL_METRICS_FILE = Path("/app/data/model_metrics.json")
FILTER_CONFIG_FILE = Path("/app/data/filter_config.json")
# Default empty response
DEFAULT_STATUS = {
@@ -413,6 +414,64 @@ async def get_signal_stats(hours: int = Query(24, ge=1, le=168)):
}
# ============================================================
# FILTER CONFIG ENDPOINTS
# ============================================================
@app.get("/api/filters/config")
async def get_filter_config():
"""Get current filter enable/disable states."""
try:
if not FILTER_CONFIG_FILE.exists():
return {"filters": {}, "metadata": {}}
with open(FILTER_CONFIG_FILE, 'r', encoding='utf-8') as f:
data = json.load(f)
return data
except Exception as e:
logger.error(f"Failed to load filter config: {e}")
return {"filters": {}, "metadata": {}, "error": str(e)}
@app.post("/api/filters/config")
async def update_filter_config(updates: dict):
"""
Update filter enable/disable states.
Body: { "filter_key": true/false, ... }
Example: { "h1_bias": false, "ml_confidence": true }
"""
try:
# Load current config
if not FILTER_CONFIG_FILE.exists():
return {"success": False, "error": "Filter config file not found"}
with open(FILTER_CONFIG_FILE, 'r', encoding='utf-8') as f:
data = json.load(f)
# Update enabled states
for filter_key, enabled in updates.items():
if filter_key in data["filters"]:
data["filters"][filter_key]["enabled"] = enabled
# Update metadata
data["metadata"]["updated_at"] = datetime.now(ZoneInfo("Asia/Jakarta")).isoformat()
# Save
with open(FILTER_CONFIG_FILE, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2, ensure_ascii=False)
logger.info(f"Filter config updated: {list(updates.keys())}")
return {"success": True, "updated": list(updates.keys())}
except Exception as e:
logger.error(f"Failed to update filter config: {e}")
return {"success": False, "error": str(e)}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)