refactor: 移除投资组合详情中的交易记录功能
重构投资组合详情响应,移除了不再需要的交易记录相关字段和逻辑 更新了README文档以反映API变更
This commit is contained in:
parent
9741468f3e
commit
564687bc1e
@ -38,7 +38,6 @@ public class PortfolioDetailResponse
|
|||||||
public double todayProfit { get; set; }
|
public double todayProfit { get; set; }
|
||||||
public string todayProfitCurrency { get; set; }
|
public string todayProfitCurrency { get; set; }
|
||||||
public List<PositionItem> positions { get; set; }
|
public List<PositionItem> positions { get; set; }
|
||||||
public List<TransactionItem> transactions { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class StrategyInfo
|
public class StrategyInfo
|
||||||
|
|||||||
@ -137,12 +137,6 @@ public class PortfolioService : IPortfolioService
|
|||||||
.Where(pos => pos.PortfolioId == id)
|
.Where(pos => pos.PortfolioId == id)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var transactions = _db.Queryable<Transaction>()
|
|
||||||
.Where(t => t.PortfolioId == id)
|
|
||||||
.OrderByDescending(t => t.TransactionTime)
|
|
||||||
.Take(5)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
return new PortfolioDetailResponse
|
return new PortfolioDetailResponse
|
||||||
{
|
{
|
||||||
id = portfolio.Id,
|
id = portfolio.Id,
|
||||||
@ -151,7 +145,7 @@ public class PortfolioService : IPortfolioService
|
|||||||
strategy = new StrategyInfo
|
strategy = new StrategyInfo
|
||||||
{
|
{
|
||||||
id = portfolio.StrategyId,
|
id = portfolio.StrategyId,
|
||||||
name = "策略名称", // 实际应该从策略表获取
|
name = "策略名称",
|
||||||
description = "策略描述"
|
description = "策略描述"
|
||||||
},
|
},
|
||||||
portfolioValue = (double)portfolio.TotalValue,
|
portfolioValue = (double)portfolio.TotalValue,
|
||||||
@ -165,24 +159,11 @@ public class PortfolioService : IPortfolioService
|
|||||||
stockName = pos.StockName,
|
stockName = pos.StockName,
|
||||||
amount = (int)pos.Shares,
|
amount = (int)pos.Shares,
|
||||||
averagePrice = (double)pos.AvgPrice,
|
averagePrice = (double)pos.AvgPrice,
|
||||||
currentPrice = (double)pos.AvgPrice, // 实际应该从市场数据获取
|
currentPrice = (double)pos.AvgPrice,
|
||||||
totalValue = (double)(pos.Shares * pos.AvgPrice),
|
totalValue = (double)(pos.Shares * pos.AvgPrice),
|
||||||
profit = 0,
|
profit = 0,
|
||||||
profitRate = 0,
|
profitRate = 0,
|
||||||
currency = pos.Currency
|
currency = pos.Currency
|
||||||
}).ToList(),
|
|
||||||
transactions = transactions.Select(t => new TransactionItem
|
|
||||||
{
|
|
||||||
id = t.Id,
|
|
||||||
portfolioId = t.PortfolioId,
|
|
||||||
date = t.TransactionTime.ToString("yyyy-MM-dd"),
|
|
||||||
time = t.TransactionTime.ToString("HH:mm:ss"),
|
|
||||||
type = t.Type,
|
|
||||||
title = t.Title,
|
|
||||||
amount = (double)t.TotalAmount,
|
|
||||||
currency = t.Currency,
|
|
||||||
status = t.Status,
|
|
||||||
remark = t.Remark
|
|
||||||
}).ToList()
|
}).ToList()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
226
README.md
226
README.md
@ -72,13 +72,110 @@ AssetManager
|
|||||||
|
|
||||||
## 📡 API 示例
|
## 📡 API 示例
|
||||||
|
|
||||||
### 创建策略 API
|
## 🎯 策略 API (Strategy API)
|
||||||
|
|
||||||
**请求 URL**: `POST /api/v1/strategies`
|
### 1. 获取策略列表
|
||||||
|
|
||||||
|
**请求 URL**: `GET /api/v1/strategy/strategies`
|
||||||
|
|
||||||
|
**请求头**:
|
||||||
|
```
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
```
|
||||||
|
|
||||||
|
**响应示例**:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"Id": "12345678-1234-1234-1234-1234567890ab",
|
||||||
|
"Title": "双均线策略",
|
||||||
|
"Type": "ma_trend",
|
||||||
|
"Description": "经典趋势跟踪策略",
|
||||||
|
"RiskLevel": "medium",
|
||||||
|
"Tags": ["趋势", "均线"],
|
||||||
|
"Parameters": {
|
||||||
|
"maType": "SMA",
|
||||||
|
"shortPeriod": 20,
|
||||||
|
"longPeriod": 60
|
||||||
|
},
|
||||||
|
"UserId": "user-123",
|
||||||
|
"CreatedAt": "2024-01-01T10:00:00",
|
||||||
|
"UpdatedAt": "2024-01-01T10:00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Id": "87654321-4321-4321-4321-210987654321",
|
||||||
|
"Title": "风险平价策略",
|
||||||
|
"Type": "risk_parity",
|
||||||
|
"Description": "资产配置策略",
|
||||||
|
"RiskLevel": "low",
|
||||||
|
"Tags": ["资产配置", "风险控制"],
|
||||||
|
"Parameters": {
|
||||||
|
"lookbackPeriod": 60,
|
||||||
|
"rebalanceThreshold": 0.05,
|
||||||
|
"assets": [
|
||||||
|
{ "symbol": "AAPL", "targetWeight": 0.6 },
|
||||||
|
{ "symbol": "BTC/USD", "targetWeight": 0.4 }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"UserId": "user-123",
|
||||||
|
"CreatedAt": "2024-01-02T10:00:00",
|
||||||
|
"UpdatedAt": "2024-01-02T10:00:00"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"message": "Success"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 获取单个策略详情
|
||||||
|
|
||||||
|
**请求 URL**: `GET /api/v1/strategy/{id}`
|
||||||
|
|
||||||
|
**请求头**:
|
||||||
|
```
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
```
|
||||||
|
|
||||||
|
**响应示例**:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"data": {
|
||||||
|
"Id": "12345678-1234-1234-1234-1234567890ab",
|
||||||
|
"Title": "双均线策略",
|
||||||
|
"Type": "ma_trend",
|
||||||
|
"Description": "经典趋势跟踪策略",
|
||||||
|
"RiskLevel": "medium",
|
||||||
|
"Tags": ["趋势", "均线"],
|
||||||
|
"Parameters": {
|
||||||
|
"maType": "SMA",
|
||||||
|
"shortPeriod": 20,
|
||||||
|
"longPeriod": 60
|
||||||
|
},
|
||||||
|
"UserId": "user-123",
|
||||||
|
"CreatedAt": "2024-01-01T10:00:00",
|
||||||
|
"UpdatedAt": "2024-01-01T10:00:00"
|
||||||
|
},
|
||||||
|
"message": "Success"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 创建策略
|
||||||
|
|
||||||
|
**请求 URL**: `POST /api/v1/strategy`
|
||||||
|
|
||||||
|
**请求头**:
|
||||||
|
```
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
Content-Type: application/json
|
||||||
|
```
|
||||||
|
|
||||||
**请求体示例**:
|
**请求体示例**:
|
||||||
|
|
||||||
#### 1. 创建双均线策略
|
#### 3.1 创建双均线策略
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@ -95,7 +192,7 @@ AssetManager
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 2. 创建风险平价策略
|
#### 3.2 创建风险平价策略
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@ -115,7 +212,7 @@ AssetManager
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 3. 创建吊灯止损策略
|
#### 3.3 创建吊灯止损策略
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@ -136,12 +233,115 @@ AssetManager
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
"code": 200,
|
||||||
|
"data": {
|
||||||
"Id": "12345678-1234-1234-1234-1234567890ab",
|
"Id": "12345678-1234-1234-1234-1234567890ab",
|
||||||
"Title": "双均线策略",
|
"Title": "双均线策略",
|
||||||
"Status": "created"
|
"Type": "ma_trend",
|
||||||
|
"Description": "经典趋势跟踪策略",
|
||||||
|
"RiskLevel": "medium",
|
||||||
|
"Tags": ["趋势", "均线"],
|
||||||
|
"Parameters": {
|
||||||
|
"maType": "SMA",
|
||||||
|
"shortPeriod": 20,
|
||||||
|
"longPeriod": 60
|
||||||
|
},
|
||||||
|
"UserId": "user-123",
|
||||||
|
"CreatedAt": "2024-01-01T10:00:00",
|
||||||
|
"UpdatedAt": "2024-01-01T10:00:00"
|
||||||
|
},
|
||||||
|
"message": "Strategy created successfully"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 4. 更新策略
|
||||||
|
|
||||||
|
**请求 URL**: `PUT /api/v1/strategy/{id}`
|
||||||
|
|
||||||
|
**请求头**:
|
||||||
|
```
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
Content-Type: application/json
|
||||||
|
```
|
||||||
|
|
||||||
|
**请求体示例**:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"name": "双均线策略(更新)",
|
||||||
|
"type": "ma_trend",
|
||||||
|
"parameters": {
|
||||||
|
"maType": "EMA",
|
||||||
|
"shortPeriod": 15,
|
||||||
|
"longPeriod": 50
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**响应示例**:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"data": {
|
||||||
|
"Id": "12345678-1234-1234-1234-1234567890ab",
|
||||||
|
"Title": "双均线策略(更新)",
|
||||||
|
"Type": "ma_trend",
|
||||||
|
"Description": "经典趋势跟踪策略",
|
||||||
|
"RiskLevel": "medium",
|
||||||
|
"Tags": ["趋势", "均线"],
|
||||||
|
"Parameters": {
|
||||||
|
"maType": "EMA",
|
||||||
|
"shortPeriod": 15,
|
||||||
|
"longPeriod": 50
|
||||||
|
},
|
||||||
|
"UserId": "user-123",
|
||||||
|
"CreatedAt": "2024-01-01T10:00:00",
|
||||||
|
"UpdatedAt": "2024-01-15T14:30:00"
|
||||||
|
},
|
||||||
|
"message": "Strategy updated successfully"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. 删除策略
|
||||||
|
|
||||||
|
**请求 URL**: `DELETE /api/v1/strategy/{id}`
|
||||||
|
|
||||||
|
**请求头**:
|
||||||
|
```
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
```
|
||||||
|
|
||||||
|
**响应示例**:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"data": {
|
||||||
|
"id": "12345678-1234-1234-1234-1234567890ab",
|
||||||
|
"status": "deleted"
|
||||||
|
},
|
||||||
|
"message": "Strategy deleted successfully"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 错误响应格式
|
||||||
|
|
||||||
|
所有策略接口在发生错误时都会返回统一的错误格式:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 401,
|
||||||
|
"data": null,
|
||||||
|
"message": "用户未授权"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**常见错误码**:
|
||||||
|
- `401`: 用户未授权
|
||||||
|
- `404`: 策略不存在
|
||||||
|
- `500`: 服务器内部错误
|
||||||
|
|
||||||
## 💼 投资组合 API (Portfolio API)
|
## 💼 投资组合 API (Portfolio API)
|
||||||
|
|
||||||
### 1. 创建投资组合
|
### 1. 创建投资组合
|
||||||
@ -325,20 +525,6 @@ Authorization: Bearer {token}
|
|||||||
"profitRate": -0.03,
|
"profitRate": -0.03,
|
||||||
"currency": "USD"
|
"currency": "USD"
|
||||||
}
|
}
|
||||||
],
|
|
||||||
"transactions": [
|
|
||||||
{
|
|
||||||
"id": "trans-abc12345",
|
|
||||||
"portfolioId": "port-abc12345",
|
|
||||||
"date": "2024-01-01",
|
|
||||||
"time": "10:30:00",
|
|
||||||
"type": "buy",
|
|
||||||
"title": "初始建仓",
|
|
||||||
"amount": 100,
|
|
||||||
"currency": "USD",
|
|
||||||
"status": "completed",
|
|
||||||
"remark": "初始建仓"
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"message": "success"
|
"message": "success"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user