mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
Merge pull request #1781 from c9s/c9s/xmaker/improvements2
FIX: [xmaker] fix covered position field
This commit is contained in:
commit
a6f5d5fff1
|
@ -204,7 +204,8 @@ type Strategy struct {
|
||||||
// persistence fields
|
// persistence fields
|
||||||
Position *types.Position `json:"position,omitempty" persistence:"position"`
|
Position *types.Position `json:"position,omitempty" persistence:"position"`
|
||||||
ProfitStats *ProfitStats `json:"profitStats,omitempty" persistence:"profit_stats"`
|
ProfitStats *ProfitStats `json:"profitStats,omitempty" persistence:"profit_stats"`
|
||||||
CoveredPosition fixedpoint.MutexValue `json:"coveredPosition,omitempty" persistence:"covered_position"`
|
|
||||||
|
coveredPosition fixedpoint.MutexValue
|
||||||
|
|
||||||
sourceBook, makerBook *types.StreamOrderBook
|
sourceBook, makerBook *types.StreamOrderBook
|
||||||
activeMakerOrders *bbgo.ActiveOrderBook
|
activeMakerOrders *bbgo.ActiveOrderBook
|
||||||
|
@ -1284,9 +1285,9 @@ func (s *Strategy) Hedge(ctx context.Context, pos fixedpoint.Value) {
|
||||||
|
|
||||||
// if it's selling, then we should add a positive position
|
// if it's selling, then we should add a positive position
|
||||||
if side == types.SideTypeSell {
|
if side == types.SideTypeSell {
|
||||||
s.CoveredPosition.Add(quantity)
|
s.coveredPosition.Add(quantity)
|
||||||
} else {
|
} else {
|
||||||
s.CoveredPosition.Add(quantity.Neg())
|
s.coveredPosition.Add(quantity.Neg())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1499,7 +1500,7 @@ func (s *Strategy) hedgeWorker(ctx context.Context) {
|
||||||
s.setPositionStartTime(tt)
|
s.setPositionStartTime(tt)
|
||||||
}
|
}
|
||||||
|
|
||||||
coveredPosition := s.CoveredPosition.Get()
|
coveredPosition := s.coveredPosition.Get()
|
||||||
uncoverPosition := position.Sub(coveredPosition)
|
uncoverPosition := position.Sub(coveredPosition)
|
||||||
absPos := uncoverPosition.Abs()
|
absPos := uncoverPosition.Abs()
|
||||||
|
|
||||||
|
@ -1744,7 +1745,7 @@ func (s *Strategy) CrossRun(
|
||||||
s.tradeCollector.OnTrade(func(trade types.Trade, profit, netProfit fixedpoint.Value) {
|
s.tradeCollector.OnTrade(func(trade types.Trade, profit, netProfit fixedpoint.Value) {
|
||||||
c := trade.PositionChange()
|
c := trade.PositionChange()
|
||||||
if trade.Exchange == s.sourceSession.ExchangeName {
|
if trade.Exchange == s.sourceSession.ExchangeName {
|
||||||
s.CoveredPosition.Add(c)
|
s.coveredPosition.Add(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.ProfitStats.AddTrade(trade)
|
s.ProfitStats.AddTrade(trade)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user