|
|
|
@ -1,6 +1,7 @@ |
|
|
|
package trade |
|
|
|
package trade |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"sig-pub/api/pb" |
|
|
|
"sig-pub/pkg/data" |
|
|
|
"sig-pub/pkg/data" |
|
|
|
"sig-pub/pkg/types" |
|
|
|
"sig-pub/pkg/types" |
|
|
|
|
|
|
|
|
|
|
|
@ -54,20 +55,49 @@ type Position struct { |
|
|
|
LastPx float64 // 最后更新价格
|
|
|
|
LastPx float64 // 最后更新价格
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// BacktestTradingPlan 交易计划回测结果
|
|
|
|
|
|
|
|
type BacktestTradingPlan struct { |
|
|
|
|
|
|
|
Id int64 `json:"id" gorm:"column:id;primaryKey"` // 测试id
|
|
|
|
|
|
|
|
UserId int64 `json:"userId" gorm:"column:user_id"` // 用户id
|
|
|
|
|
|
|
|
PlanId int64 `json:"planId" gorm:"column:plan_id"` // 交易计划id
|
|
|
|
|
|
|
|
InstId string `json:"instId" gorm:"column:inst_id"` // 交易产品id
|
|
|
|
|
|
|
|
Exchange pb.ExchangeType `json:"exchange" gorm:"column:exchange"` // 交易所
|
|
|
|
|
|
|
|
Interval string `json:"interval" gorm:"column:interval"` // 交易周期
|
|
|
|
|
|
|
|
SeriesBefore int64 `json:"seriesBefore" gorm:"column:series_before"` // 回测周期开始时间
|
|
|
|
|
|
|
|
SeriesAfter int64 `json:"seriesAfter" gorm:"column:series_after"` // 回测周期结束时间
|
|
|
|
|
|
|
|
Ctime int64 `json:"ctime" gorm:"column:ctime"` // 创建时间(测试时间)
|
|
|
|
|
|
|
|
Etime int64 `json:"etime" gorm:"column:etime"` // 测试结束时间
|
|
|
|
|
|
|
|
Cash float64 `json:"cash" gorm:"column:cash"` // 起始金额
|
|
|
|
|
|
|
|
EndCash float64 `json:"endCash" gorm:"column:end_cash"` // 结束金额
|
|
|
|
|
|
|
|
Profit float64 `json:"profit" gorm:"column:profit"` // 利润
|
|
|
|
|
|
|
|
Singals int `json:"singals" gorm:"column:singals"` // 交易信号数
|
|
|
|
|
|
|
|
TotalTrades int `json:"totalTrades" gorm:"column:total_trades"` // 总单数
|
|
|
|
|
|
|
|
WinningTrades int `json:"winningTrades" gorm:"column:winning_trades"` // 盈利单数
|
|
|
|
|
|
|
|
LosingTrades int `json:"losingTrades" gorm:"column:losing_trades"` // 亏损单数
|
|
|
|
|
|
|
|
Fee float64 `json:"fee" gorm:"column:fee"` // 总手续费
|
|
|
|
|
|
|
|
MaxDrawdown float64 `json:"maxDrawdown" gorm:"column:max_drawdown"` // 最大回撤
|
|
|
|
|
|
|
|
SharpeRatio float64 `json:"sharpeRatio" gorm:"column:sharpe_ratio"` // 夏普比率
|
|
|
|
|
|
|
|
Trades []*TradeOrder `json:"-" gorm:"-"` // 回测交易单
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (BacktestTradingPlan) TableName() string { |
|
|
|
|
|
|
|
return "t_backtest_trading_plan" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TradeOrder 交易订单
|
|
|
|
// TradeOrder 交易订单
|
|
|
|
type TradeOrder struct { |
|
|
|
type TradeOrder struct { |
|
|
|
BacktestId int64 `jsno:"backtestId" gorm:"column:backtest_id"` // 回测单id
|
|
|
|
BacktestId int64 `json:"backtestId" gorm:"column:backtest_id"` // 回测单id
|
|
|
|
TradeId int64 `jsno:"tradeId" gorm:"column:trade_id"` // 交易单id
|
|
|
|
TradeId int64 `json:"tradeId" gorm:"column:trade_id"` // 交易单id
|
|
|
|
TradeType TradeType `jsno:"tradeType" gorm:"column:trade_type"` // 交易类型: 1.开仓 2.平仓
|
|
|
|
TradeType TradeType `json:"tradeType" gorm:"column:trade_type"` // 交易类型: 1.开仓 2.平仓
|
|
|
|
InstId string `jsno:"instId" gorm:"column:inst_id"` // 交易产品id
|
|
|
|
InstId string `json:"instId" gorm:"column:inst_id"` // 交易产品id
|
|
|
|
Side types.Side `jsno:"side" gorm:"column:side"` // 交易方向
|
|
|
|
Side types.Side `json:"side" gorm:"column:side"` // 交易方向
|
|
|
|
Qty decimal.Decimal `jsno:"qty" gorm:"column:qty"` // 交易量
|
|
|
|
Qty decimal.Decimal `json:"qty" gorm:"column:qty"` // 交易量
|
|
|
|
Price float64 `jsno:"price" gorm:"column:price"` // 交易价格
|
|
|
|
Price float64 `json:"price" gorm:"column:price"` // 交易价格
|
|
|
|
Fee float64 `jsno:"fee" gorm:"column:fee"` // 手续费
|
|
|
|
Fee float64 `json:"fee" gorm:"column:fee"` // 手续费
|
|
|
|
Leverage int32 `jsno:"leverage" gorm:"column:leverage"` // 杠杆倍数
|
|
|
|
Leverage int32 `json:"leverage" gorm:"column:leverage"` // 杠杆倍数
|
|
|
|
Ctime int64 `jsno:"ctime" gorm:"column:ctime"` // 交易时间
|
|
|
|
Ctime int64 `json:"ctime" gorm:"column:ctime"` // 交易时间
|
|
|
|
Status data.Status `jsno:"status" gorm:"column:status"` // 1.交易成功 2.交易中 4.交易失败
|
|
|
|
Status data.Status `json:"status" gorm:"column:status"` // 1.交易成功 2.交易中 4.交易失败
|
|
|
|
PeakPx float64 `jsno:"peakPx" gorm:"column:peak_px"` // 持仓最高价格(空单最低价格)
|
|
|
|
PeakPx float64 `json:"peakPx" gorm:"column:peak_px"` // 持仓最高价格(空单最低价格)
|
|
|
|
// ----------------- 平仓单信息
|
|
|
|
// ----------------- 平仓单信息
|
|
|
|
CloseCause Cause `json:"closeCause" gorm:"column:close_cause"` // 平仓原因 ["stoploss", "takeprofit", "trailing", "retrace", "signal"](“止损”、“止盈”、“动态跟踪”、“回撤”、“信号”)
|
|
|
|
CloseCause Cause `json:"closeCause" gorm:"column:close_cause"` // 平仓原因 ["stoploss", "takeprofit", "trailing", "retrace", "signal"](“止损”、“止盈”、“动态跟踪”、“回撤”、“信号”)
|
|
|
|
Equity float64 `json:"equity" gorm:"column:equity"` // 平仓后账户净值
|
|
|
|
Equity float64 `json:"equity" gorm:"column:equity"` // 平仓后账户净值
|
|
|
|
|