mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-27 01:05:15 +00:00
63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
package xmaker
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
|
"github.com/c9s/bbgo/pkg/types"
|
|
)
|
|
|
|
type State struct {
|
|
CoveredPosition fixedpoint.Value `json:"coveredPosition,omitempty"`
|
|
Position *types.Position `json:"position,omitempty"`
|
|
ProfitStats ProfitStats `json:"profitStats,omitempty"`
|
|
}
|
|
|
|
type ProfitStats struct {
|
|
types.ProfitStats
|
|
lock sync.Mutex
|
|
|
|
MakerExchange types.ExchangeName `json:"makerExchange"`
|
|
|
|
AccumulatedMakerVolume fixedpoint.Value `json:"accumulatedMakerVolume,omitempty"`
|
|
AccumulatedMakerBidVolume fixedpoint.Value `json:"accumulatedMakerBidVolume,omitempty"`
|
|
AccumulatedMakerAskVolume fixedpoint.Value `json:"accumulatedMakerAskVolume,omitempty"`
|
|
|
|
TodayMakerVolume fixedpoint.Value `json:"todayMakerVolume,omitempty"`
|
|
TodayMakerBidVolume fixedpoint.Value `json:"todayMakerBidVolume,omitempty"`
|
|
TodayMakerAskVolume fixedpoint.Value `json:"todayMakerAskVolume,omitempty"`
|
|
}
|
|
|
|
func (s *ProfitStats) AddTrade(trade types.Trade) {
|
|
s.ProfitStats.AddTrade(trade)
|
|
|
|
if trade.Exchange == s.MakerExchange {
|
|
s.lock.Lock()
|
|
s.AccumulatedMakerVolume = s.AccumulatedMakerVolume.Add(trade.Quantity)
|
|
s.TodayMakerVolume = s.TodayMakerVolume.Add(trade.Quantity)
|
|
|
|
switch trade.Side {
|
|
|
|
case types.SideTypeSell:
|
|
s.AccumulatedMakerAskVolume = s.AccumulatedMakerAskVolume.Add(trade.Quantity)
|
|
s.TodayMakerAskVolume = s.TodayMakerAskVolume.Add(trade.Quantity)
|
|
|
|
case types.SideTypeBuy:
|
|
s.AccumulatedMakerBidVolume = s.AccumulatedMakerBidVolume.Add(trade.Quantity)
|
|
s.TodayMakerBidVolume = s.TodayMakerBidVolume.Add(trade.Quantity)
|
|
|
|
}
|
|
s.lock.Unlock()
|
|
}
|
|
}
|
|
|
|
func (s *ProfitStats) ResetToday() {
|
|
s.ProfitStats.ResetToday()
|
|
|
|
s.lock.Lock()
|
|
s.TodayMakerVolume = fixedpoint.Zero
|
|
s.TodayMakerBidVolume = fixedpoint.Zero
|
|
s.TodayMakerAskVolume = fixedpoint.Zero
|
|
s.lock.Unlock()
|
|
}
|