File size: 96,315 Bytes
8ff9278 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 |
diff --git a/backend/routers/hf_space_api.py b/backend/routers/hf_space_api.py
index 6cac1b0..7683868 100644
--- a/backend/routers/hf_space_api.py
+++ b/backend/routers/hf_space_api.py
@@ -1,7 +1,7 @@
"""
HF Space Complete API Router
Implements all required endpoints for Hugging Face Space deployment
-with fallback support and comprehensive data endpoints
+using REAL data providers.
"""
from fastapi import APIRouter, HTTPException, Query, Body, Depends
from fastapi.responses import JSONResponse
@@ -14,16 +14,19 @@ import json
import os
from pathlib import Path
+# Import Real Data Providers
+from backend.live_data.providers import (
+ coingecko_provider,
+ binance_provider,
+ cryptopanic_provider,
+ alternative_me_provider
+)
+from backend.cache.cache_manager import cache_manager
+
logger = logging.getLogger(__name__)
router = APIRouter(tags=["HF Space Complete API"])
-# Import persistence
-from backend.services.hf_persistence import get_persistence
-
-persistence = get_persistence()
-
-
# ============================================================================
# Pydantic Models for Request/Response
# ============================================================================
@@ -32,8 +35,7 @@ class MetaInfo(BaseModel):
"""Metadata for all responses"""
cache_ttl_seconds: int = Field(default=30, description="Cache TTL in seconds")
generated_at: str = Field(default_factory=lambda: datetime.now().isoformat())
- source: str = Field(default="hf", description="Data source (hf, fallback provider name)")
-
+ source: str = Field(default="live", description="Data source")
class MarketItem(BaseModel):
"""Market ticker item"""
@@ -41,8 +43,7 @@ class MarketItem(BaseModel):
price: float
change_24h: float
volume_24h: float
- source: str = "hf"
-
+ source: str = "live"
class MarketResponse(BaseModel):
"""Market snapshot response"""
@@ -50,63 +51,6 @@ class MarketResponse(BaseModel):
items: List[MarketItem]
meta: MetaInfo
-
-class TradingPair(BaseModel):
- """Trading pair information"""
- pair: str
- base: str
- quote: str
- tick_size: float
- min_qty: float
-
-
-class PairsResponse(BaseModel):
- """Trading pairs response"""
- pairs: List[TradingPair]
- meta: MetaInfo
-
-
-class OHLCEntry(BaseModel):
- """OHLC candlestick entry"""
- ts: int
- open: float
- high: float
- low: float
- close: float
- volume: float
-
-
-class OrderBookEntry(BaseModel):
- """Order book entry [price, quantity]"""
- price: float
- qty: float
-
-
-class DepthResponse(BaseModel):
- """Order book depth response"""
- bids: List[List[float]]
- asks: List[List[float]]
- meta: MetaInfo
-
-
-class PredictRequest(BaseModel):
- """Model prediction request"""
- symbol: str
- context: Optional[str] = None
- params: Optional[Dict[str, Any]] = None
-
-
-class SignalResponse(BaseModel):
- """Trading signal response"""
- id: str
- symbol: str
- type: str # buy, sell, hold
- score: float
- model: str
- created_at: str
- meta: MetaInfo
-
-
class NewsArticle(BaseModel):
"""News article"""
id: str
@@ -116,19 +60,11 @@ class NewsArticle(BaseModel):
summary: Optional[str] = None
published_at: str
-
class NewsResponse(BaseModel):
"""News response"""
articles: List[NewsArticle]
meta: MetaInfo
-
-class SentimentRequest(BaseModel):
- """Sentiment analysis request"""
- text: str
- mode: Optional[str] = "crypto" # crypto, news, social
-
-
class SentimentResponse(BaseModel):
"""Sentiment analysis response"""
score: float
@@ -136,29 +72,6 @@ class SentimentResponse(BaseModel):
details: Optional[Dict[str, Any]] = None
meta: MetaInfo
-
-class WhaleTransaction(BaseModel):
- """Whale transaction"""
- id: str
- tx_hash: str
- chain: str
- from_address: str
- to_address: str
- amount_usd: float
- token: str
- block: int
- tx_at: str
-
-
-class WhaleStatsResponse(BaseModel):
- """Whale activity stats"""
- total_transactions: int
- total_volume_usd: float
- avg_transaction_usd: float
- top_chains: List[Dict[str, Any]]
- meta: MetaInfo
-
-
class GasPrice(BaseModel):
"""Gas price information"""
fast: float
@@ -166,134 +79,13 @@ class GasPrice(BaseModel):
slow: float
unit: str = "gwei"
-
class GasResponse(BaseModel):
"""Gas price response"""
chain: str
- gas_prices: GasPrice
+ gas_prices: Optional[GasPrice] = None
timestamp: str
meta: MetaInfo
-
-class BlockchainStats(BaseModel):
- """Blockchain statistics"""
- chain: str
- blocks_24h: int
- transactions_24h: int
- avg_gas_price: float
- mempool_size: Optional[int] = None
- meta: MetaInfo
-
-
-class ProviderInfo(BaseModel):
- """Provider information"""
- id: str
- name: str
- category: str
- status: str # active, degraded, down
- capabilities: List[str]
-
-
-# ============================================================================
-# Fallback Provider Manager
-# ============================================================================
-
-class FallbackManager:
- """Manages fallback providers from config file"""
-
- def __init__(self, config_path: str = "/workspace/api-resources/api-config-complete__1_.txt"):
- self.config_path = config_path
- self.providers = {}
- self._load_config()
-
- def _load_config(self):
- """Load fallback providers from config file"""
- try:
- if not os.path.exists(self.config_path):
- logger.warning(f"Config file not found: {self.config_path}")
- return
-
- # Parse the config file to extract provider information
- # This is a simple parser - adjust based on actual config format
- self.providers = {
- 'market_data': {
- 'primary': {'name': 'coingecko', 'url': 'https://api.coingecko.com/api/v3'},
- 'fallbacks': [
- {'name': 'binance', 'url': 'https://api.binance.com/api/v3'},
- {'name': 'coincap', 'url': 'https://api.coincap.io/v2'}
- ]
- },
- 'blockchain': {
- 'ethereum': {
- 'primary': {'name': 'etherscan', 'url': 'https://api.etherscan.io/api', 'key': 'SZHYFZK2RR8H9TIMJBVW54V4H81K2Z2KR2'},
- 'fallbacks': [
- {'name': 'blockchair', 'url': 'https://api.blockchair.com/ethereum'}
- ]
- }
- },
- 'whale_tracking': {
- 'primary': {'name': 'clankapp', 'url': 'https://clankapp.com/api'},
- 'fallbacks': []
- },
- 'news': {
- 'primary': {'name': 'cryptopanic', 'url': 'https://cryptopanic.com/api/v1'},
- 'fallbacks': [
- {'name': 'reddit', 'url': 'https://www.reddit.com/r/CryptoCurrency/hot.json'}
- ]
- },
- 'sentiment': {
- 'primary': {'name': 'alternative.me', 'url': 'https://api.alternative.me/fng'}
- }
- }
- logger.info(f"Loaded fallback providers from {self.config_path}")
- except Exception as e:
- logger.error(f"Error loading fallback config: {e}")
-
- async def fetch_with_fallback(self, category: str, endpoint: str, params: Optional[Dict] = None) -> tuple:
- """
- Fetch data with automatic fallback
- Returns (data, source_name)
- """
- import aiohttp
-
- if category not in self.providers:
- raise HTTPException(status_code=500, detail=f"Category {category} not configured")
-
- provider_config = self.providers[category]
-
- # Try primary first
- primary = provider_config.get('primary')
- if primary:
- try:
- async with aiohttp.ClientSession() as session:
- url = f"{primary['url']}{endpoint}"
- async with session.get(url, params=params, timeout=aiohttp.ClientTimeout(total=10)) as response:
- if response.status == 200:
- data = await response.json()
- return data, primary['name']
- except Exception as e:
- logger.warning(f"Primary provider {primary['name']} failed: {e}")
-
- # Try fallbacks
- fallbacks = provider_config.get('fallbacks', [])
- for fallback in fallbacks:
- try:
- async with aiohttp.ClientSession() as session:
- url = f"{fallback['url']}{endpoint}"
- async with session.get(url, params=params, timeout=aiohttp.ClientTimeout(total=10)) as response:
- if response.status == 200:
- data = await response.json()
- return data, fallback['name']
- except Exception as e:
- logger.warning(f"Fallback provider {fallback['name']} failed: {e}")
-
- raise HTTPException(status_code=503, detail="All providers failed")
-
-
-# Initialize fallback manager
-fallback_manager = FallbackManager()
-
-
# ============================================================================
# Market & Pairs Endpoints
# ============================================================================
@@ -301,64 +93,40 @@ fallback_manager = FallbackManager()
@router.get("/api/market", response_model=MarketResponse)
async def get_market_snapshot():
"""
- Get current market snapshot with prices, changes, and volumes
- Priority: HF HTTP → Fallback providers
+ Get current market snapshot with prices, changes, and volumes.
+ Uses CoinGecko API.
"""
+ cache_key = "market_snapshot"
+ cached = await cache_manager.get(cache_key)
+ if cached:
+ return cached
+
try:
- # Try HF implementation first
- # For now, use fallback
- data, source = await fallback_manager.fetch_with_fallback(
- 'market_data',
- '/simple/price',
- params={'ids': 'bitcoin,ethereum,tron', 'vs_currencies': 'usd', 'include_24hr_change': 'true', 'include_24hr_vol': 'true'}
- )
+ data = await coingecko_provider.get_market_data(ids="bitcoin,ethereum,tron,solana,binancecoin,ripple")
- # Transform data
items = []
- for coin_id, coin_data in data.items():
+ for coin in data:
items.append(MarketItem(
- symbol=coin_id.upper(),
- price=coin_data.get('usd', 0),
- change_24h=coin_data.get('usd_24h_change', 0),
- volume_24h=coin_data.get('usd_24h_vol', 0),
- source=source
+ symbol=coin.get('symbol', '').upper(),
+ price=coin.get('current_price', 0),
+ change_24h=coin.get('price_change_percentage_24h', 0),
+ volume_24h=coin.get('total_volume', 0),
+ source="coingecko"
))
- return MarketResponse(
+ response = MarketResponse(
last_updated=datetime.now().isoformat(),
items=items,
- meta=MetaInfo(cache_ttl_seconds=30, source=source)
+ meta=MetaInfo(cache_ttl_seconds=60, source="coingecko")
)
-
- except Exception as e:
- logger.error(f"Error in get_market_snapshot: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/market/pairs", response_model=PairsResponse)
-async def get_trading_pairs():
- """
- Get canonical list of trading pairs
- MUST be served by HF HTTP (not WebSocket)
- """
- try:
- # This should be implemented by HF Space
- # For now, return sample data
- pairs = [
- TradingPair(pair="BTC/USDT", base="BTC", quote="USDT", tick_size=0.01, min_qty=0.0001),
- TradingPair(pair="ETH/USDT", base="ETH", quote="USDT", tick_size=0.01, min_qty=0.001),
- TradingPair(pair="BNB/USDT", base="BNB", quote="USDT", tick_size=0.01, min_qty=0.01),
- ]
- return PairsResponse(
- pairs=pairs,
- meta=MetaInfo(cache_ttl_seconds=300, source="hf")
- )
+ await cache_manager.set(cache_key, response, ttl=60)
+ return response
except Exception as e:
- logger.error(f"Error in get_trading_pairs: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
+ logger.error(f"Error in get_market_snapshot: {e}")
+ # Return empty list or cached stale data if available, but NEVER fake data
+ raise HTTPException(status_code=503, detail="Market data unavailable")
@router.get("/api/market/ohlc")
async def get_ohlc(
@@ -366,207 +134,55 @@ async def get_ohlc(
interval: int = Query(60, description="Interval in minutes"),
limit: int = Query(100, description="Number of candles")
):
- """Get OHLC candlestick data"""
+ """Get OHLC candlestick data from Binance"""
+ cache_key = f"ohlc_{symbol}_{interval}_{limit}"
+ cached = await cache_manager.get(cache_key)
+ if cached:
+ return cached
+
try:
- # Should implement actual OHLC fetching
- # For now, return sample data
- ohlc_data = []
- base_price = 50000 if symbol.upper() == "BTC" else 3500
+ # Map minutes to Binance intervals
+ binance_interval = "1h"
+ if interval == 1: binance_interval = "1m"
+ elif interval == 5: binance_interval = "5m"
+ elif interval == 15: binance_interval = "15m"
+ elif interval == 60: binance_interval = "1h"
+ elif interval == 240: binance_interval = "4h"
+ elif interval == 1440: binance_interval = "1d"
+
+ # Binance symbol needs to be e.g., BTCUSDT
+ formatted_symbol = symbol.upper()
+ if not formatted_symbol.endswith("USDT") and not formatted_symbol.endswith("USD"):
+ formatted_symbol += "USDT"
+
+ klines = await binance_provider.get_klines(formatted_symbol, interval=binance_interval, limit=limit)
- for i in range(limit):
- ts = int((datetime.now() - timedelta(minutes=interval * (limit - i))).timestamp())
+ ohlc_data = []
+ for k in klines:
+ # Binance kline: [open_time, open, high, low, close, volume, ...]
ohlc_data.append({
- "ts": ts,
- "open": base_price + (i % 10) * 100,
- "high": base_price + (i % 10) * 100 + 200,
- "low": base_price + (i % 10) * 100 - 100,
- "close": base_price + (i % 10) * 100 + 50,
- "volume": 1000000 + (i % 5) * 100000
+ "ts": int(k[0] / 1000),
+ "open": float(k[1]),
+ "high": float(k[2]),
+ "low": float(k[3]),
+ "close": float(k[4]),
+ "volume": float(k[5])
})
- return {
+ response = {
"symbol": symbol,
"interval": interval,
"data": ohlc_data,
- "meta": MetaInfo(cache_ttl_seconds=120).__dict__
- }
-
- except Exception as e:
- logger.error(f"Error in get_ohlc: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/market/depth", response_model=DepthResponse)
-async def get_order_book_depth(
- symbol: str = Query(..., description="Trading symbol"),
- limit: int = Query(50, description="Depth limit")
-):
- """Get order book depth (bids and asks)"""
- try:
- # Sample orderbook data
- base_price = 50000 if symbol.upper() == "BTC" else 3500
-
- bids = [[base_price - i * 10, 0.1 + i * 0.01] for i in range(limit)]
- asks = [[base_price + i * 10, 0.1 + i * 0.01] for i in range(limit)]
-
- return DepthResponse(
- bids=bids,
- asks=asks,
- meta=MetaInfo(cache_ttl_seconds=10, source="hf")
- )
-
- except Exception as e:
- logger.error(f"Error in get_order_book_depth: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/market/tickers")
-async def get_tickers(
- limit: int = Query(100, description="Number of tickers"),
- sort: str = Query("volume", description="Sort by: volume, change, price")
-):
- """Get sorted tickers"""
- try:
- # Fetch from fallback
- data, source = await fallback_manager.fetch_with_fallback(
- 'market_data',
- '/coins/markets',
- params={'vs_currency': 'usd', 'order': 'market_cap_desc', 'per_page': limit, 'page': 1}
- )
-
- tickers = []
- for coin in data:
- tickers.append({
- 'symbol': coin.get('symbol', '').upper(),
- 'name': coin.get('name'),
- 'price': coin.get('current_price'),
- 'change_24h': coin.get('price_change_percentage_24h'),
- 'volume_24h': coin.get('total_volume'),
- 'market_cap': coin.get('market_cap')
- })
-
- return {
- 'tickers': tickers,
- 'meta': MetaInfo(cache_ttl_seconds=60, source=source).__dict__
+ "meta": MetaInfo(cache_ttl_seconds=60, source="binance").dict()
}
-
- except Exception as e:
- logger.error(f"Error in get_tickers: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
-# ============================================================================
-# Signals & Models Endpoints
-# ============================================================================
-
[email protected]("/api/models/{model_key}/predict", response_model=SignalResponse)
-async def predict_single(model_key: str, request: PredictRequest):
- """
- Run prediction for a single symbol using specified model
- """
- try:
- # Generate signal
- import random
- signal_id = f"sig_{int(datetime.now().timestamp())}_{random.randint(1000, 9999)}"
-
- signal_types = ["buy", "sell", "hold"]
- signal_type = random.choice(signal_types)
- score = random.uniform(0.6, 0.95)
-
- signal = SignalResponse(
- id=signal_id,
- symbol=request.symbol,
- type=signal_type,
- score=score,
- model=model_key,
- created_at=datetime.now().isoformat(),
- meta=MetaInfo(source=f"model:{model_key}")
- )
-
- # Store in database
- persistence.save_signal(signal.dict())
- return signal
-
- except Exception as e:
- logger.error(f"Error in predict_single: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/models/batch/predict")
-async def predict_batch(
- symbols: List[str] = Body(..., embed=True),
- context: Optional[str] = Body(None),
- params: Optional[Dict[str, Any]] = Body(None)
-):
- """Run batch prediction for multiple symbols"""
- try:
- results = []
- import random
-
- for symbol in symbols:
- signal_id = f"sig_{int(datetime.now().timestamp())}_{random.randint(1000, 9999)}"
- signal_types = ["buy", "sell", "hold"]
-
- signal = {
- 'id': signal_id,
- 'symbol': symbol,
- 'type': random.choice(signal_types),
- 'score': random.uniform(0.6, 0.95),
- 'model': 'batch_model',
- 'created_at': datetime.now().isoformat()
- }
- results.append(signal)
- persistence.save_signal(signal)
-
- return {
- 'predictions': results,
- 'meta': MetaInfo(source="hf:batch").__dict__
- }
-
- except Exception as e:
- logger.error(f"Error in predict_batch: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
+ await cache_manager.set(cache_key, response, ttl=60)
+ return response
[email protected]("/api/signals")
-async def get_signals(
- limit: int = Query(50, description="Number of signals to return"),
- symbol: Optional[str] = Query(None, description="Filter by symbol")
-):
- """Get recent trading signals"""
- try:
- # Get from database
- signals = persistence.get_signals(limit=limit, symbol=symbol)
-
- return {
- 'signals': signals,
- 'total': len(signals),
- 'meta': MetaInfo(cache_ttl_seconds=30).__dict__
- }
-
- except Exception as e:
- logger.error(f"Error in get_signals: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/signals/ack")
-async def acknowledge_signal(signal_id: str = Body(..., embed=True)):
- """Acknowledge a signal"""
- try:
- # Update in database
- success = persistence.acknowledge_signal(signal_id)
- if not success:
- raise HTTPException(status_code=404, detail="Signal not found")
-
- return {'status': 'success', 'signal_id': signal_id}
-
- except HTTPException:
- raise
except Exception as e:
- logger.error(f"Error in acknowledge_signal: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
+ logger.error(f"Error in get_ohlc: {e}")
+ # Try fallbacks? For now, fail gracefully.
+ raise HTTPException(status_code=503, detail="OHLC data unavailable")
# ============================================================================
# News & Sentiment Endpoints
@@ -577,13 +193,14 @@ async def get_news(
limit: int = Query(20, description="Number of articles"),
source: Optional[str] = Query(None, description="Filter by source")
):
- """Get cryptocurrency news"""
+ """Get cryptocurrency news from CryptoPanic"""
+ cache_key = f"news_{limit}_{source}"
+ cached = await cache_manager.get(cache_key)
+ if cached:
+ return cached
+
try:
- data, source_name = await fallback_manager.fetch_with_fallback(
- 'news',
- '/posts/',
- params={'public': 'true'}
- )
+ data = await cryptopanic_provider.get_news()
articles = []
results = data.get('results', [])[:limit]
@@ -594,876 +211,84 @@ async def get_news(
title=post.get('title', ''),
url=post.get('url', ''),
source=post.get('source', {}).get('title', 'Unknown'),
- summary=post.get('title', ''),
+ summary=post.get('slug', ''),
published_at=post.get('published_at', datetime.now().isoformat())
))
- return NewsResponse(
+ response = NewsResponse(
articles=articles,
- meta=MetaInfo(cache_ttl_seconds=300, source=source_name)
+ meta=MetaInfo(cache_ttl_seconds=300, source="cryptopanic")
)
-
- except Exception as e:
- logger.error(f"Error in get_news: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/news/{news_id}")
-async def get_news_article(news_id: str):
- """Get specific news article details"""
- try:
- # Should fetch from database or API
- return {
- 'id': news_id,
- 'title': 'Bitcoin Reaches New High',
- 'content': 'Full article content...',
- 'url': 'https://example.com/news',
- 'source': 'CryptoNews',
- 'published_at': datetime.now().isoformat(),
- 'meta': MetaInfo().__dict__
- }
-
- except Exception as e:
- logger.error(f"Error in get_news_article: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/news/analyze")
-async def analyze_news(
- text: Optional[str] = Body(None),
- url: Optional[str] = Body(None)
-):
- """Analyze news article for sentiment and topics"""
- try:
- import random
-
- sentiment_labels = ["positive", "negative", "neutral"]
- return {
- 'sentiment': {
- 'score': random.uniform(-1, 1),
- 'label': random.choice(sentiment_labels)
- },
- 'topics': ['bitcoin', 'market', 'trading'],
- 'summary': 'Article discusses cryptocurrency market trends...',
- 'meta': MetaInfo(source="hf:nlp").__dict__
- }
+ await cache_manager.set(cache_key, response, ttl=300)
+ return response
except Exception as e:
- logger.error(f"Error in analyze_news: {e}")
- raise HTTPException(status_code=500, detail=str(e))
+ logger.error(f"Error in get_news: {e}")
+ return NewsResponse(articles=[], meta=MetaInfo(source="error"))
[email protected]("/api/sentiment/analyze", response_model=SentimentResponse)
-async def analyze_sentiment(request: SentimentRequest):
- """Analyze text sentiment"""
- try:
- import random
-
- # Use HF sentiment model or fallback to simple analysis
- sentiment_labels = ["positive", "negative", "neutral"]
- label = random.choice(sentiment_labels)
[email protected]("/api/sentiment/global")
+async def get_global_sentiment():
+ """Get global market sentiment (Fear & Greed Index)"""
+ cache_key = "sentiment_global"
+ cached = await cache_manager.get(cache_key)
+ if cached:
+ return cached
- score_map = {"positive": random.uniform(0.5, 1), "negative": random.uniform(-1, -0.5), "neutral": random.uniform(-0.3, 0.3)}
-
- return SentimentResponse(
- score=score_map[label],
- label=label,
- details={'mode': request.mode, 'text_length': len(request.text)},
- meta=MetaInfo(source="hf:sentiment-model")
- )
-
- except Exception as e:
- logger.error(f"Error in analyze_sentiment: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
-# ============================================================================
-# Whale Tracking Endpoints
-# ============================================================================
-
[email protected]("/api/crypto/whales/transactions")
-async def get_whale_transactions(
- limit: int = Query(50, description="Number of transactions"),
- chain: Optional[str] = Query(None, description="Filter by blockchain"),
- min_amount_usd: float = Query(100000, description="Minimum transaction amount in USD")
-):
- """Get recent large whale transactions"""
try:
- # Get from database
- transactions = persistence.get_whale_transactions(
- limit=limit,
- chain=chain,
- min_amount_usd=min_amount_usd
- )
+ data = await alternative_me_provider.get_fear_and_greed()
+ fng_value = 50
+ classification = "Neutral"
- return {
- 'transactions': transactions,
- 'total': len(transactions),
- 'meta': MetaInfo(cache_ttl_seconds=60).__dict__
+ if data.get('data'):
+ item = data['data'][0]
+ fng_value = int(item.get('value', 50))
+ classification = item.get('value_classification', 'Neutral')
+
+ result = {
+ "score": fng_value,
+ "label": classification,
+ "meta": MetaInfo(cache_ttl_seconds=3600, source="alternative.me").dict()
}
-
- except Exception as e:
- logger.error(f"Error in get_whale_transactions: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/crypto/whales/stats", response_model=WhaleStatsResponse)
-async def get_whale_stats(hours: int = Query(24, description="Time window in hours")):
- """Get aggregated whale activity statistics"""
- try:
- # Get from database
- stats = persistence.get_whale_stats(hours=hours)
- return WhaleStatsResponse(
- total_transactions=stats.get('total_transactions', 0),
- total_volume_usd=stats.get('total_volume_usd', 0),
- avg_transaction_usd=stats.get('avg_transaction_usd', 0),
- top_chains=stats.get('top_chains', []),
- meta=MetaInfo(cache_ttl_seconds=300)
- )
-
+ await cache_manager.set(cache_key, result, ttl=3600)
+ return result
except Exception as e:
- logger.error(f"Error in get_whale_stats: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
+ logger.error(f"Error in get_global_sentiment: {e}")
+ raise HTTPException(status_code=503, detail="Sentiment data unavailable")
# ============================================================================
-# Blockchain (Gas & Stats) Endpoints
+# Blockchain Endpoints
# ============================================================================
@router.get("/api/crypto/blockchain/gas", response_model=GasResponse)
async def get_gas_prices(chain: str = Query("ethereum", description="Blockchain network")):
- """Get current gas prices for specified blockchain"""
- try:
- import random
-
- # Sample gas prices
- base_gas = 20 if chain == "ethereum" else 5
-
- return GasResponse(
- chain=chain,
- gas_prices=GasPrice(
- fast=base_gas + random.uniform(5, 15),
- standard=base_gas + random.uniform(2, 8),
- slow=base_gas + random.uniform(0, 5)
- ),
- timestamp=datetime.now().isoformat(),
- meta=MetaInfo(cache_ttl_seconds=30)
- )
-
- except Exception as e:
- logger.error(f"Error in get_gas_prices: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/crypto/blockchain/stats", response_model=BlockchainStats)
-async def get_blockchain_stats(
- chain: str = Query("ethereum", description="Blockchain network"),
- hours: int = Query(24, description="Time window")
-):
- """Get blockchain statistics"""
- try:
- import random
-
- return BlockchainStats(
- chain=chain,
- blocks_24h=random.randint(6000, 7000),
- transactions_24h=random.randint(1000000, 1500000),
- avg_gas_price=random.uniform(15, 30),
- mempool_size=random.randint(50000, 150000),
- meta=MetaInfo(cache_ttl_seconds=120)
- )
-
- except Exception as e:
- logger.error(f"Error in get_blockchain_stats: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
+ """Get gas prices - Placeholder for real implementation"""
+ # TODO: Implement Etherscan or similar provider
+ # For now, return empty/null to indicate no data rather than fake data
+ return GasResponse(
+ chain=chain,
+ gas_prices=None,
+ timestamp=datetime.now().isoformat(),
+ meta=MetaInfo(source="unavailable")
+ )
# ============================================================================
-# System Management & Provider Endpoints
+# System Management
# ============================================================================
[email protected]("/api/providers")
-async def get_providers():
- """List all data providers and their capabilities"""
- try:
- providers = []
-
- for category, config in fallback_manager.providers.items():
- primary = config.get('primary')
- if primary:
- providers.append(ProviderInfo(
- id=f"{category}_primary",
- name=primary['name'],
- category=category,
- status='active',
- capabilities=[category]
- ).dict())
-
- for idx, fallback in enumerate(config.get('fallbacks', [])):
- providers.append(ProviderInfo(
- id=f"{category}_fallback_{idx}",
- name=fallback['name'],
- category=category,
- status='active',
- capabilities=[category]
- ).dict())
-
- return {
- 'providers': providers,
- 'total': len(providers),
- 'meta': MetaInfo().__dict__
- }
-
- except Exception as e:
- logger.error(f"Error in get_providers: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
@router.get("/api/status")
async def get_system_status():
"""Get overall system status"""
- try:
- return {
- 'status': 'operational',
- 'timestamp': datetime.now().isoformat(),
- 'services': {
- 'market_data': 'operational',
- 'whale_tracking': 'operational',
- 'blockchain': 'operational',
- 'news': 'operational',
- 'sentiment': 'operational',
- 'models': 'operational'
- },
- 'uptime_seconds': 86400,
- 'version': '1.0.0',
- 'meta': MetaInfo().__dict__
- }
+ from backend.live_data.providers import get_all_providers_status
+
+ provider_status = await get_all_providers_status()
- except Exception as e:
- logger.error(f"Error in get_system_status: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/health")
-async def health_check():
- """Health check endpoint"""
return {
- 'status': 'healthy',
+ 'status': 'operational',
'timestamp': datetime.now().isoformat(),
- 'checks': {
- 'database': True,
- 'fallback_providers': True,
- 'models': True
- }
- }
-
-
[email protected]("/api/freshness")
-async def get_data_freshness():
- """Get last-updated timestamps for each subsystem"""
- try:
- now = datetime.now()
-
- return {
- 'market_data': (now - timedelta(seconds=30)).isoformat(),
- 'whale_tracking': (now - timedelta(minutes=1)).isoformat(),
- 'blockchain_stats': (now - timedelta(minutes=2)).isoformat(),
- 'news': (now - timedelta(minutes=5)).isoformat(),
- 'sentiment': (now - timedelta(minutes=1)).isoformat(),
- 'signals': (now - timedelta(seconds=10)).isoformat(),
- 'meta': MetaInfo().__dict__
- }
-
- except Exception as e:
- logger.error(f"Error in get_data_freshness: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
-# ============================================================================
-# Export & Diagnostics Endpoints
-# ============================================================================
-
[email protected]("/api/v2/export/{export_type}")
-async def export_data(
- export_type: str,
- format: str = Query("json", description="Export format: json or csv")
-):
- """Export dataset"""
- try:
- data = {}
-
- if export_type == "signals":
- data = {'signals': persistence.get_signals(limit=10000)}
- elif export_type == "whales":
- data = {'whale_transactions': persistence.get_whale_transactions(limit=10000)}
- elif export_type == "all":
- data = {
- 'signals': persistence.get_signals(limit=10000),
- 'whale_transactions': persistence.get_whale_transactions(limit=10000),
- 'database_stats': persistence.get_database_stats(),
- 'exported_at': datetime.now().isoformat()
- }
- else:
- raise HTTPException(status_code=400, detail="Invalid export type")
-
- # Save to file
- export_dir = Path("data/exports")
- export_dir.mkdir(parents=True, exist_ok=True)
-
- filename = f"export_{export_type}_{int(datetime.now().timestamp())}.{format}"
- filepath = export_dir / filename
-
- if format == "json":
- with open(filepath, 'w') as f:
- json.dump(data, f, indent=2)
-
- return {
- 'status': 'success',
- 'export_type': export_type,
- 'format': format,
- 'filepath': str(filepath),
- 'records': len(data),
- 'meta': MetaInfo().__dict__
- }
-
- except HTTPException:
- raise
- except Exception as e:
- logger.error(f"Error in export_data: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/diagnostics/run")
-async def run_diagnostics():
- """Run system diagnostics and self-tests"""
- try:
- results = {
- 'timestamp': datetime.now().isoformat(),
- 'tests': []
- }
-
- # Test fallback providers connectivity
- for category in ['market_data', 'news', 'sentiment']:
- try:
- _, source = await fallback_manager.fetch_with_fallback(category, '/', {})
- results['tests'].append({
- 'name': f'{category}_connectivity',
- 'status': 'passed',
- 'source': source
- })
- except:
- results['tests'].append({
- 'name': f'{category}_connectivity',
- 'status': 'failed'
- })
-
- # Test model health
- results['tests'].append({
- 'name': 'model_health',
- 'status': 'passed',
- 'models_available': 3
- })
-
- # Test database
- db_stats = persistence.get_database_stats()
- results['tests'].append({
- 'name': 'database_connectivity',
- 'status': 'passed',
- 'stats': db_stats
- })
-
- passed = sum(1 for t in results['tests'] if t['status'] == 'passed')
- failed = len(results['tests']) - passed
-
- results['summary'] = {
- 'total_tests': len(results['tests']),
- 'passed': passed,
- 'failed': failed,
- 'success_rate': round(passed / len(results['tests']) * 100, 1)
- }
-
- # Save diagnostic results
- persistence.set_cache('last_diagnostics', results, ttl_seconds=3600)
-
- return results
-
- except Exception as e:
- logger.error(f"Error in run_diagnostics: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/diagnostics/last")
-async def get_last_diagnostics():
- """Get last diagnostic results"""
- try:
- last_results = persistence.get_cache('last_diagnostics')
- if last_results:
- return last_results
- else:
- return {
- 'message': 'No diagnostics have been run yet',
- 'meta': MetaInfo().__dict__
- }
- except Exception as e:
- logger.error(f"Error in get_last_diagnostics: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
-# ============================================================================
-# Charts & Analytics Endpoints
-# ============================================================================
-
[email protected]("/api/charts/health-history")
-async def get_health_history(hours: int = Query(24, description="Time window in hours")):
- """Get provider health history for charts"""
- try:
- stats = persistence.get_provider_health_stats(hours=hours)
-
- # Format for charting
- chart_data = {
- 'period_hours': hours,
- 'series': []
- }
-
- for provider in stats.get('providers', []):
- success_rate = 0
- if provider['total_requests'] > 0:
- success_rate = round((provider['success_count'] / provider['total_requests']) * 100, 1)
-
- chart_data['series'].append({
- 'provider': provider['provider'],
- 'category': provider['category'],
- 'success_rate': success_rate,
- 'avg_response_time': round(provider.get('avg_response_time', 0)),
- 'total_requests': provider['total_requests']
- })
-
- return {
- 'chart_data': chart_data,
- 'meta': MetaInfo(cache_ttl_seconds=300).__dict__
- }
-
- except Exception as e:
- logger.error(f"Error in get_health_history: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/charts/compliance")
-async def get_compliance_metrics(days: int = Query(7, description="Time window in days")):
- """Get API compliance metrics over time"""
- try:
- # Calculate compliance based on data availability
- db_stats = persistence.get_database_stats()
-
- compliance = {
- 'period_days': days,
- 'metrics': {
- 'data_freshness': 95.5, # % of endpoints with fresh data
- 'uptime': 99.2, # % uptime
- 'coverage': 87.3, # % of required endpoints implemented
- 'response_time': 98.1 # % meeting SLA
- },
- 'details': {
- 'signals_available': db_stats.get('signals_count', 0) > 0,
- 'whales_available': db_stats.get('whale_transactions_count', 0) > 0,
- 'cache_healthy': db_stats.get('cache_entries', 0) > 0,
- 'total_health_checks': db_stats.get('health_logs_count', 0)
- },
- 'meta': MetaInfo(cache_ttl_seconds=3600).__dict__
- }
-
- return compliance
-
- except Exception as e:
- logger.error(f"Error in get_compliance_metrics: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
-# ============================================================================
-# Logs & Monitoring Endpoints
-# ============================================================================
-
[email protected]("/api/logs")
-async def get_logs(
- from_time: Optional[str] = Query(None, description="Start time ISO format"),
- to_time: Optional[str] = Query(None, description="End time ISO format"),
- limit: int = Query(100, description="Max number of logs")
-):
- """Get system logs within time range"""
- try:
- # Get provider health logs as system logs
- hours = 24
- if from_time:
- try:
- from_dt = datetime.fromisoformat(from_time.replace('Z', '+00:00'))
- hours = int((datetime.now() - from_dt).total_seconds() / 3600) + 1
- except:
- pass
-
- health_stats = persistence.get_provider_health_stats(hours=hours)
-
- logs = []
- for provider in health_stats.get('providers', [])[:limit]:
- logs.append({
- 'timestamp': datetime.now().isoformat(),
- 'level': 'INFO',
- 'provider': provider['provider'],
- 'category': provider['category'],
- 'message': f"Provider {provider['provider']} processed {provider['total_requests']} requests",
- 'details': provider
- })
-
- return {
- 'logs': logs,
- 'total': len(logs),
- 'from': from_time or 'beginning',
- 'to': to_time or 'now',
- 'meta': MetaInfo(cache_ttl_seconds=60).__dict__
- }
-
- except Exception as e:
- logger.error(f"Error in get_logs: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/logs/recent")
-async def get_recent_logs(limit: int = Query(50, description="Number of recent logs")):
- """Get most recent system logs"""
- try:
- return await get_logs(limit=limit)
- except Exception as e:
- logger.error(f"Error in get_recent_logs: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
-# ============================================================================
-# Rate Limits & Config Endpoints
-# ============================================================================
-
[email protected]("/api/rate-limits")
-async def get_rate_limits():
- """Get current rate limit configuration"""
- try:
- rate_limits = {
- 'global': {
- 'requests_per_minute': 60,
- 'requests_per_hour': 3600,
- 'burst_limit': 100
- },
- 'endpoints': {
- '/api/market/*': {'rpm': 120, 'burst': 200},
- '/api/signals/*': {'rpm': 60, 'burst': 100},
- '/api/news/*': {'rpm': 30, 'burst': 50},
- '/api/crypto/whales/*': {'rpm': 30, 'burst': 50},
- '/api/models/*': {'rpm': 20, 'burst': 30}
- },
- 'current_usage': {
- 'requests_last_minute': 15,
- 'requests_last_hour': 450,
- 'remaining_minute': 45,
- 'remaining_hour': 3150
- },
- 'meta': MetaInfo(cache_ttl_seconds=30).__dict__
- }
-
- return rate_limits
-
- except Exception as e:
- logger.error(f"Error in get_rate_limits: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/config/keys")
-async def get_api_keys():
- """Get configured API keys (masked)"""
- try:
- # Return masked keys for security
- keys = {
- 'hf_api_token': 'hf_***' if os.getenv('HF_API_TOKEN') else None,
- 'configured_providers': []
- }
-
- # Check fallback provider keys
- for category, config in fallback_manager.providers.items():
- primary = config.get('primary', {})
- if primary.get('key'):
- keys['configured_providers'].append({
- 'category': category,
- 'provider': primary['name'],
- 'has_key': True
- })
-
- return {
- 'keys': keys,
- 'total_configured': len(keys['configured_providers']),
- 'meta': MetaInfo().__dict__
- }
-
- except Exception as e:
- logger.error(f"Error in get_api_keys: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/config/keys/test")
-async def test_api_keys(provider: str = Body(..., embed=True)):
- """Test API key connectivity for a provider"""
- try:
- # Find provider category
- found_category = None
- for category, config in fallback_manager.providers.items():
- primary = config.get('primary', {})
- if primary.get('name') == provider:
- found_category = category
- break
-
- if not found_category:
- raise HTTPException(status_code=404, detail="Provider not found")
-
- # Test connectivity
- start_time = datetime.now()
- try:
- _, source = await fallback_manager.fetch_with_fallback(found_category, '/', {})
- response_time = int((datetime.now() - start_time).total_seconds() * 1000)
-
- # Log the test
- persistence.log_provider_health(
- provider=provider,
- category=found_category,
- status='success',
- response_time_ms=response_time
- )
-
- return {
- 'status': 'success',
- 'provider': provider,
- 'category': found_category,
- 'response_time_ms': response_time,
- 'message': 'API key is valid and working'
- }
- except Exception as test_error:
- # Log the failure
- persistence.log_provider_health(
- provider=provider,
- category=found_category,
- status='failed',
- error_message=str(test_error)
- )
-
- return {
- 'status': 'failed',
- 'provider': provider,
- 'category': found_category,
- 'error': str(test_error),
- 'message': 'API key test failed'
- }
-
- except HTTPException:
- raise
- except Exception as e:
- logger.error(f"Error in test_api_keys: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
-# ============================================================================
-# Pool Management Endpoints
-# ============================================================================
-
-# Global pools storage (in production, use database)
-_pools_storage = {
- 'pool_1': {
- 'id': 'pool_1',
- 'name': 'Primary Market Data Pool',
- 'providers': ['coingecko', 'binance', 'coincap'],
- 'strategy': 'round-robin',
- 'health': 'healthy',
- 'created_at': datetime.now().isoformat()
+ 'providers': provider_status,
+ 'version': '1.0.0',
+ 'meta': MetaInfo(source="system").dict()
}
-}
-
-
[email protected]("/api/pools")
-async def list_pools():
- """List all provider pools"""
- try:
- pools = list(_pools_storage.values())
- return {
- 'pools': pools,
- 'total': len(pools),
- 'meta': MetaInfo().__dict__
- }
- except Exception as e:
- logger.error(f"Error in list_pools: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/pools/{pool_id}")
-async def get_pool(pool_id: str):
- """Get specific pool details"""
- try:
- if pool_id not in _pools_storage:
- raise HTTPException(status_code=404, detail="Pool not found")
-
- return {
- 'pool': _pools_storage[pool_id],
- 'meta': MetaInfo().__dict__
- }
- except HTTPException:
- raise
- except Exception as e:
- logger.error(f"Error in get_pool: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/pools")
-async def create_pool(
- name: str = Body(...),
- providers: List[str] = Body(...),
- strategy: str = Body('round-robin')
-):
- """Create a new provider pool"""
- try:
- import uuid
- pool_id = f"pool_{uuid.uuid4().hex[:8]}"
-
- pool = {
- 'id': pool_id,
- 'name': name,
- 'providers': providers,
- 'strategy': strategy,
- 'health': 'healthy',
- 'created_at': datetime.now().isoformat()
- }
-
- _pools_storage[pool_id] = pool
-
- return {
- 'status': 'success',
- 'pool_id': pool_id,
- 'pool': pool,
- 'meta': MetaInfo().__dict__
- }
- except Exception as e:
- logger.error(f"Error in create_pool: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/pools/{pool_id}")
-async def update_pool(
- pool_id: str,
- name: Optional[str] = Body(None),
- providers: Optional[List[str]] = Body(None),
- strategy: Optional[str] = Body(None)
-):
- """Update pool configuration"""
- try:
- if pool_id not in _pools_storage:
- raise HTTPException(status_code=404, detail="Pool not found")
-
- pool = _pools_storage[pool_id]
-
- if name:
- pool['name'] = name
- if providers:
- pool['providers'] = providers
- if strategy:
- pool['strategy'] = strategy
-
- pool['updated_at'] = datetime.now().isoformat()
-
- return {
- 'status': 'success',
- 'pool': pool,
- 'meta': MetaInfo().__dict__
- }
- except HTTPException:
- raise
- except Exception as e:
- logger.error(f"Error in update_pool: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/pools/{pool_id}")
-async def delete_pool(pool_id: str):
- """Delete a pool"""
- try:
- if pool_id not in _pools_storage:
- raise HTTPException(status_code=404, detail="Pool not found")
-
- del _pools_storage[pool_id]
-
- return {
- 'status': 'success',
- 'message': f'Pool {pool_id} deleted',
- 'meta': MetaInfo().__dict__
- }
- except HTTPException:
- raise
- except Exception as e:
- logger.error(f"Error in delete_pool: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/pools/{pool_id}/rotate")
-async def rotate_pool(pool_id: str):
- """Rotate to next provider in pool"""
- try:
- if pool_id not in _pools_storage:
- raise HTTPException(status_code=404, detail="Pool not found")
-
- pool = _pools_storage[pool_id]
- providers = pool.get('providers', [])
-
- if len(providers) > 1:
- # Rotate providers
- providers.append(providers.pop(0))
- pool['providers'] = providers
- pool['last_rotated'] = datetime.now().isoformat()
-
- return {
- 'status': 'success',
- 'pool_id': pool_id,
- 'current_provider': providers[0] if providers else None,
- 'meta': MetaInfo().__dict__
- }
- except HTTPException:
- raise
- except Exception as e:
- logger.error(f"Error in rotate_pool: {e}")
- raise HTTPException(status_code=500, detail=str(e))
-
-
[email protected]("/api/pools/{pool_id}/failover")
-async def failover_pool(pool_id: str, failed_provider: str = Body(..., embed=True)):
- """Trigger failover for a failed provider"""
- try:
- if pool_id not in _pools_storage:
- raise HTTPException(status_code=404, detail="Pool not found")
-
- pool = _pools_storage[pool_id]
- providers = pool.get('providers', [])
-
- if failed_provider in providers:
- # Move failed provider to end
- providers.remove(failed_provider)
- providers.append(failed_provider)
- pool['providers'] = providers
- pool['last_failover'] = datetime.now().isoformat()
- pool['health'] = 'degraded'
-
- return {
- 'status': 'success',
- 'pool_id': pool_id,
- 'failed_provider': failed_provider,
- 'new_primary': providers[0] if providers else None,
- 'meta': MetaInfo().__dict__
- }
- else:
- raise HTTPException(status_code=400, detail="Provider not in pool")
-
- except HTTPException:
- raise
- except Exception as e:
- logger.error(f"Error in failover_pool: {e}")
- raise HTTPException(status_code=500, detail=str(e))
diff --git a/backend/services/ohlcv_service.py b/backend/services/ohlcv_service.py
index afe4bfc..075903e 100644
--- a/backend/services/ohlcv_service.py
+++ b/backend/services/ohlcv_service.py
@@ -7,6 +7,7 @@ import logging
from typing import Dict, List, Any, Optional
from fastapi import HTTPException
from .api_fallback_manager import get_fallback_manager
+import os
logger = logging.getLogger(__name__)
@@ -20,7 +21,7 @@ class OHLCVService:
def _setup_providers(self):
"""Setup OHLCV providers in priority order"""
- # Priority 1: Binance (fastest, most reliable - but may have regional restrictions)
+ # Priority 1: Binance (fastest, most reliable)
self.manager.add_provider(
name="Binance",
priority=1,
@@ -29,7 +30,7 @@ class OHLCVService:
max_failures=3
)
- # Priority 2: CoinGecko (reliable alternative, no geo-restrictions)
+ # Priority 2: CoinGecko (reliable alternative)
self.manager.add_provider(
name="CoinGecko",
priority=2,
@@ -38,7 +39,7 @@ class OHLCVService:
max_failures=3
)
- # Priority 3: HuggingFace Space (fallback)
+ # Priority 3: HuggingFace Space (proxy to other services)
self.manager.add_provider(
name="HuggingFace",
priority=3,
@@ -47,16 +48,7 @@ class OHLCVService:
max_failures=5
)
- # Priority 4: Mock/Demo data (always available)
- self.manager.add_provider(
- name="Demo",
- priority=999,
- fetch_function=self._fetch_demo,
- cooldown_seconds=0,
- max_failures=999 # Never fails
- )
-
- logger.info("✅ OHLCV Service initialized with 4 providers (Binance, CoinGecko, HuggingFace, Demo)")
+ logger.info("✅ OHLCV Service initialized with 3 providers (Binance, CoinGecko, HuggingFace)")
async def _fetch_binance(self, symbol: str, timeframe: str, limit: int = 100) -> Dict:
"""Fetch from Binance API"""
@@ -128,10 +120,10 @@ class OHLCVService:
candles.append({
"timestamp": int(timestamp),
"open": price,
- "high": price * 1.01, # Approximate
- "low": price * 0.99, # Approximate
+ "high": price, # Approximate
+ "low": price, # Approximate
"close": price,
- "volume": 0 # CoinGecko doesn't provide volume in this endpoint
+ "volume": 0
})
return candles
@@ -139,7 +131,6 @@ class OHLCVService:
async def _fetch_huggingface(self, symbol: str, timeframe: str, limit: int = 100) -> Dict:
"""Fetch from HuggingFace Space"""
import httpx
- import os
base_url = os.getenv("HF_SPACE_BASE_URL", "https://really-amin-datasourceforcryptocurrency.hf.space")
token = os.getenv("HF_API_TOKEN", "").strip()
@@ -156,43 +147,6 @@ class OHLCVService:
response.raise_for_status()
return response.json()
- async def _fetch_demo(self, symbol: str, timeframe: str, limit: int = 100) -> Dict:
- """Fetch demo/fallback data"""
- import time
- import random
-
- # Generate realistic demo candles
- base_price = 50000 if symbol.upper() == "BTC" else 3000
- candles = []
-
- for i in range(limit):
- timestamp = int(time.time()) - (i * 3600) # 1 hour intervals
- open_price = base_price + random.uniform(-1000, 1000)
- close_price = open_price + random.uniform(-500, 500)
- high_price = max(open_price, close_price) + random.uniform(0, 300)
- low_price = min(open_price, close_price) - random.uniform(0, 300)
- volume = random.uniform(1000, 10000)
-
- candles.append({
- "t": timestamp * 1000,
- "o": round(open_price, 2),
- "h": round(high_price, 2),
- "l": round(low_price, 2),
- "c": round(close_price, 2),
- "v": round(volume, 2)
- })
-
- return {
- "symbol": symbol.upper(),
- "timeframe": timeframe,
- "interval": timeframe,
- "limit": limit,
- "count": len(candles),
- "ohlcv": candles[::-1], # Reverse to oldest first
- "source": "demo",
- "warning": "Using demo data - live data unavailable"
- }
-
async def get_ohlcv(
self,
symbol: str,
@@ -236,4 +190,3 @@ def get_ohlcv_service() -> OHLCVService:
if _ohlcv_service is None:
_ohlcv_service = OHLCVService()
return _ohlcv_service
-
diff --git a/backend/services/provider_fallback_manager.py b/backend/services/provider_fallback_manager.py
index 6a1f405..beeeb20 100644
--- a/backend/services/provider_fallback_manager.py
+++ b/backend/services/provider_fallback_manager.py
@@ -235,26 +235,9 @@ class ProviderFallbackManager:
try:
# This would call actual HF models/datasets
- # For now, simulate HF response
- logger.debug(f"Attempting HF for {endpoint}")
-
- # Simulate HF response based on endpoint
- if "/pair" in endpoint:
- # Pair metadata MUST come from HF
- return {
- "pair": params.get("pair", "BTC/USDT"),
- "base": "BTC",
- "quote": "USDT",
- "tick_size": 0.01,
- "min_qty": 0.00001
- }, None
-
- # For other endpoints, simulate occasional failure to test fallback
- import random
- if random.random() > 0.3: # 70% success rate for testing
- return None, "HF data not available"
-
- return {"source": "hf", "data": "sample"}, None
+ # For now, HF integration is not fully implemented in this method
+ # Return None to trigger fallback to external providers
+ return None, "HF integration pending"
except Exception as e:
logger.debug(f"HF call failed: {e}")
diff --git a/hf_unified_server.py b/hf_unified_server.py
index 21e324c..36aaf2f 100644
--- a/hf_unified_server.py
+++ b/hf_unified_server.py
@@ -891,118 +891,36 @@ async def api_sentiment_global(timeframe: str = "1D"):
except Exception as e:
logger.error(f"Failed to fetch Fear & Greed Index: {e}")
- # Fallback to generated data
- base_sentiment = random.randint(40, 70)
- history = []
- base_time = int(datetime.utcnow().timestamp() * 1000)
-
- data_points = {
- "1D": 24,
- "7D": 168,
- "30D": 30,
- "1Y": 365
- }.get(timeframe, 24)
-
- interval = {
- "1D": 3600000, # 1 hour
- "7D": 3600000, # 1 hour
- "30D": 86400000, # 1 day
- "1Y": 86400000 # 1 day
- }.get(timeframe, 3600000)
-
- for i in range(data_points):
- history.append({
- "timestamp": base_time - ((data_points - i) * interval),
- "sentiment": max(20, min(80, base_sentiment + random.randint(-10, 10))),
- "volume": random.randint(50000, 150000)
- })
-
- if base_sentiment >= 65:
- sentiment = "greed"
- market_mood = "bullish"
- elif base_sentiment >= 45:
- sentiment = "neutral"
- market_mood = "neutral"
- else:
- sentiment = "fear"
- market_mood = "bearish"
-
+ # Fallback - return error or empty (NO MOCK DATA)
+ logger.warning("Sentiment data unavailable and mock data is disabled.")
return {
- "fear_greed_index": base_sentiment,
- "sentiment": sentiment,
- "market_mood": market_mood,
- "confidence": 0.72,
- "history": history,
+ "fear_greed_index": 50,
+ "sentiment": "neutral",
+ "market_mood": "neutral",
+ "confidence": 0,
+ "history": [],
"timestamp": datetime.utcnow().isoformat() + "Z",
- "source": "fallback"
+ "source": "unavailable",
+ "error": "Real data unavailable"
}
@app.get("/api/sentiment/asset/{symbol}")
async def api_sentiment_asset(symbol: str):
"""Get sentiment analysis for a specific asset"""
- import random
-
- try:
- # Normalize symbol
- symbol = symbol.upper().replace('USDT', '').replace('USD', '')
-
- # Generate sentiment score based on symbol (with some consistency based on symbol hash)
- hash_val = sum(ord(c) for c in symbol) % 50
- sentiment_value = 40 + hash_val + random.randint(-10, 10)
- sentiment_value = max(20, min(90, sentiment_value))
-
- # Determine sentiment category
- if sentiment_value >= 75:
- sentiment = "very_positive"
- color = "#10b981"
- elif sentiment_value >= 60:
- sentiment = "positive"
- color = "#3b82f6"
- elif sentiment_value >= 40:
- sentiment = "neutral"
- color = "#94a3b8"
- elif sentiment_value >= 25:
- sentiment = "negative"
- color = "#f59e0b"
- else:
- sentiment = "very_negative"
- color = "#ef4444"
-
- # Generate social metrics
- social_score = random.randint(40, 90)
- news_score = random.randint(35, 85)
-
- return {
- "success": True,
- "symbol": symbol,
- "sentiment": sentiment,
- "sentiment_value": sentiment_value,
- "color": color,
- "social_score": social_score,
- "news_score": news_score,
- "sources": {
- "twitter": random.randint(1000, 50000),
- "reddit": random.randint(500, 10000),
- "news": random.randint(10, 200)
- },
- "timestamp": datetime.utcnow().isoformat() + "Z"
- }
-
- except Exception as e:
- logger.error(f"Error getting sentiment for {symbol}: {e}")
- return {
- "success": False,
- "symbol": symbol,
- "sentiment": "neutral",
- "sentiment_value": 50,
- "color": "#94a3b8",
- "social_score": 50,
- "news_score": 50,
- "sources": {"twitter": 0, "reddit": 0, "news": 0},
- "error": str(e),
- "timestamp": datetime.utcnow().isoformat() + "Z"
- }
+ # NO MOCK DATA
+ return {
+ "success": False,
+ "symbol": symbol,
+ "sentiment": "neutral",
+ "sentiment_value": 50,
+ "color": "#94a3b8",
+ "social_score": 0,
+ "news_score": 0,
+ "sources": {"twitter": 0, "reddit": 0, "news": 0},
+ "error": "Asset sentiment unavailable (mock data removed)",
+ "timestamp": datetime.utcnow().isoformat() + "Z"
+ }
@app.get("/api/models/list")
@@ -1085,26 +1003,16 @@ async def api_models_reinitialize():
@app.get("/api/ai/signals")
async def api_ai_signals(symbol: str = "BTC"):
- """AI trading signals for a symbol"""
- import random
+ """AI trading signals for a symbol - Real signals only"""
+ # No mock signals
signals = []
- signal_types = ["buy", "sell", "hold"]
- for i in range(3):
- signals.append({
- "id": f"sig_{int(time.time())}_{i}",
- "symbol": symbol,
- "type": random.choice(signal_types),
- "score": round(random.uniform(0.65, 0.95), 2),
- "model": ["cryptobert_elkulako", "finbert", "twitter_sentiment"][i % 3],
- "created_at": datetime.utcnow().isoformat() + "Z",
- "confidence": round(random.uniform(0.7, 0.95), 2)
- })
return {
"symbol": symbol,
"signals": signals,
- "total": len(signals),
- "timestamp": datetime.utcnow().isoformat() + "Z"
+ "total": 0,
+ "timestamp": datetime.utcnow().isoformat() + "Z",
+ "message": "No active signals from real models"
}
@@ -1120,34 +1028,18 @@ class AIDecisionRequest(BaseModel):
@app.post("/api/ai/decision")
async def api_ai_decision(payload: AIDecisionRequest) -> Dict[str, Any]:
"""AI trading decision for AI Analyst page."""
- import random
-
- base_conf = 0.7
- risk = payload.risk_tolerance.lower()
- confidence = base_conf + (0.1 if risk == "aggressive" else -0.05 if risk == "conservative" else 0.0)
- confidence = max(0.5, min(confidence, 0.95))
-
+
+ # NO MOCK DATA - Return safe default
decision = "HOLD"
- if confidence > 0.8:
- decision = "BUY"
- elif confidence < 0.6:
- decision = "SELL"
-
- summary = (
- f"Based on recent market conditions and a {payload.horizon} horizon, "
- f"the AI suggests a {decision} stance for {payload.symbol} with "
- f"{int(confidence * 100)}% confidence."
- )
+ confidence = 0.0
+ summary = "AI analysis unavailable. Real models required."
signals: List[Dict[str, Any]] = [
- {"type": "bullish" if decision == "BUY" else "bearish" if decision == "SELL" else "neutral",
- "text": f"Primary signal indicates {decision} bias."},
- {"type": "neutral", "text": "Consider position sizing according to your risk tolerance."},
+ {"type": "neutral", "text": "AI models not connected or unavailable."},
]
risks: List[str] = [
- "Market volatility may increase around major macro events.",
- "On-chain or regulatory news can invalidate this view quickly.",
+ "Data unavailable.",
]
targets = {
diff --git a/static/pages/trading-assistant/FINAL_VERSION_FEATURES.json b/static/pages/trading-assistant/FINAL_VERSION_FEATURES.json
deleted file mode 100644
index 7bc7d26..0000000
--- a/static/pages/trading-assistant/FINAL_VERSION_FEATURES.json
+++ /dev/null
@@ -1,408 +0,0 @@
-{
- "version": "6.0.0 - FINAL PROFESSIONAL EDITION",
- "release_date": "2025-12-02",
- "status": "PRODUCTION READY - ULTIMATE",
-
- "major_improvements": {
- "svg_icons": {
- "total_icons": "20+ custom SVG icons",
- "locations": [
- "Logo icon (lightning bolt)",
- "Live indicator",
- "Header stats (clock, activity)",
- "Card titles (robot, dollar, target, chart, signal)",
- "Crypto cards (custom per coin)",
- "Strategy cards (target icons)",
- "Agent avatar (robot)",
- "Buttons (play, stop, refresh, analyze)",
- "Signal badges (arrows)",
- "Signal items (price, confidence, stop, target icons)",
- "Empty state (signal waves)",
- "Toast notifications"
- ],
- "benefits": [
- "خیلی حرفهایتر",
- "جذابیت بصری بالا",
- "انیمیشنهای روان",
- "سبک و سریع",
- "قابل تغییر رنگ",
- "کیفیت بالا در هر سایزی"
- ]
- },
-
- "advanced_css": {
- "features": [
- "CSS Variables برای تمسازی",
- "Backdrop filter با blur effect",
- "Multiple gradient backgrounds",
- "Complex animations (15+ types)",
- "Smooth transitions",
- "Glass morphism effects",
- "Shadow layering",
- "Hover states پیشرفته",
- "Responsive design کامل",
- "Custom scrollbar styling"
- ],
- "animations": {
- "backgroundPulse": "پسزمینه متحرک",
- "headerShine": "درخشش header",
- "logoFloat": "شناور شدن لوگو",
- "livePulse": "تپش نقطه LIVE",
- "iconFloat": "شناور شدن آیکونها",
- "agentRotate": "چرخش avatar ایجنت",
- "signalSlideIn": "ورود سیگنالها",
- "emptyFloat": "شناور شدن empty state",
- "toastSlideIn": "ورود toast",
- "loadingSpin": "چرخش loading"
- },
- "effects": {
- "glass_morphism": "شیشهای با blur",
- "gradient_borders": "border های گرادیانت",
- "glow_shadows": "سایههای درخشان",
- "hover_transforms": "تبدیل در hover",
- "active_states": "حالتهای فعال جذاب",
- "shimmer_effects": "افکت درخشش",
- "pulse_animations": "انیمیشن تپش"
- }
- }
- },
-
- "css_architecture": {
- "variables": {
- "colors": "12 متغیر رنگ",
- "backgrounds": "3 لایه پسزمینه",
- "text": "3 سطح متن",
- "shadows": "4 سایز سایه",
- "radius": "5 اندازه border-radius",
- "transitions": "3 سرعت transition"
- },
-
- "layout": {
- "grid_system": "CSS Grid سه ستونه",
- "responsive": "3 breakpoint",
- "spacing": "فاصلهگذاری یکنواخت",
- "alignment": "تراز مرکزی و flexbox"
- },
-
- "components": {
- "cards": "Glass morphism با hover effects",
- "buttons": "Gradient با ripple effect",
- "badges": "Pill shape با glow",
- "inputs": "Custom styling",
- "scrollbar": "Custom design"
- }
- },
-
- "svg_icons_details": {
- "logo": {
- "icon": "Lightning bolt",
- "animation": "Float up/down",
- "colors": "Gradient blue to cyan",
- "size": "48x48px"
- },
-
- "agent": {
- "icon": "Robot head",
- "animation": "360° rotation",
- "colors": "Gradient blue to cyan",
- "size": "56x56px"
- },
-
- "crypto_icons": {
- "BTC": "₿ symbol",
- "ETH": "Ξ symbol",
- "BNB": "🔸 diamond",
- "SOL": "◎ circle",
- "XRP": "✕ cross",
- "ADA": "₳ symbol"
- },
-
- "signal_icons": {
- "buy": "Arrow up",
- "sell": "Arrow down",
- "price": "Dollar sign",
- "confidence": "Target",
- "stop_loss": "Shield",
- "take_profit": "Flag"
- },
-
- "ui_icons": {
- "refresh": "Circular arrows",
- "play": "Triangle right",
- "stop": "Square",
- "analyze": "Lightning",
- "clock": "Clock face",
- "activity": "Heart rate line",
- "chart": "Line chart",
- "signal": "Radio waves"
- }
- },
-
- "color_system": {
- "primary_palette": {
- "primary": "#3b82f6 - آبی اصلی",
- "primary_light": "#60a5fa - آبی روشن",
- "primary_dark": "#2563eb - آبی تیره",
- "secondary": "#8b5cf6 - بنفش",
- "accent": "#06b6d4 - فیروزهای"
- },
-
- "semantic_colors": {
- "success": "#10b981 - سبز موفقیت",
- "danger": "#ef4444 - قرمز خطر",
- "warning": "#f59e0b - نارنجی هشدار"
- },
-
- "backgrounds": {
- "primary": "#0f172a - تیره",
- "secondary": "#1e293b - متوسط",
- "tertiary": "#334155 - روشنتر"
- },
-
- "text_hierarchy": {
- "primary": "#f1f5f9 - سفید روشن",
- "secondary": "#cbd5e1 - خاکستری روشن",
- "muted": "#94a3b8 - خاکستری"
- },
-
- "gradients": {
- "primary_gradient": "blue → cyan",
- "secondary_gradient": "purple → blue",
- "success_gradient": "green → dark green",
- "danger_gradient": "red → dark red",
- "background_gradient": "dark → darker"
- }
- },
-
- "animation_system": {
- "timing_functions": {
- "fast": "150ms cubic-bezier(0.4, 0, 0.2, 1)",
- "base": "300ms cubic-bezier(0.4, 0, 0.2, 1)",
- "slow": "500ms cubic-bezier(0.4, 0, 0.2, 1)"
- },
-
- "keyframe_animations": {
- "backgroundPulse": {
- "duration": "20s",
- "effect": "opacity change",
- "infinite": true
- },
- "headerShine": {
- "duration": "3s",
- "effect": "diagonal sweep",
- "infinite": true
- },
- "logoFloat": {
- "duration": "3s",
- "effect": "vertical movement",
- "infinite": true
- },
- "livePulse": {
- "duration": "2s",
- "effect": "scale + opacity",
- "infinite": true
- },
- "agentRotate": {
- "duration": "10s",
- "effect": "360° rotation",
- "infinite": true
- },
- "signalSlideIn": {
- "duration": "0.5s",
- "effect": "slide from right",
- "once": true
- }
- },
-
- "hover_effects": {
- "cards": "translateY(-2px) + shadow increase",
- "buttons": "translateY(-2px) + shadow + ripple",
- "crypto_cards": "translateY(-4px) + scale(1.02)",
- "strategy_cards": "translateX(6px) + shadow",
- "signal_cards": "translateX(-4px) + shadow"
- }
- },
-
- "glass_morphism": {
- "properties": {
- "background": "rgba with transparency",
- "backdrop_filter": "blur(20px) saturate(180%)",
- "border": "1px solid rgba(255, 255, 255, 0.1)",
- "box_shadow": "Multiple layers"
- },
-
- "applied_to": [
- "Header",
- "All cards",
- "Toast notifications",
- "Signal cards"
- ],
-
- "visual_effect": "شیشهای مات با عمق"
- },
-
- "responsive_design": {
- "breakpoints": {
- "desktop": "> 1400px - 3 columns",
- "laptop": "1200px - 1400px - 3 columns (narrower)",
- "tablet": "768px - 1200px - 1 column",
- "mobile": "< 768px - 1 column + adjusted spacing"
- },
-
- "adjustments": {
- "mobile": [
- "Single column layout",
- "Reduced padding",
- "Smaller fonts",
- "Stacked header",
- "Full width buttons"
- ]
- }
- },
-
- "performance_optimizations": {
- "css": {
- "will_change": "Used on animated elements",
- "transform": "GPU accelerated",
- "contain": "Layout containment",
- "variables": "Reusable values"
- },
-
- "animations": {
- "60fps": "Smooth 60 FPS",
- "hardware_accelerated": "GPU rendering",
- "optimized_keyframes": "Minimal repaints"
- }
- },
-
- "visual_hierarchy": {
- "level_1": {
- "elements": ["Logo", "Live indicator", "Main stats"],
- "size": "Largest",
- "weight": "800",
- "color": "Gradient"
- },
-
- "level_2": {
- "elements": ["Card titles", "Signal badges", "Prices"],
- "size": "Large",
- "weight": "700",
- "color": "Primary/Accent"
- },
-
- "level_3": {
- "elements": ["Crypto names", "Strategy descriptions", "Signal details"],
- "size": "Medium",
- "weight": "600",
- "color": "Secondary"
- },
-
- "level_4": {
- "elements": ["Labels", "Timestamps", "Helper text"],
- "size": "Small",
- "weight": "400-500",
- "color": "Muted"
- }
- },
-
- "comparison_with_previous": {
- "icons": {
- "before": "❌ Emoji/text icons",
- "after": "✅ Professional SVG icons"
- },
-
- "css": {
- "before": "❌ Basic styling",
- "after": "✅ Advanced CSS با 15+ animation"
- },
-
- "colors": {
- "before": "❌ رنگهای ساده",
- "after": "✅ Gradient system حرفهای"
- },
-
- "effects": {
- "before": "❌ افکتهای ساده",
- "after": "✅ Glass morphism + glow + shimmer"
- },
-
- "animations": {
- "before": "❌ انیمیشن کم",
- "after": "✅ 10+ keyframe animation"
- },
-
- "visual_appeal": {
- "before": "❌ جذابیت کم",
- "after": "✅ خیرهکننده و حرفهای"
- }
- },
-
- "files": {
- "html": {
- "name": "index-final.html",
- "size": "~35KB",
- "lines": "~800",
- "svg_icons": "20+",
- "components": "15+"
- },
-
- "javascript": {
- "name": "trading-assistant-ultimate.js",
- "size": "~15KB",
- "unchanged": true,
- "note": "همان فایل قبلی - فقط HTML/CSS تغییر کرد"
- }
- },
-
- "usage": {
- "step_1": "باز کردن index-final.html در مرورگر",
- "step_2": "لذت بردن از UI خیرهکننده",
- "step_3": "انتخاب ارز و استراتژی",
- "step_4": "شروع Agent یا Analyze",
- "step_5": "مشاهده سیگنالهای real-time"
- },
-
- "browser_compatibility": {
- "chrome": "✅ Full support (recommended)",
- "firefox": "✅ Full support",
- "edge": "✅ Full support",
- "safari": "✅ Full support (iOS 12+)",
- "opera": "✅ Full support"
- },
-
- "success_criteria": {
- "svg_icons": "✅ ACHIEVED - 20+ custom icons",
- "advanced_css": "✅ ACHIEVED - 15+ animations",
- "glass_morphism": "✅ ACHIEVED - All cards",
- "gradient_system": "✅ ACHIEVED - 5+ gradients",
- "smooth_animations": "✅ ACHIEVED - 60 FPS",
- "professional_look": "✅ ACHIEVED - خیرهکننده",
- "visual_appeal": "✅ ACHIEVED - بسیار جذاب",
- "user_experience": "✅ ACHIEVED - عالی"
- },
-
- "highlights": {
- "most_impressive": [
- "🎨 20+ SVG icons سفارشی",
- "✨ 15+ keyframe animation",
- "💎 Glass morphism در همه جا",
- "🌈 5+ gradient system",
- "⚡ 60 FPS smooth animations",
- "🎯 Perfect visual hierarchy",
- "📱 Fully responsive",
- "🚀 Production ready"
- ]
- },
-
- "technical_specs": {
- "css_lines": "~1200 lines",
- "css_variables": "25+",
- "animations": "15+",
- "svg_paths": "30+",
- "gradients": "10+",
- "shadows": "20+",
- "transitions": "50+",
- "hover_effects": "30+"
- }
-}
-
diff --git a/static/pages/trading-assistant/FIX_503_ERROR.json b/static/pages/trading-assistant/FIX_503_ERROR.json
deleted file mode 100644
index 562afb9..0000000
--- a/static/pages/trading-assistant/FIX_503_ERROR.json
+++ /dev/null
@@ -1,184 +0,0 @@
-{
- "issue": "503 Error - Backend API Not Available",
- "problem_description": "System was trying to connect to backend API (really-amin-datasourceforcryptocurrency-2.hf.space) which returned 503 errors",
- "date_fixed": "2025-12-02",
-
- "root_cause": {
- "file": "trading-assistant-professional.js",
- "issue": "Backend API dependency in fetchPrice() and fetchOHLCV()",
- "backend_url": "window.location.origin + '/api'",
- "error_type": "503 Service Unavailable",
- "frequency": "Every 5 seconds (price updates)"
- },
-
- "solution": {
- "approach": "Remove ALL backend dependencies",
- "primary_source": "Binance API (https://api.binance.com/api/v3)",
- "backup_source": "CoinGecko API (for prices only)",
- "fallback": "Demo prices (last resort)",
- "result": "100% independent system - works without backend"
- },
-
- "changes_made": [
- {
- "file": "trading-assistant-professional.js",
- "section": "API_CONFIG",
- "before": {
- "backend": "window.location.origin + '/api'",
- "fallbacks": {
- "binance": "https://api.binance.com/api/v3",
- "coingecko": "https://api.coingecko.com/api/v3"
- }
- },
- "after": {
- "binance": "https://api.binance.com/api/v3",
- "coingecko": "https://api.coingecko.com/api/v3",
- "timeout": 10000,
- "retries": 2
- },
- "impact": "Removed backend dependency completely"
- },
- {
- "file": "trading-assistant-professional.js",
- "function": "fetchPrice()",
- "before": "Tried backend first, then Binance as fallback",
- "after": "Uses Binance directly, CoinGecko as backup",
- "flow": [
- "1. Check cache",
- "2. Try Binance API",
- "3. Try CoinGecko API (backup)",
- "4. Use demo price (last resort)"
- ],
- "no_backend": true
- },
- {
- "file": "trading-assistant-professional.js",
- "function": "fetchOHLCV()",
- "before": "Tried Binance first, then backend as fallback",
- "after": "Uses ONLY Binance API",
- "flow": [
- "1. Check cache",
- "2. Try Binance klines API",
- "3. Generate demo data (last resort)"
- ],
- "no_backend": true
- }
- ],
-
- "api_endpoints_used": {
- "binance": {
- "price": "https://api.binance.com/api/v3/ticker/price?symbol={SYMBOL}",
- "ohlcv": "https://api.binance.com/api/v3/klines?symbol={SYMBOL}&interval={INTERVAL}&limit={LIMIT}",
- "rate_limit": "1200 requests/minute",
- "reliability": "99.9%",
- "cors": "Allowed for public endpoints"
- },
- "coingecko": {
- "price": "https://api.coingecko.com/api/v3/simple/price?ids={COIN_ID}&vs_currencies=usd",
- "rate_limit": "50 calls/minute (free tier)",
- "reliability": "95%",
- "cors": "Allowed"
- }
- },
-
- "testing": {
- "before_fix": {
- "errors": "17+ consecutive 503 errors",
- "frequency": "Every 5 seconds",
- "impact": "System unusable, prices not loading"
- },
- "after_fix": {
- "errors": "0 backend calls",
- "binance_calls": "Working perfectly",
- "coingecko_calls": "Available as backup",
- "impact": "System fully functional"
- }
- },
-
- "performance_improvements": {
- "latency": {
- "before": "5000ms timeout + retry = 10+ seconds",
- "after": "Direct Binance call = 200-500ms"
- },
- "reliability": {
- "before": "Dependent on backend availability (0% uptime)",
- "after": "Dependent on Binance (99.9% uptime)"
- },
- "error_rate": {
- "before": "100% (all backend calls failed)",
- "after": "< 1% (Binance is very reliable)"
- }
- },
-
- "benefits": {
- "independence": "No backend required - fully standalone",
- "reliability": "99.9% uptime (Binance SLA)",
- "speed": "5-10x faster response times",
- "simplicity": "Fewer dependencies, easier to maintain",
- "scalability": "Can handle more users (Binance rate limits are generous)"
- },
-
- "verified_working": {
- "price_fetching": true,
- "ohlcv_data": true,
- "hts_analysis": true,
- "agent_monitoring": true,
- "tradingview_chart": true,
- "no_503_errors": true
- },
-
- "deployment_notes": {
- "requirements": [
- "Modern browser with ES6+ support",
- "Internet connection",
- "No backend server needed",
- "No API keys needed"
- ],
- "cors_handling": "Binance and CoinGecko allow CORS for public endpoints",
- "rate_limits": "Respected with caching and delays",
- "fallback_strategy": "Cache -> Binance -> CoinGecko -> Demo data"
- },
-
- "files_affected": [
- "trading-assistant-professional.js (FIXED)",
- "index.html (uses fixed file)",
- "index-professional.html (uses fixed file)"
- ],
-
- "files_not_affected": [
- "trading-assistant-enhanced.js (already using Binance only)",
- "index-enhanced.html (already correct)",
- "hts-engine.js (no API calls)",
- "trading-strategies.js (no API calls)"
- ],
-
- "recommended_usage": {
- "best": "index-enhanced.html - Beautiful UI + Binance only",
- "good": "index.html - Standard UI + Binance only (now fixed)",
- "testing": "test-hts-integration.html - For HTS engine testing"
- },
-
- "monitoring": {
- "console_logs": [
- "[API] Fetching price from Binance: ...",
- "[API] BTC price: $43250.00",
- "[API] Fetching OHLCV from Binance: ...",
- "[API] Successfully fetched 100 candles"
- ],
- "no_more_errors": [
- "No more 503 errors",
- "No more backend calls",
- "No more failed requests"
- ]
- },
-
- "success_criteria": {
- "zero_503_errors": "✅ ACHIEVED",
- "binance_working": "✅ ACHIEVED",
- "prices_loading": "✅ ACHIEVED",
- "ohlcv_loading": "✅ ACHIEVED",
- "agent_working": "✅ ACHIEVED",
- "no_backend_dependency": "✅ ACHIEVED"
- }
-}
-
diff --git a/static/pages/trading-assistant/ULTIMATE_VERSION.json b/static/pages/trading-assistant/ULTIMATE_VERSION.json
deleted file mode 100644
index 045f7be..0000000
--- a/static/pages/trading-assistant/ULTIMATE_VERSION.json
+++ /dev/null
@@ -1,277 +0,0 @@
-{
- "version": "5.0.0 - ULTIMATE EDITION",
- "release_date": "2025-12-02",
- "status": "PRODUCTION READY",
-
- "improvements": {
- "ui_design": {
- "before": "نامناسب، رنگبندی ضعیف، جذابیت بصری کم",
- "after": "حرفهای، رنگبندی عالی، جذابیت بصری بالا",
- "changes": [
- "رنگبندی کاملاً جدید با پالت حرفهای",
- "گرادیانتهای زیبا و متحرک",
- "کارتهای شیشهای با افکت blur",
- "انیمیشنهای روان و جذاب",
- "تایپوگرافی بهتر و خواناتر",
- "فاصلهگذاری و layout بهینه"
- ]
- },
-
- "real_data": {
- "before": "دادههای غیر واقعی، demo data، mock data",
- "after": "100% داده واقعی از Binance",
- "changes": [
- "حذف کامل backend dependency",
- "اتصال مستقیم به Binance API",
- "قیمتهای واقعی هر 3 ثانیه",
- "OHLCV واقعی برای تحلیل",
- "تغییرات قیمت 24 ساعته واقعی",
- "صفر داده جعلی یا نمایشی"
- ]
- },
-
- "user_experience": {
- "before": "کاربرپسند نبود، جذابیت کم",
- "after": "بسیار کاربرپسند و جذاب",
- "changes": [
- "کارتهای بزرگتر و واضحتر",
- "دکمههای جذاب با hover effects",
- "نمایش اطلاعات بهتر",
- "رنگبندی معنادار (سبز=خرید، قرمز=فروش)",
- "فونتهای خواناتر",
- "فضای سفید بهتر"
- ]
- }
- },
-
- "color_palette": {
- "primary": {
- "blue": "#2563eb - آبی اصلی",
- "cyan": "#06b6d4 - فیروزهای",
- "purple": "#7c3aed - بنفش"
- },
- "semantic": {
- "success": "#10b981 - سبز (خرید)",
- "danger": "#ef4444 - قرمز (فروش)",
- "warning": "#f59e0b - نارنجی (هشدار)"
- },
- "backgrounds": {
- "dark": "#0f172a - پسزمینه اصلی",
- "darker": "#020617 - پسزمینه تیرهتر",
- "card": "#1e293b - کارتها",
- "card_hover": "#334155 - hover روی کارت"
- },
- "text": {
- "primary": "#f1f5f9 - متن اصلی",
- "secondary": "#cbd5e1 - متن ثانویه",
- "muted": "#64748b - متن کمرنگ"
- }
- },
-
- "features": {
- "real_time_data": {
- "enabled": true,
- "source": "Binance API",
- "update_frequency": "3 seconds",
- "data_types": [
- "Live prices",
- "24h price change",
- "OHLCV candles",
- "Volume data"
- ]
- },
-
- "ai_agent": {
- "enabled": true,
- "scan_frequency": "45 seconds",
- "monitored_pairs": 6,
- "confidence_threshold": 75,
- "auto_signals": true
- },
-
- "hts_engine": {
- "enabled": true,
- "algorithm": "RSI+MACD (40%) + SMC (25%) + Patterns (20%) + Sentiment (10%) + ML (5%)",
- "accuracy": "85%",
- "real_data_only": true
- },
-
- "tradingview_chart": {
- "enabled": true,
- "theme": "Dark (professional)",
- "indicators": ["RSI", "MACD", "Volume"],
- "real_time": true,
- "customized_colors": true
- }
- },
-
- "ui_components": {
- "header": {
- "features": [
- "Logo با gradient جذاب",
- "Live badge متحرک",
- "آمار real-time",
- "دکمه refresh"
- ],
- "colors": "Glass morphism با backdrop blur"
- },
-
- "crypto_cards": {
- "features": [
- "آیکونهای زیبا",
- "قیمت real-time",
- "تغییرات 24 ساعته",
- "رنگبندی معنادار",
- "Hover effects جذاب",
- "Active state واضح"
- ],
- "layout": "Grid 2 ستونه"
- },
-
- "strategy_cards": {
- "features": [
- "نام واضح و جذاب",
- "توضیحات کامل",
- "Badge premium/standard",
- "آمار accuracy و timeframe",
- "Hover effects",
- "Active state با گرادیانت"
- ],
- "layout": "Vertical stack"
- },
-
- "chart": {
- "features": [
- "TradingView professional",
- "Dark theme سفارشی",
- "شمعهای سبز/قرمز",
- "اندیکاتورهای RSI, MACD, Volume",
- "Real-time updates"
- ],
- "height": "600px"
- },
-
- "signals": {
- "features": [
- "کارتهای جذاب",
- "رنگبندی معنادار",
- "اطلاعات کامل",
- "Slide-in animation",
- "Grid layout برای اطلاعات",
- "Scrollable container"
- ],
- "max_signals": 30
- }
- },
-
- "animations": {
- "background": "Gradient shift متحرک",
- "live_dot": "Pulse animation",
- "cards": "Hover effects با transform",
- "buttons": "Hover lift با shadow",
- "signals": "Slide-in از راست",
- "toast": "Slide-in از راست",
- "agent_avatar": "Rotate 360 degrees"
- },
-
- "data_flow": {
- "prices": {
- "source": "Binance /ticker/24hr",
- "frequency": "Every 3 seconds",
- "data": ["price", "24h change %"],
- "caching": "In-memory",
- "fallback": "None - shows error if Binance fails"
- },
-
- "ohlcv": {
- "source": "Binance /klines",
- "on_demand": true,
- "intervals": ["1h", "4h"],
- "limit": 100,
- "fallback": "None - shows error if Binance fails"
- },
-
- "analysis": {
- "engine": "HTS Engine",
- "input": "Real OHLCV from Binance",
- "output": "Signal + Confidence + Levels",
- "no_fake_data": true
- }
- },
-
- "performance": {
- "page_load": "< 1 second",
- "price_update": "3 seconds",
- "agent_scan": "45 seconds",
- "analysis_time": "2-5 seconds",
- "smooth_animations": "60 FPS",
- "memory_usage": "< 80MB"
- },
-
- "comparison": {
- "old_version": {
- "ui": "❌ نامناسب",
- "colors": "❌ ضعیف",
- "data": "❌ غیر واقعی",
- "ux": "❌ کاربرپسند نبود",
- "visual": "❌ جذابیت کم"
- },
- "ultimate_version": {
- "ui": "✅ حرفهای و مدرن",
- "colors": "✅ پالت عالی",
- "data": "✅ 100% واقعی",
- "ux": "✅ بسیار کاربرپسند",
- "visual": "✅ خیرهکننده"
- }
- },
-
- "files": {
- "html": "index-ultimate.html (18KB)",
- "javascript": "trading-assistant-ultimate.js (15KB)",
- "dependencies": ["hts-engine.js", "TradingView widget"]
- },
-
- "usage": {
- "step_1": "باز کردن index-ultimate.html",
- "step_2": "انتخاب ارز (کلیک روی کارت)",
- "step_3": "انتخاب استراتژی (کلیک روی کارت)",
- "step_4": "Start Agent یا Analyze Now",
- "step_5": "مشاهده سیگنالهای real-time"
- },
-
- "api_usage": {
- "binance_only": true,
- "no_backend": true,
- "no_api_key": true,
- "public_endpoints": true,
- "rate_limits": "Respected with delays"
- },
-
- "browser_support": {
- "chrome": "✅ Full support",
- "firefox": "✅ Full support",
- "edge": "✅ Full support",
- "safari": "✅ Full support",
- "mobile": "✅ Responsive"
- },
-
- "success_criteria": {
- "professional_ui": "✅ ACHIEVED",
- "beautiful_colors": "✅ ACHIEVED",
- "real_data_only": "✅ ACHIEVED",
- "user_friendly": "✅ ACHIEVED",
- "visual_appeal": "✅ ACHIEVED",
- "smooth_animations": "✅ ACHIEVED",
- "fast_performance": "✅ ACHIEVED"
- },
-
- "next_steps": {
- "v5.1": [
- "WebSocket برای streaming",
- "نمودارهای اضافی",
- "تاریخچه معاملات",
- "گزارشهای پیشرفته"
- ]
- }
-}
-
|