mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 16:55:15 +00:00
xfunding: initialize NeutralPosition
This commit is contained in:
parent
5c21445b15
commit
23746678b4
|
@ -110,9 +110,21 @@ type Strategy struct {
|
||||||
Reset bool `json:"reset"`
|
Reset bool `json:"reset"`
|
||||||
|
|
||||||
ProfitStats *types.ProfitStats `persistence:"profit_stats"`
|
ProfitStats *types.ProfitStats `persistence:"profit_stats"`
|
||||||
|
|
||||||
|
// SpotPosition is used for the spot position (usually long position)
|
||||||
|
// so that we know how much spot we have bought and the average cost of the spot.
|
||||||
SpotPosition *types.Position `persistence:"spot_position"`
|
SpotPosition *types.Position `persistence:"spot_position"`
|
||||||
|
|
||||||
|
// FuturesPosition is used for the futures position
|
||||||
|
// this position is the reverse side of the spot position, when spot position is long, then the futures position will be short.
|
||||||
|
// but the base quantity should be the same as the spot position
|
||||||
FuturesPosition *types.Position `persistence:"futures_position"`
|
FuturesPosition *types.Position `persistence:"futures_position"`
|
||||||
|
|
||||||
|
// NeutralPosition is used for sharing spot/futures position
|
||||||
|
// when creating the spot position and futures position, there will be a spread between the spot position and the futures position.
|
||||||
|
// this neutral position can calculate the spread cost between these two positions
|
||||||
|
NeutralPosition *types.Position `persistence:"neutral_position"`
|
||||||
|
|
||||||
State *State `persistence:"state"`
|
State *State `persistence:"state"`
|
||||||
|
|
||||||
// mu is used for locking state
|
// mu is used for locking state
|
||||||
|
@ -241,12 +253,16 @@ func (s *Strategy) CrossRun(ctx context.Context, orderExecutionRouter bbgo.Order
|
||||||
s.ProfitStats = types.NewProfitStats(s.Market)
|
s.ProfitStats = types.NewProfitStats(s.Market)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.SpotPosition == nil || s.Reset {
|
||||||
|
s.SpotPosition = types.NewPositionFromMarket(s.spotMarket)
|
||||||
|
}
|
||||||
|
|
||||||
if s.FuturesPosition == nil || s.Reset {
|
if s.FuturesPosition == nil || s.Reset {
|
||||||
s.FuturesPosition = types.NewPositionFromMarket(s.futuresMarket)
|
s.FuturesPosition = types.NewPositionFromMarket(s.futuresMarket)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.SpotPosition == nil || s.Reset {
|
if s.NeutralPosition == nil || s.Reset {
|
||||||
s.SpotPosition = types.NewPositionFromMarket(s.spotMarket)
|
s.NeutralPosition = types.NewPositionFromMarket(s.futuresMarket)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.State == nil || s.Reset {
|
if s.State == nil || s.Reset {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user