Spaces:
Running
Running
Update README.md
Browse files
README.md
CHANGED
@@ -14,9 +14,100 @@ short_description: Combines cryptocurrency insights with AI-driven analytics.
|
|
14 |
|
15 |
---
|
16 |
|
17 |
-
|
|
|
|
|
18 |
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
---
|
16 |
|
17 |
+
This file should be placed in the root directory of your project. It's written in Markdown.
|
18 |
+
Generated markdown
|
19 |
+
# π€ Sentinel Arbitrage Engine
|
20 |
|
21 |
+
**Sentinel is a high-frequency, AI-powered arbitrage detection engine for cryptocurrency markets. It autonomously monitors real-time price dislocations between major decentralized oracles and provides AI-generated risk analysis and trading strategies.**
|
22 |
|
23 |
+
This application is designed to identify and analyze fleeting arbitrage opportunities that exist between different price-reporting networks in the DeFi space. It uses a robust, multi-asset architecture and leverages Google's Gemini Pro for sophisticated, real-time decision support.
|
24 |
+
|
25 |
+
---
|
26 |
+
|
27 |
+
## β¨ Core Features
|
28 |
+
|
29 |
+
* **Multi-Asset Monitoring:** Continuously tracks prices for multiple crypto assets (BTC, ETH, SOL, etc.) across different data sources simultaneously.
|
30 |
+
* **Decentralized & Resilient:** Queries globally-accessible, censorship-resistant oracles (Pyth and Chainlink aggregators) to avoid CEX geoblocking and rate-limiting issues.
|
31 |
+
* **AI-Powered Alpha Briefings:** For every detected opportunity, it uses the Gemini Pro API to generate a concise briefing, including:
|
32 |
+
* **Risk Assessment** (LOW, MEDIUM, HIGH)
|
33 |
+
* **Execution Strategy** (e.g., "Execute a flash loan arbitrage...")
|
34 |
+
* **Rationale** (The "why" behind the risk assessment)
|
35 |
+
* **Real-Time WebSocket UI:** The frontend uses a professional, Socket.IO-powered dashboard to display signals with millisecond latency. The UI is clean, data-dense, and built for at-a-glance interpretation.
|
36 |
+
* **Asynchronous Architecture:** Built with Python, FastAPI, and `asyncio`, the entire engine is asynchronous from the ground up, ensuring high performance and concurrency.
|
37 |
+
|
38 |
+
## π οΈ Tech Stack
|
39 |
+
|
40 |
+
* **Backend:** Python 3.9+, FastAPI
|
41 |
+
* **Real-Time Communication:** `python-socketio`
|
42 |
+
* **Data Fetching:** `httpx` (for async HTTP requests)
|
43 |
+
* **AI Engine:** Google Gemini Pro
|
44 |
+
* **Data Sources:**
|
45 |
+
* Pyth Network (On-chain data)
|
46 |
+
* CoinGecko (Off-chain aggregated data)
|
47 |
+
* **Frontend:** Vanilla JavaScript with the Socket.IO Client
|
48 |
+
* **Styling:** Pico.css
|
49 |
+
|
50 |
+
## π Getting Started
|
51 |
+
|
52 |
+
### 1. Prerequisites
|
53 |
+
|
54 |
+
* Python 3.9+
|
55 |
+
* An account with [Hugging Face](https://huggingface.co/) to deploy as a Space (recommended).
|
56 |
+
* API Keys for:
|
57 |
+
* **Google Gemini:** Obtain from [Google AI Studio](https://aistudio.google.com/).
|
58 |
+
* **(Optional but Recommended)** **CoinGecko:** A free or Pro key from [CoinGecko API](https://www.coingecko.com/en/api).
|
59 |
+
|
60 |
+
### 2. Project Structure
|
61 |
+
|
62 |
+
The project uses a standard package structure for scalability and maintainability.
|
63 |
+
Use code with caution.
|
64 |
+
Markdown
|
65 |
+
/
|
66 |
+
βββ app/
|
67 |
+
β βββ init.py
|
68 |
+
β βββ arbitrage_analyzer.py
|
69 |
+
β βββ broker.py
|
70 |
+
β βββ main.py
|
71 |
+
β βββ price_fetcher.py
|
72 |
+
βββ static/
|
73 |
+
β βββ index.html
|
74 |
+
βββ .gitignore
|
75 |
+
βββ Dockerfile
|
76 |
+
βββ requirements.txt
|
77 |
+
Generated code
|
78 |
+
### 3. Installation & Setup
|
79 |
+
|
80 |
+
1. **Clone the repository:**
|
81 |
+
```bash
|
82 |
+
git clone https://huggingface.co/spaces/mgbam/CryptoSentinel_AI
|
83 |
+
cd CryptoSentinel_AI
|
84 |
+
```
|
85 |
+
|
86 |
+
2. **Install dependencies:**
|
87 |
+
```bash
|
88 |
+
pip install -r requirements.txt
|
89 |
+
```
|
90 |
+
|
91 |
+
3. **Configure Environment Secrets:**
|
92 |
+
* If running locally, create a `.env` file and add your API key:
|
93 |
+
```
|
94 |
+
GEMINI_API_KEY="your_gemini_api_key_here"
|
95 |
+
```
|
96 |
+
* If deploying on Hugging Face Spaces, add `GEMINI_API_KEY` as a repository secret in your Space's **Settings** tab.
|
97 |
+
|
98 |
+
### 4. Running the Engine
|
99 |
+
|
100 |
+
The application is run using `uvicorn`. From the root directory of the project, execute:
|
101 |
+
|
102 |
+
```bash
|
103 |
+
uvicorn app.main:app --host 0.0.0.0 --port 7860 --reload
|
104 |
+
Use code with caution.
|
105 |
+
--reload enables hot-reloading for development. Remove this flag for production.
|
106 |
+
Once running, navigate to http://127.0.0.1:7860 in your browser to view the Sentinel Arbitrage Engine dashboard.
|
107 |
+
βοΈ How It Works
|
108 |
+
Lifespan Management: On startup, the lifespan manager in app/main.py initializes all necessary services (PriceFetcher, ArbitrageAnalyzer) and launches the main run_arbitrage_detector loop as a persistent background task.
|
109 |
+
Data Fetching: The PriceFetcher runs in the background loop, making concurrent async calls to the Pyth and CoinGecko APIs to get the latest prices for all configured assets.
|
110 |
+
Discrepancy Detection: The loop compares the prices from the two oracles for each asset. If the percentage difference exceeds the OPPORTUNITY_THRESHOLD, it's flagged as a potential arbitrage opportunity.
|
111 |
+
AI Analysis: The detected opportunity data is passed to the ArbitrageAnalyzer, which constructs a detailed prompt for the Gemini API.
|
112 |
+
Signal Emission: Gemini's structured response (Risk, Strategy, Rationale) is combined with the price data into a final "signal" object. This signal is then broadcast to all connected clients using sio.emit('new_signal', ...).
|
113 |
+
Real-Time UI: The static/index.html page connects to the Socket.IO server. A JavaScript listener for the new_signal event receives the data and dynamically constructs a new table row, prepending it to the live signal stream.
|