Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
from agents import Agent, Runner
|
| 5 |
+
from agents.mcp import MCPServerStdio
|
| 6 |
+
|
| 7 |
+
# Optional: default exchange via env; can also hardcode "binance"
|
| 8 |
+
DEFAULT_EXCHANGE = os.getenv("EXCHANGE_NAME", "binance")
|
| 9 |
+
|
| 10 |
+
async def handle_request(request: str):
|
| 11 |
+
instructions = f"""You are a cryptocurrency perpetuals trading researcher. You have the tools for trend/momentum/volatility/volume technical indicators and strategies.
|
| 12 |
+
Default analysis interval is 1h, and default lookback period is 36.
|
| 13 |
+
Default indicators/strategies you have are:
|
| 14 |
+
- EMA (20, 200)
|
| 15 |
+
- MACD (12, 26, 9)
|
| 16 |
+
- stochastic RSI (14, 14, 3, 3)
|
| 17 |
+
- Accumulation/Distribution (ADL)
|
| 18 |
+
- Volume
|
| 19 |
+
Based on the indicators, Look for possible long/short opportunities, and come up with a strategy.
|
| 20 |
+
The current datetime is {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}"""
|
| 21 |
+
|
| 22 |
+
params = {
|
| 23 |
+
"command": "node",
|
| 24 |
+
"args": ["crypto-indicators-mcp/index.js"],
|
| 25 |
+
"env": {
|
| 26 |
+
"EXCHANGE_NAME": DEFAULT_EXCHANGE
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
async with MCPServerStdio(params=params, client_session_timeout_seconds=60) as mcp_server:
|
| 31 |
+
agent = Agent(
|
| 32 |
+
name="crypto_technical_researcher",
|
| 33 |
+
instructions=instructions,
|
| 34 |
+
model="gpt-4.1-mini",
|
| 35 |
+
mcp_servers=[mcp_server],
|
| 36 |
+
)
|
| 37 |
+
result = await Runner.run(agent, request)
|
| 38 |
+
return result.final_output
|
| 39 |
+
|
| 40 |
+
iface = gr.Interface(
|
| 41 |
+
fn=handle_request,
|
| 42 |
+
inputs=gr.Textbox(label="Request", placeholder="e.g., Get the latest indicators on BTC"),
|
| 43 |
+
outputs=gr.Textbox(label="Response", lines=12),
|
| 44 |
+
title="Crypto Technical Researcher",
|
| 45 |
+
description="Ask for technical analysis via an MCP-powered toolchain."
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
if __name__ == "__main__":
|
| 49 |
+
iface.launch()
|