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.
75 lines
2.4 KiB
75 lines
2.4 KiB
package trade |
|
|
|
import ( |
|
"sig-pub/pkg/types" |
|
) |
|
|
|
type Cause int32 |
|
|
|
const ( |
|
// _ Cause = iota |
|
CauseCloseForced Cause = 1001 // 平仓:强制平仓 |
|
CauseCloseStoploss Cause = 1002 // 平仓:固定止损 |
|
CauseCloseTakeprofit Cause = 1003 // 平仓:固定止盈 |
|
CauseCloseReverseSingal Cause = 1004 // 平仓:策略反向信号 |
|
CauseCloseTrailing Cause = 1005 // 平仓:移动止损基于最高利润点回撤百分比 |
|
CauseRiskAlreadyTrade Cause = 2001 // 风控:已有持仓 |
|
CauseRiskSideAlreadyTrade Cause = 2002 // 风控:相同方向已有持仓 |
|
) |
|
|
|
func (c Cause) String() string { |
|
switch c { |
|
default: |
|
return "" |
|
case CauseCloseForced: |
|
return "closeForced" |
|
case CauseCloseStoploss: |
|
return "closeStoploss" |
|
case CauseCloseTakeprofit: |
|
return "closeTakeprofit" |
|
case CauseCloseReverseSingal: |
|
return "closeReverseSingal" |
|
case CauseCloseTrailing: |
|
return "closeTrailing" |
|
case CauseRiskAlreadyTrade: |
|
return "riskAlreadyTrade" |
|
case CauseRiskSideAlreadyTrade: |
|
return "riskSideAlreadyTrade" |
|
} |
|
} |
|
|
|
// Position 持仓仓位 |
|
type Position struct { |
|
TradeId int64 // 交易订单id |
|
InstId string // 交易产品id |
|
Status int32 // 1.交易中 2.持仓中 3.已平仓 |
|
Side types.Side // 交易方向 |
|
Qty float64 // 交易量 |
|
EntryPx float64 // 入场价格 |
|
EntryTs int64 // 入场时间 |
|
PeakPx float64 // highest (for long) or lowest (for short) observed price since entry |
|
AvgPx float64 // 平均持仓价格 |
|
Fee float64 // 手续费 |
|
FeeRate float64 // 手续费率 |
|
} |
|
|
|
// TradeOrder 交易订单 |
|
type TradeOrder struct { |
|
InstId string // 交易产品id |
|
Status int32 // 1.交易中 2.持仓中 3.已平仓 |
|
Ctime int64 // 创建时间 |
|
Side types.Side // 交易方向 |
|
Qty float64 // 交易量 |
|
Price float64 // 开仓价格 |
|
Fee float64 // 开仓手续费 |
|
Leverage int32 // 杠杆倍数 |
|
Time int64 // 开仓时间 |
|
// ClosePrice float64 // 平仓价格 |
|
// CloseFee float64 // 平仓手续费 |
|
// CloseTime int64 // 平仓时间 |
|
// CloseCause Cause // 平仓原因 |
|
Pnl float64 // 盈利/亏损 pnl = (t.ClosePrice-t.Price)*t.Qty - t.Fee - t.CloseFee |
|
Cash float64 // 平仓后账户净值 |
|
HoldTime string // 持仓时间 |
|
PeakPx float64 // highest (for long) or lowest (for short) observed price since entry |
|
}
|
|
|