add
This commit is contained in:
@@ -14,32 +14,32 @@ import (
|
||||
type TradingRecordsCreateRequest struct {
|
||||
EventType string `json:"event_type" binding:"required"` // 固定为 "futures_trade"
|
||||
Payload struct {
|
||||
OpenYear int `json:"open_year" binding:"required,min=1900,max=2100"`
|
||||
OpenMonth int `json:"open_month" binding:"required,min=1,max=12"`
|
||||
OpenDay int `json:"open_day" binding:"required,min=1,max=31"`
|
||||
Symbol string `json:"symbol" binding:"required"`
|
||||
Contract string `json:"contract" binding:"required"`
|
||||
Direction string `json:"direction" binding:"required,oneof=long short"`
|
||||
OpenPrice float64 `json:"open_price" binding:"required"`
|
||||
OpenFee float64 `json:"open_fee" binding:"required,min=0"`
|
||||
CloseYear int `json:"close_year" binding:"required,min=1900,max=2100"`
|
||||
CloseMonth int `json:"close_month" binding:"required,min=1,max=12"`
|
||||
CloseDay int `json:"close_day" binding:"required,min=1,max=31"`
|
||||
ClosePrice float64 `json:"close_price" binding:"required"`
|
||||
CloseFee float64 `json:"close_fee" binding:"required,min=0"`
|
||||
PriceDiff float64 `json:"price_diff" binding:"required"`
|
||||
MinTick float64 `json:"min_tick" binding:"required"`
|
||||
TickPrice float64 `json:"tick_price" binding:"required"`
|
||||
DiffPnL float64 `json:"diff_pnl" binding:"required"`
|
||||
TotalFee float64 `json:"total_fee" binding:"required,min=0"`
|
||||
ClosePnL float64 `json:"close_pnl" binding:"required"`
|
||||
OpenYear int `json:"open_year" binding:"required,min=1900,max=2200"` // 开仓时间:年(1900-2200)
|
||||
OpenMonth int `json:"open_month" binding:"required,min=1,max=12"` // 开仓时间:月(1-12)
|
||||
OpenDay int `json:"open_day" binding:"required,min=1,max=31"` // 开仓时间:日(1-31)
|
||||
Symbol string `json:"symbol" binding:"required"` // 品种代码(如 RB、CU)
|
||||
Contract string `json:"contract" binding:"required"` // 合约代码(如 2505)
|
||||
Direction string `json:"direction" binding:"required,oneof=long short"` // 交易方向:long 多头 / short 空头
|
||||
OpenPrice float64 `json:"open_price" binding:"required"` // 开仓价格(单位:元)
|
||||
OpenFee float64 `json:"open_fee" binding:"required,min=0"` // 开仓手续费(≥0)
|
||||
CloseYear int `json:"close_year" binding:"required,min=1900,max=2100"` // 平仓时间:年(1900-2200)
|
||||
CloseMonth int `json:"close_month" binding:"required,min=1,max=12"` // 平仓时间:月(1-12)
|
||||
CloseDay int `json:"close_day" binding:"required,min=1,max=31"` // 平仓时间:日(1-31)
|
||||
ClosePrice float64 `json:"close_price" binding:"required"` // 平仓价格(单位:元)
|
||||
CloseFee float64 `json:"close_fee" binding:"required,min=0"` // 平仓手续费(≥0)
|
||||
PriceDiff float64 `json:"price_diff" binding:"required"` // 平仓差价 = ClosePrice - OpenPrice
|
||||
MinTick float64 `json:"min_tick" binding:"required"` // 品种最小跳点(如 1)
|
||||
TickPrice float64 `json:"tick_price" binding:"required"` // 每跳价格(如 10 元)
|
||||
DiffPnL float64 `json:"diff_pnl" binding:"required"` // 差价盈亏(已考虑方向与跳点)
|
||||
TotalFee float64 `json:"total_fee" binding:"required,min=0"` // 手续费合计 = OpenFee + CloseFee(≥0)
|
||||
ClosePnL float64 `json:"close_pnl" binding:"required"` // 平仓净盈亏 = DiffPnL - TotalFee
|
||||
} `json:"payload" binding:"required"`
|
||||
}
|
||||
|
||||
// TradingRecordsCreateResponse 创建响应结构
|
||||
type TradingRecordsCreateResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
Data TradingRecordsCreateData `json:"data"`
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ type TradingRecordsCreateData struct {
|
||||
RecordID string `json:"record_id"`
|
||||
}
|
||||
|
||||
// TradingRecordsCreateHandler 处理交易记录创建逻辑
|
||||
func TradingRecordsCreateHandler(c *gin.Context) {
|
||||
// CreateHandler 处理交易记录创建逻辑
|
||||
func CreateHandler(c *gin.Context) {
|
||||
startTime := time.Now()
|
||||
reqID := c.Request.Header.Get("X-TradingRecordsRequest-ID")
|
||||
if reqID == "" {
|
||||
@@ -118,8 +118,8 @@ func TradingRecordsCreateHandler(c *gin.Context) {
|
||||
// 插入交易记录
|
||||
var recordID string
|
||||
err = tx.QueryRow(
|
||||
`INSERT INTO trading_records (event_type, payload, deleted, created_at, updated_at)
|
||||
VALUES ($1, $2, FALSE, NOW(), NOW())
|
||||
`INSERT INTO trading_records (event_type, payload)
|
||||
VALUES ($1, $2)
|
||||
RETURNING id`,
|
||||
req.EventType,
|
||||
req.Payload,
|
||||
|
||||
Reference in New Issue
Block a user