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.
61 lines
2.3 KiB
61 lines
2.3 KiB
package trade |
|
|
|
import ( |
|
"sig-pub/pkg/strategy" |
|
"sig-pub/pkg/types" |
|
|
|
"github.com/govalues/decimal" |
|
) |
|
|
|
// IRiskStrategy 风险控制接口 |
|
type IRiskStrategy interface { |
|
strategy.ISigStrategy |
|
|
|
// 需要的各周期最小数据k线数 |
|
CandlePeriods(ctx strategy.IInstanceIntervalSigStrategyContext) (tradeInsts []string, iPeriods *types.IntervalState[int16]) |
|
|
|
// RishAssess 信号风险评估, 是否进行交易 |
|
RishAssess(ctx strategy.IInstanceIntervalSigStrategyContext, account ITradeAccount, sigInstId string, sigSide types.Side) (ok bool, cause Cause, err error) |
|
} |
|
|
|
// ITradeStrategy 下单策略 |
|
type ITradeStrategy interface { |
|
strategy.ISigStrategy |
|
|
|
// 需要的各周期最小数据k线数 |
|
CandlePeriods(ctx strategy.IInstanceIntervalSigStrategyContext) (tradeInsts []string, iPeriods *types.IntervalState[int16]) |
|
|
|
// TradeAssess 生成下单参数(交易量/方向/杠杆) |
|
// 控制滑点, 仓位管理 |
|
// 持仓中币种不能改变杠杆 |
|
TradeAssess(ctx strategy.IInstanceIntervalSigStrategyContext, account ITradeAccount, sigInstId string, sigSide types.Side) (tickets []TradeTicket, err error) |
|
} |
|
|
|
// Exit 止盈止损策略(trading service 管理) |
|
type ICloseStrategy interface { |
|
strategy.ISigStrategy |
|
|
|
// 需要的各周期最小数据k线数 |
|
CandlePeriods(ctx strategy.IInstanceIntervalSigStrategyContext) (tradeInsts []string, iPeriods *types.IntervalState[int16]) |
|
|
|
// CloseAssess 价格更新评估是否平仓 |
|
// @return closeTicket平仓单信息 |
|
CloseAssessOnPrice(ctx strategy.IInstanceIntervalSigStrategyContext, account ITradeAccount, instId string, price float64) (closeTickets []TradeTicket, err error) |
|
|
|
// CloseAssessOnSig 信号触发时评估是否平仓 |
|
CloseAssessOnSig(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 (仅平仓使用) |
|
}
|
|
|