Upload 322 files
Browse files- hf_unified_server.py +12 -42
- index.html +1 -1
hf_unified_server.py
CHANGED
|
@@ -35,7 +35,6 @@ import json
|
|
| 35 |
from pathlib import Path
|
| 36 |
import httpx
|
| 37 |
|
| 38 |
-
from database import CryptoDatabase
|
| 39 |
|
| 40 |
from ai_models import (
|
| 41 |
analyze_chart_points,
|
|
@@ -92,8 +91,8 @@ APL_REPORT_PATH = WORKSPACE_ROOT / "PROVIDER_AUTO_DISCOVERY_REPORT.json"
|
|
| 92 |
# Ensure log directory exists
|
| 93 |
LOG_DIR.mkdir(parents=True, exist_ok=True)
|
| 94 |
|
| 95 |
-
#
|
| 96 |
-
|
| 97 |
|
| 98 |
def tail_log_file(path: Path, max_lines: int = 200) -> List[str]:
|
| 99 |
"""Return the last max_lines from a log file, if it exists."""
|
|
@@ -666,24 +665,6 @@ async def get_market():
|
|
| 666 |
if not prices:
|
| 667 |
raise HTTPException(status_code=503, detail="Unable to fetch market data")
|
| 668 |
|
| 669 |
-
# Persist real market data into SQLite database (no mocks)
|
| 670 |
-
try:
|
| 671 |
-
for item in prices:
|
| 672 |
-
payload = {
|
| 673 |
-
"symbol": item.get("symbol", "").upper(),
|
| 674 |
-
"name": item.get("name"),
|
| 675 |
-
"price_usd": item.get("current_price") or item.get("price"),
|
| 676 |
-
"volume_24h": item.get("total_volume"),
|
| 677 |
-
"market_cap": item.get("market_cap"),
|
| 678 |
-
"percent_change_1h": item.get("price_change_1h") or item.get("price_change_percentage_1h_in_currency"),
|
| 679 |
-
"percent_change_24h": item.get("price_change_percentage_24h"),
|
| 680 |
-
"percent_change_7d": item.get("price_change_percentage_7d_in_currency"),
|
| 681 |
-
"rank": item.get("market_cap_rank"),
|
| 682 |
-
}
|
| 683 |
-
db.save_price(payload)
|
| 684 |
-
except Exception as db_err:
|
| 685 |
-
logger.warning(f"Failed to save market data to DB: {db_err}")
|
| 686 |
-
|
| 687 |
return {
|
| 688 |
"total_market_cap": overview.get("total_market_cap", 0),
|
| 689 |
"btc_dominance": overview.get("btc_dominance", 0),
|
|
@@ -2458,34 +2439,23 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
| 2458 |
@app.get("/api/market/history")
|
| 2459 |
async def get_market_history(symbol: str = "BTC", limit: int = 10):
|
| 2460 |
"""
|
| 2461 |
-
Get historical prices from the
|
| 2462 |
|
| 2463 |
-
|
| 2464 |
-
and
|
| 2465 |
"""
|
| 2466 |
symbol = symbol.upper()
|
| 2467 |
-
|
| 2468 |
-
|
| 2469 |
-
except Exception as e:
|
| 2470 |
-
logger.error(f"Error reading history for {symbol}: {e}")
|
| 2471 |
-
raise HTTPException(status_code=500, detail="Error reading market history")
|
| 2472 |
-
|
| 2473 |
-
if not history:
|
| 2474 |
-
return {
|
| 2475 |
-
"symbol": symbol,
|
| 2476 |
-
"history": [],
|
| 2477 |
-
"count": 0,
|
| 2478 |
-
"message": "No history available",
|
| 2479 |
-
}
|
| 2480 |
-
|
| 2481 |
return {
|
| 2482 |
"symbol": symbol,
|
| 2483 |
-
"history":
|
| 2484 |
-
"count":
|
| 2485 |
-
"
|
| 2486 |
}
|
| 2487 |
|
| 2488 |
|
|
|
|
| 2489 |
@app.get("/api/status")
|
| 2490 |
async def get_status():
|
| 2491 |
"""
|
|
@@ -2498,7 +2468,7 @@ async def get_status():
|
|
| 2498 |
providers = providers_cfg or {}
|
| 2499 |
validated_count = sum(1 for p in providers.values() if p.get("validated"))
|
| 2500 |
|
| 2501 |
-
db_path =
|
| 2502 |
db_status = "connected" if db_path.exists() else "initializing"
|
| 2503 |
|
| 2504 |
return {
|
|
|
|
| 35 |
from pathlib import Path
|
| 36 |
import httpx
|
| 37 |
|
|
|
|
| 38 |
|
| 39 |
from ai_models import (
|
| 40 |
analyze_chart_points,
|
|
|
|
| 91 |
# Ensure log directory exists
|
| 92 |
LOG_DIR.mkdir(parents=True, exist_ok=True)
|
| 93 |
|
| 94 |
+
# Database path (managed by DatabaseManager in the admin API)
|
| 95 |
+
DB_PATH = WORKSPACE_ROOT / "data" / "api_monitor.db"
|
| 96 |
|
| 97 |
def tail_log_file(path: Path, max_lines: int = 200) -> List[str]:
|
| 98 |
"""Return the last max_lines from a log file, if it exists."""
|
|
|
|
| 665 |
if not prices:
|
| 666 |
raise HTTPException(status_code=503, detail="Unable to fetch market data")
|
| 667 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 668 |
return {
|
| 669 |
"total_market_cap": overview.get("total_market_cap", 0),
|
| 670 |
"btc_dominance": overview.get("btc_dominance", 0),
|
|
|
|
| 2439 |
@app.get("/api/market/history")
|
| 2440 |
async def get_market_history(symbol: str = "BTC", limit: int = 10):
|
| 2441 |
"""
|
| 2442 |
+
Get historical prices from the local database if available.
|
| 2443 |
|
| 2444 |
+
For this deployment we avoid touching the internal DatabaseManager
|
| 2445 |
+
and simply report that no history API is wired yet.
|
| 2446 |
"""
|
| 2447 |
symbol = symbol.upper()
|
| 2448 |
+
# We don't fabricate data here; if you need real history, it should
|
| 2449 |
+
# be implemented via the shared database models.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2450 |
return {
|
| 2451 |
"symbol": symbol,
|
| 2452 |
+
"history": [],
|
| 2453 |
+
"count": 0,
|
| 2454 |
+
"message": "History endpoint not wired to DB in this Space",
|
| 2455 |
}
|
| 2456 |
|
| 2457 |
|
| 2458 |
+
|
| 2459 |
@app.get("/api/status")
|
| 2460 |
async def get_status():
|
| 2461 |
"""
|
|
|
|
| 2468 |
providers = providers_cfg or {}
|
| 2469 |
validated_count = sum(1 for p in providers.values() if p.get("validated"))
|
| 2470 |
|
| 2471 |
+
db_path = DB_PATH
|
| 2472 |
db_status = "connected" if db_path.exists() else "initializing"
|
| 2473 |
|
| 2474 |
return {
|
index.html
CHANGED
|
@@ -2493,4 +2493,4 @@
|
|
| 2493 |
<!-- Load App JS as ES6 Module -->
|
| 2494 |
<script type="module" src="static/js/app.js?v=20250119"></script>
|
| 2495 |
</body>
|
| 2496 |
-
</html>
|
|
|
|
| 2493 |
<!-- Load App JS as ES6 Module -->
|
| 2494 |
<script type="module" src="static/js/app.js?v=20250119"></script>
|
| 2495 |
</body>
|
| 2496 |
+
</html>
|