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.
51 lines
1.5 KiB
51 lines
1.5 KiB
package trade |
|
|
|
import "sig-pub/pkg/types" |
|
|
|
// Position 持仓仓位 |
|
type Position struct { |
|
TradeId int64 // 交易订单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 |
|
Fee float64 // 手续费 |
|
FeeRate float64 // 手续费率 |
|
} |
|
|
|
type Trade struct { |
|
Id int64 // 交易id |
|
Side types.Side // 交易方向 |
|
Qty float64 // 交易量 |
|
Price float64 // 开仓价格 |
|
Fee float64 // 开仓手续费 |
|
Ts int64 // 开仓时间 |
|
ClosePrice float64 // 平仓价格 |
|
CloseFee float64 // 平仓手续费 |
|
CloseTs int64 // 平仓时间 |
|
CloseCause string // 平仓原因 ["stoploss", "takeprofit", "trailing", "retrace", "signal"](“止损”、“止盈”、“动态跟踪”、“回撤”、“信号”) |
|
Pnl float64 // 盈利/亏损 pnl = (t.ClosePrice-t.Price)*t.Qty - t.Fee - t.CloseFee |
|
HoldTime string // 持仓时间 |
|
} |
|
|
|
type Cause int32 |
|
|
|
const ( |
|
_ Cause = iota |
|
CauseStoploss // 固定止损 |
|
CauseTakeprofit // 固定止盈 |
|
CauseReverseSingal // 策略反向信号 |
|
) |
|
|
|
func (c Cause) String() string { |
|
switch c { |
|
default: |
|
return "" |
|
case CauseStoploss: |
|
return "stoploss" |
|
case CauseTakeprofit: |
|
return "takeprofit" |
|
} |
|
}
|
|
|