You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.2 KiB
60 lines
2.2 KiB
package trade |
|
|
|
import ( |
|
"sig-pub/pkg/strategy" |
|
"sig-pub/pkg/types" |
|
|
|
"github.com/govalues/decimal" |
|
) |
|
|
|
// ITradeAnalyzer 建仓到平仓分析器 |
|
type ITradeAnalyzer interface { |
|
IEntryAnalyzer |
|
IExitAnalyzer |
|
|
|
// Init 校验参数, 并根据参数初始化策略 |
|
Init(input types.Input) (err error) |
|
} |
|
|
|
// IEntryAnalyzer 建仓下单策略 |
|
type IEntryAnalyzer interface { |
|
strategy.ISigStrategy |
|
|
|
// 需要的各周期最小数据k线数 |
|
CandlePeriods(ctx strategy.IInstanceIntervalSigStrategyContext) (tradeInsts []string, iPeriods *types.IntervalState[int16]) |
|
|
|
// EntryAnalysis 生成下单参数(交易量/方向/杠杆) 建仓分析:确定是否入场、下单价格及仓位大小 |
|
// 币种持仓中不能改变杠杆 |
|
// tickets 建仓单信息 |
|
// skipCause 跳过交易信号原因 |
|
EntryAnalysis(ctx strategy.IInstanceIntervalSigStrategyContext, account ITradeAccount, sigInstId string, sigSide types.Side) (tickets []TradeTicket, skipCause Cause, err error) |
|
} |
|
|
|
// IExitAnalyzer 平仓评估评估、止盈止损策略(trading service 管理) |
|
type IExitAnalyzer interface { |
|
strategy.ISigStrategy |
|
|
|
// 需要的各周期最小数据k线数 |
|
CandlePeriods(ctx strategy.IInstanceIntervalSigStrategyContext) (tradeInsts []string, iPeriods *types.IntervalState[int16]) |
|
|
|
// ExitAnalysisOnPrice 价格更新评估是否平仓 |
|
// @return closeTicket平仓单信息 |
|
ExitAnalysisOnPrice(ctx strategy.IInstanceIntervalSigStrategyContext, account ITradeAccount, instId string, price float64) (closeTickets []TradeTicket, err error) |
|
|
|
// ExitAnalysisOnSig 信号触发时评估是否平仓 |
|
ExitAnalysisOnSig(ctx strategy.IInstanceIntervalSigStrategyContext, account ITradeAccount, instId string, sigSide types.Side) (closeTickets []TradeTicket, err error) |
|
} |
|
|
|
type TradeTicket struct { |
|
TradeType TradeType |
|
InstId string |
|
Side types.Side // 开仓方向 |
|
Price float64 // 开仓价格 |
|
Leverage int32 // 杠杆倍数 |
|
Qty decimal.Decimal // 交易量 qty为交易产品数量 todo decimal |
|
Interval string // k线周期 |
|
Ktime int64 // k线时间 |
|
Ctime int64 // 创建时间(ctime-ktime=信号延迟) |
|
Cause Cause |
|
TradesId []int64 // 关联交易订单id (仅平仓使用) |
|
}
|
|
|