feat: 添加前端界面和市场分析模块
- 新增 Vue 3 + Vuetify 前端界面 - 新增市场分析模块 (market/) - 更新主服务器和路由 - 更新 MT5 EA 文件 - 添加 .gitignore 排除临时文件
This commit is contained in:
+91
-35
@@ -4,7 +4,7 @@
|
||||
EA 相关的接口路由
|
||||
"""
|
||||
|
||||
from fastapi import APIRouter, Query
|
||||
from fastapi import APIRouter, Query, Request
|
||||
from typing import Optional, List, Dict
|
||||
from models import TradeInstruction
|
||||
from server import TradingServer
|
||||
@@ -15,7 +15,7 @@ def create_ea_routes(server: TradingServer) -> APIRouter:
|
||||
创建 EA 相关路由
|
||||
"""
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/get_trades")
|
||||
async def get_trades(
|
||||
symbol: str = Query(..., description="交易品种"),
|
||||
@@ -23,11 +23,11 @@ def create_ea_routes(server: TradingServer) -> APIRouter:
|
||||
) -> Dict:
|
||||
"""
|
||||
获取指定SYMBOL的交易指令
|
||||
|
||||
|
||||
参数:
|
||||
- symbol: 交易品种 (e.g., "EURUSD")
|
||||
- price: 当前中间价格,用于条件过滤
|
||||
|
||||
|
||||
返回:
|
||||
```json
|
||||
{
|
||||
@@ -40,21 +40,42 @@ def create_ea_routes(server: TradingServer) -> APIRouter:
|
||||
"sl": 1.0800,
|
||||
"tp": 1.0900
|
||||
}
|
||||
],
|
||||
"close_tickets": [123456, 789012],
|
||||
"pivot_alerts": [
|
||||
{
|
||||
"type": "pivot_alert",
|
||||
"symbol": "EURUSD",
|
||||
"period": "H4",
|
||||
"direction": "high",
|
||||
"pivot_price": 1.0900,
|
||||
"current_price": 1.0880,
|
||||
"distance_pct": 0.18,
|
||||
"message": "EURUSD H4 接近高点 1.0900"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
"""
|
||||
trades = server.get_trades_by_symbol(symbol, price)
|
||||
return {"trades": trades}
|
||||
|
||||
result = server.get_trades_by_symbol(symbol, price)
|
||||
# 添加平仓指令
|
||||
result["close_tickets"] = server.get_close_position_instructions(symbol)
|
||||
|
||||
# 打印完整返回数据用于调试
|
||||
import json
|
||||
print(f"[EA API] 返回给EA的数据: {json.dumps(result, ensure_ascii=False)}")
|
||||
|
||||
return result
|
||||
|
||||
@router.post("/send_statistics")
|
||||
async def send_statistics(data: dict) -> Dict:
|
||||
async def send_statistics(request: Request) -> Dict:
|
||||
"""
|
||||
接收 EA 发送的统计数据
|
||||
|
||||
|
||||
参数 (JSON):
|
||||
```json
|
||||
{
|
||||
"symbol": "eurusd",
|
||||
"timestamp": "2024-01-15 14:30:45",
|
||||
"tickCount": 1234,
|
||||
"bidPrice": 1.0850,
|
||||
@@ -62,30 +83,11 @@ def create_ea_routes(server: TradingServer) -> APIRouter:
|
||||
"balance": 10000.00,
|
||||
"equity": 10500.50,
|
||||
"marginLevel": 150.0,
|
||||
"positions": [
|
||||
{
|
||||
"symbol": "eurusd",
|
||||
"tickets": 123456,
|
||||
"type": "buy",
|
||||
"volume": 0.1,
|
||||
"openPrice": 1.0800,
|
||||
"takeProfit": 1.0900,
|
||||
"stopLoss": 1.0750,
|
||||
"profit": 50.00
|
||||
}
|
||||
],
|
||||
"trades": [
|
||||
{
|
||||
"tickets": 789012,
|
||||
"symbol": "eurusd",
|
||||
"action": "buy",
|
||||
"openPrice": 1.0800,
|
||||
"volume": 0.1
|
||||
}
|
||||
]
|
||||
"positions": [],
|
||||
"trades": []
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
返回:
|
||||
```json
|
||||
{
|
||||
@@ -94,7 +96,61 @@ def create_ea_routes(server: TradingServer) -> APIRouter:
|
||||
}
|
||||
```
|
||||
"""
|
||||
server.save_statistics(data)
|
||||
return {"status": "ok", "message": "统计数据已保存"}
|
||||
|
||||
return router
|
||||
# 获取原始请求体用于调试
|
||||
body = await request.body()
|
||||
print(f"[DEBUG] Raw body type: {type(body)}")
|
||||
print(f"[DEBUG] Raw body: {body}")
|
||||
print(f"[DEBUG] Raw body length: {len(body)}")
|
||||
|
||||
# 尝试解析JSON
|
||||
import json
|
||||
try:
|
||||
data = await request.json()
|
||||
print(f"[DEBUG] Parsed JSON successfully: {data}")
|
||||
server.save_statistics(data)
|
||||
return {"status": "ok", "message": "统计数据已保存"}
|
||||
except Exception as e:
|
||||
print(f"[ERROR] Failed to parse JSON: {e}")
|
||||
print(f"[ERROR] Body as string: {body.decode('utf-8', errors='ignore')}")
|
||||
return {"status": "error", "message": str(e)}
|
||||
|
||||
@router.post("/close_position")
|
||||
async def close_position(request: Request) -> Dict:
|
||||
"""
|
||||
平仓指令
|
||||
|
||||
请求体:
|
||||
```json
|
||||
{
|
||||
"ticket": 123456,
|
||||
"symbol": "GOLD#"
|
||||
}
|
||||
```
|
||||
|
||||
返回:
|
||||
```json
|
||||
{
|
||||
"status": "ok",
|
||||
"message": "平仓指令已添加"
|
||||
}
|
||||
```
|
||||
"""
|
||||
try:
|
||||
data = await request.json()
|
||||
ticket = data.get('ticket')
|
||||
symbol = data.get('symbol', '').upper()
|
||||
|
||||
if not ticket:
|
||||
return {"status": "error", "message": "缺少订单号"}
|
||||
|
||||
# 添加平仓指令到队列
|
||||
server.add_close_position_instruction(symbol, ticket)
|
||||
|
||||
print(f"[EA API] 平仓指令已添加: {symbol} ticket={ticket}")
|
||||
return {"status": "ok", "message": "平仓指令已添加"}
|
||||
|
||||
except Exception as e:
|
||||
print(f"[ERROR] close_position 异常: {str(e)}")
|
||||
return {"status": "error", "message": str(e)}
|
||||
|
||||
return router
|
||||
Reference in New Issue
Block a user