Spaces:
Sleeping
Sleeping
Update app/arbitrage_analyzer.py
Browse files
app/arbitrage_analyzer.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
"""
|
| 2 |
-
The Oracle Discrepancy Analyzer.
|
| 3 |
-
Uses Gemini to provide risk assessment
|
| 4 |
-
discrepancies between the Pyth and Chainlink oracles.
|
| 5 |
"""
|
| 6 |
import os
|
| 7 |
import logging
|
|
@@ -21,12 +20,12 @@ class ArbitrageAnalyzer:
|
|
| 21 |
self.params = {"key": self.api_key}
|
| 22 |
self.headers = {"Content-Type": "application/json"}
|
| 23 |
|
| 24 |
-
def _build_prompt(self, opportunity: Dict) -> dict:
|
| 25 |
return {
|
| 26 |
"contents": [{
|
| 27 |
"parts": [{
|
| 28 |
"text": f"""
|
| 29 |
-
You are a high-frequency DeFi strategist. A price dislocation for
|
| 30 |
Provide a concise "Alpha Briefing" as a single, minified JSON object with NO markdown formatting.
|
| 31 |
|
| 32 |
The JSON object must have these exact keys: "risk", "strategy", "rationale".
|
|
@@ -35,7 +34,7 @@ class ArbitrageAnalyzer:
|
|
| 35 |
- "strategy": A brief, one-sentence action plan.
|
| 36 |
- "rationale": A short explanation for the risk assessment.
|
| 37 |
|
| 38 |
-
DISLOCATION DETAILS:
|
| 39 |
- Pyth Network Price: ${opportunity['pyth_price']:,.2f}
|
| 40 |
- Chainlink Aggregated Price: ${opportunity['chainlink_price']:,.2f}
|
| 41 |
- Discrepancy: {opportunity['spread_pct']:.3f}%
|
|
@@ -44,8 +43,8 @@ class ArbitrageAnalyzer:
|
|
| 44 |
}]
|
| 45 |
}
|
| 46 |
|
| 47 |
-
async def get_alpha_briefing(self, opportunity: Dict) -> Optional[Dict]:
|
| 48 |
-
prompt = self._build_prompt(opportunity)
|
| 49 |
try:
|
| 50 |
response = await self.client.post(self.API_URL, json=prompt, params=self.params, headers=self.headers, timeout=20)
|
| 51 |
response.raise_for_status()
|
|
@@ -54,5 +53,5 @@ class ArbitrageAnalyzer:
|
|
| 54 |
content = content.strip("```json\n")
|
| 55 |
return json.loads(content)
|
| 56 |
except Exception as e:
|
| 57 |
-
logger.error(f"❌ Gemini Alpha Briefing Error: {e}")
|
| 58 |
return None
|
|
|
|
| 1 |
"""
|
| 2 |
+
The Multi-Asset Oracle Discrepancy Analyzer.
|
| 3 |
+
Uses Gemini to provide context-aware risk assessment for various assets.
|
|
|
|
| 4 |
"""
|
| 5 |
import os
|
| 6 |
import logging
|
|
|
|
| 20 |
self.params = {"key": self.api_key}
|
| 21 |
self.headers = {"Content-Type": "application/json"}
|
| 22 |
|
| 23 |
+
def _build_prompt(self, asset_symbol: str, opportunity: Dict) -> dict:
|
| 24 |
return {
|
| 25 |
"contents": [{
|
| 26 |
"parts": [{
|
| 27 |
"text": f"""
|
| 28 |
+
You are a high-frequency DeFi strategist. A price dislocation for {asset_symbol} has been detected between the Pyth and Chainlink oracle networks.
|
| 29 |
Provide a concise "Alpha Briefing" as a single, minified JSON object with NO markdown formatting.
|
| 30 |
|
| 31 |
The JSON object must have these exact keys: "risk", "strategy", "rationale".
|
|
|
|
| 34 |
- "strategy": A brief, one-sentence action plan.
|
| 35 |
- "rationale": A short explanation for the risk assessment.
|
| 36 |
|
| 37 |
+
DISLOCATION DETAILS for {asset_symbol}:
|
| 38 |
- Pyth Network Price: ${opportunity['pyth_price']:,.2f}
|
| 39 |
- Chainlink Aggregated Price: ${opportunity['chainlink_price']:,.2f}
|
| 40 |
- Discrepancy: {opportunity['spread_pct']:.3f}%
|
|
|
|
| 43 |
}]
|
| 44 |
}
|
| 45 |
|
| 46 |
+
async def get_alpha_briefing(self, asset_symbol: str, opportunity: Dict) -> Optional[Dict]:
|
| 47 |
+
prompt = self._build_prompt(asset_symbol, opportunity)
|
| 48 |
try:
|
| 49 |
response = await self.client.post(self.API_URL, json=prompt, params=self.params, headers=self.headers, timeout=20)
|
| 50 |
response.raise_for_status()
|
|
|
|
| 53 |
content = content.strip("```json\n")
|
| 54 |
return json.loads(content)
|
| 55 |
except Exception as e:
|
| 56 |
+
logger.error(f"❌ Gemini Alpha Briefing Error for {asset_symbol}: {e}")
|
| 57 |
return None
|