diff --git a/internal/trading/trading_plan.go b/internal/trading/trading_plan.go index a732a87..ced6596 100644 --- a/internal/trading/trading_plan.go +++ b/internal/trading/trading_plan.go @@ -15,7 +15,7 @@ type TradingPlan struct { StrategyName string `json:"strategyName"` } -func NewTradingPlan(plan entity.TradingPlan, strategy strategy.ISigStrategy) *TradingPlan { +func NewTradingPlan(plan entity.TradePlan, strategy strategy.ISigStrategy) *TradingPlan { return &TradingPlan{} } diff --git a/pkg/data/entity/trade_order.go b/pkg/data/entity/trade_order.go new file mode 100644 index 0000000..4dd226b --- /dev/null +++ b/pkg/data/entity/trade_order.go @@ -0,0 +1,54 @@ +package entity + +import ( + "github.com/govalues/decimal" +) + +// TradeOrder 交易计划订单 +type TradeOrder struct { + Id int64 `gorm:"column:id;primaryKey" json:"id"` // 订单id + UserId int64 `gorm:"column:user_id" json:"userId"` // 用户id + PlanId int64 `gorm:"column:plan_id" json:"planId"` // 交易计划id + Side int8 `gorm:"column:side" json:"side"` // 交易方向:0.空,1.多 + Status int8 `gorm:"column:status" json:"status"` // 状态:0.padding,1交易完成,2.交易中,3交易取消 + Exchange int8 `gorm:"column:exchange" json:"exchange"` // 交易所: 1.okx, 2.binance + InstId string `gorm:"column:inst_id" json:"instId"` // 交易产品id + InstType int8 `gorm:"column:inst_type" json:"instType"` // 交易产品类型:1现货2永续合约 + OrderType int8 `gorm:"column:order_type" json:"orderType"` // 订单类型:1.限价单,2.市价单 + Leverage int `gorm:"column:leverage" json:"leverage"` // 杠杆倍数 + SigPrice decimal.Decimal `gorm:"column:sig_price" json:"sigPrice"` // 下单价格(市价单为空 + SigVol decimal.Decimal `gorm:"column:sig_vol" json:"sigVol"` // 下单数量 + SigVolQuantity decimal.Decimal `gorm:"column:sig_vol_quantity" json:"sigVolQuantity"` // 下单金额 + TradePrice decimal.Decimal `gorm:"column:trade_price" json:"tradePrice"` // 成交价格(平均价 + TradeQuantity decimal.Decimal `gorm:"column:trade_quantity" json:"tradeQuantity"` // 成交数量 + TradeAmount decimal.Decimal `gorm:"column:trade_amount" json:"tradeAmount"` // 成交金额 + TradeTime int64 `gorm:"column:trade_time" json:"tradeTime"` // 成交时间 + CreateTime int64 `gorm:"column:create_time" json:"createTime"` // 创建时间 + UpdateTime int64 `gorm:"column:update_time" json:"updateTime"` // 更新时间 +} + +func (TradeOrder) TableName() string { + return "t_trade_order" +} + +// TradeOrderClose 交易平仓订单 +type TradeOrderClose struct { + Id int64 `gorm:"column:id;primaryKey" json:"id"` // 平仓单id + OrderId int64 `gorm:"column:order_id" json:"orderId"` // 交易订单id + Status int8 `gorm:"column:status" json:"status"` // 状态:0.padding,1交易完成,2.交易中,3交易取消 + Exchange int8 `gorm:"column:exchange" json:"exchange"` // 交易所 + InstId string `gorm:"column:inst_id" json:"instId"` // 交易产品id + CloseSide int8 `gorm:"column:close_side" json:"closeSide"` // 平仓方向:0.空,1.多 + ClosePrice decimal.Decimal `gorm:"column:close_price" json:"closePrice"` // 平仓价格 + CloseAmount decimal.Decimal `gorm:"column:close_amount" json:"closeAmount"` // 平仓金额 + CloseQuantity decimal.Decimal `gorm:"column:close_quantity" json:"closeQuantity"` // 平仓数量 + Pnl decimal.Decimal `gorm:"column:pnl" json:"pnl"` // 盈亏金额(计算:(close_price - entry_price) * quantity * side_factor) + PnlPercent decimal.Decimal `gorm:"column:pnl_percent" json:"pnlPercent"` // 盈亏百分比 + TradeTime int64 `gorm:"column:trade_time" json:"tradeTime"` // 成交时间 + CreateTime int64 `gorm:"column:create_time" json:"createTime"` // 创建时间戳毫秒 + UpdateTime int64 `gorm:"column:update_time" json:"updateTime"` // 更新时间戳毫秒 +} + +func (TradeOrderClose) TableName() string { + return "t_trade_order_close" +} diff --git a/pkg/data/entity/trade_plan.go b/pkg/data/entity/trade_plan.go index 3d991af..5ac0a19 100644 --- a/pkg/data/entity/trade_plan.go +++ b/pkg/data/entity/trade_plan.go @@ -1,21 +1,23 @@ package entity -import ( - "sig-pub/api/pb" - "sig-pub/pkg/types" -) - -type TradingPlan struct { - Id int64 `gorm:"column:id;primaryKey" json:"id"` // 交易计划id - Userid string `gorm:"column:userid" json:"userid"` // 所属用户id - Exchange pb.ExchangeType `gorm:"column:exchange" json:"exchange"` // 交易所 - InstId string `gorm:"column:instId" json:"instId"` // 交易产品 - Interval types.Interval `gorm:"column:interval" json:"interval"` // 交易周期 - Strategy string `gorm:"column:strategy" json:"strategy"` // 策略名称 - UpdateBy string `gorm:"column:update_by" json:"updateBy"` // 更新人 - UpdateTime int64 `gorm:"column:update_time" json:"updateTime"` // 更新时间戳毫秒 +// TradePlan 交易计划 +type TradePlan struct { + Id int64 `gorm:"column:id;primaryKey" json:"id"` // id + UserId int64 `gorm:"column:user_id" json:"userId"` // 用户id + Status int8 `gorm:"column:status" json:"status"` // 状态:0禁用,1启用 + Exchange int8 `gorm:"column:exchange" json:"exchange"` // 交易所 + InstId string `gorm:"column:inst_id" json:"instId"` // 交易产品id + Interval string `gorm:"column:interval" json:"interval"` // 交易周期 + SigStrategy string `gorm:"column:sig_strategy" json:"sigStrategy"` // 交易信号策略 + ExitStrategy string `gorm:"column:exit_strategy" json:"exitStrategy"` // 退出策略 + TradeStrategy string `gorm:"column:trade_strategy" json:"tradeStrategy"` // 下单仓位管理策略 + SigStrategyParams string `gorm:"column:sig_strategy_params" json:"sigStrategyParams"` // 交易信号策略参数 + ExitStrategyParams string `gorm:"column:exit_strategy_params" json:"exitStrategyParams"` // 退出策略名称参数 + TradeStrategyParams string `gorm:"column:trade_strategy_params" json:"tradeStrategyParams"` // 下单仓位管理策略参数 + UpdateBy string `gorm:"column:update_by" json:"updateBy"` // 更新人 + UpdateTime int64 `gorm:"column:update_time" json:"updateTime"` // 更新时间戳毫秒 } -func (TradingPlan) TableName() string { - return "t_trading_plan" +func (TradePlan) TableName() string { + return "t_trade_plan" }