2022-01-08 16:30:18 +00:00
|
|
|
package xmaker
|
|
|
|
|
|
|
|
import (
|
fix bollgrid, emstop, flashcrash, funding, grid, pricealert, pricedrop, rebalance, schedule, swing, xbalance, xgap, xmaker and speedup fixedpoint
2022-02-04 11:39:23 +00:00
|
|
|
"sync"
|
2022-09-19 01:32:26 +00:00
|
|
|
"time"
|
fix bollgrid, emstop, flashcrash, funding, grid, pricealert, pricedrop, rebalance, schedule, swing, xbalance, xgap, xmaker and speedup fixedpoint
2022-02-04 11:39:23 +00:00
|
|
|
|
2022-01-08 16:30:18 +00:00
|
|
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
|
|
|
"github.com/c9s/bbgo/pkg/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type State struct {
|
|
|
|
CoveredPosition fixedpoint.Value `json:"coveredPosition,omitempty"`
|
2022-05-05 07:05:38 +00:00
|
|
|
|
|
|
|
// Deprecated:
|
2022-06-17 04:01:15 +00:00
|
|
|
Position *types.Position `json:"position,omitempty"`
|
2022-05-05 07:05:38 +00:00
|
|
|
|
|
|
|
// Deprecated:
|
2022-06-17 04:01:15 +00:00
|
|
|
ProfitStats ProfitStats `json:"profitStats,omitempty"`
|
2022-01-08 16:30:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ProfitStats struct {
|
2022-05-05 07:05:38 +00:00
|
|
|
*types.ProfitStats
|
|
|
|
|
2022-02-15 05:55:19 +00:00
|
|
|
lock sync.Mutex
|
2022-01-08 16:30:18 +00:00
|
|
|
|
|
|
|
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 {
|
fix bollgrid, emstop, flashcrash, funding, grid, pricealert, pricedrop, rebalance, schedule, swing, xbalance, xgap, xmaker and speedup fixedpoint
2022-02-04 11:39:23 +00:00
|
|
|
s.lock.Lock()
|
|
|
|
s.AccumulatedMakerVolume = s.AccumulatedMakerVolume.Add(trade.Quantity)
|
|
|
|
s.TodayMakerVolume = s.TodayMakerVolume.Add(trade.Quantity)
|
2022-01-08 16:30:18 +00:00
|
|
|
|
|
|
|
switch trade.Side {
|
|
|
|
|
|
|
|
case types.SideTypeSell:
|
fix bollgrid, emstop, flashcrash, funding, grid, pricealert, pricedrop, rebalance, schedule, swing, xbalance, xgap, xmaker and speedup fixedpoint
2022-02-04 11:39:23 +00:00
|
|
|
s.AccumulatedMakerAskVolume = s.AccumulatedMakerAskVolume.Add(trade.Quantity)
|
|
|
|
s.TodayMakerAskVolume = s.TodayMakerAskVolume.Add(trade.Quantity)
|
2022-01-08 16:30:18 +00:00
|
|
|
|
|
|
|
case types.SideTypeBuy:
|
fix bollgrid, emstop, flashcrash, funding, grid, pricealert, pricedrop, rebalance, schedule, swing, xbalance, xgap, xmaker and speedup fixedpoint
2022-02-04 11:39:23 +00:00
|
|
|
s.AccumulatedMakerBidVolume = s.AccumulatedMakerBidVolume.Add(trade.Quantity)
|
|
|
|
s.TodayMakerBidVolume = s.TodayMakerBidVolume.Add(trade.Quantity)
|
2022-01-08 16:30:18 +00:00
|
|
|
|
|
|
|
}
|
fix bollgrid, emstop, flashcrash, funding, grid, pricealert, pricedrop, rebalance, schedule, swing, xbalance, xgap, xmaker and speedup fixedpoint
2022-02-04 11:39:23 +00:00
|
|
|
s.lock.Unlock()
|
2022-01-08 16:30:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ProfitStats) ResetToday() {
|
2022-09-19 01:32:26 +00:00
|
|
|
s.ProfitStats.ResetToday(time.Now())
|
fix bollgrid, emstop, flashcrash, funding, grid, pricealert, pricedrop, rebalance, schedule, swing, xbalance, xgap, xmaker and speedup fixedpoint
2022-02-04 11:39:23 +00:00
|
|
|
|
|
|
|
s.lock.Lock()
|
|
|
|
s.TodayMakerVolume = fixedpoint.Zero
|
|
|
|
s.TodayMakerBidVolume = fixedpoint.Zero
|
|
|
|
s.TodayMakerAskVolume = fixedpoint.Zero
|
|
|
|
s.lock.Unlock()
|
2022-01-08 16:30:18 +00:00
|
|
|
}
|