mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
use the profit struct to pass profit info
This commit is contained in:
parent
fac14a8c7f
commit
45645d0a3d
|
@ -38,19 +38,19 @@ type ProfitStats struct {
|
|||
TodaySince int64 `json:"todaySince,omitempty"`
|
||||
}
|
||||
|
||||
func (s *ProfitStats) AddProfit(profit, netProfit fixedpoint.Value) {
|
||||
s.AccumulatedPnL += profit
|
||||
s.AccumulatedNetProfit += netProfit
|
||||
func (s *ProfitStats) AddProfit(profit Profit) {
|
||||
s.AccumulatedPnL += profit.Profit
|
||||
s.AccumulatedNetProfit += profit.NetProfit
|
||||
|
||||
s.TodayPnL += profit
|
||||
s.TodayNetProfit += netProfit
|
||||
s.TodayPnL += profit.Profit
|
||||
s.TodayNetProfit += profit.NetProfit
|
||||
|
||||
if profit < 0 {
|
||||
s.AccumulatedLoss += profit
|
||||
s.TodayLoss += profit
|
||||
} else if profit > 0 {
|
||||
s.AccumulatedProfit += profit
|
||||
s.TodayProfit += profit
|
||||
if profit.Profit < 0 {
|
||||
s.AccumulatedLoss += profit.Profit
|
||||
s.TodayLoss += profit.Profit
|
||||
} else if profit.Profit > 0 {
|
||||
s.AccumulatedProfit += profit.Profit
|
||||
s.TodayProfit += profit.Profit
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ type State struct {
|
|||
HedgePosition fixedpoint.Value `json:"hedgePosition"`
|
||||
CoveredPosition fixedpoint.Value `json:"coveredPosition,omitempty"`
|
||||
Position *bbgo.Position `json:"position,omitempty"`
|
||||
ProfitStats bbgo.ProfitStats `json:"profitStats,omitempty"`
|
||||
ProfitStats ProfitStats `json:"profitStats,omitempty"`
|
||||
}
|
||||
|
||||
type ProfitStats struct {
|
||||
|
@ -623,7 +623,10 @@ func (s *Strategy) processTrade(trade types.Trade) {
|
|||
s.state.ProfitStats.AddTrade(trade)
|
||||
|
||||
if profit, netProfit, madeProfit := s.state.Position.AddTrade(trade); madeProfit {
|
||||
s.state.ProfitStats.AddProfit(profit, netProfit)
|
||||
s.state.ProfitStats.AddProfit(bbgo.Profit{
|
||||
Profit: profit,
|
||||
NetProfit: netProfit,
|
||||
})
|
||||
|
||||
profitMargin := profit.DivFloat64(trade.QuoteQuantity)
|
||||
netProfitMargin := netProfit.DivFloat64(trade.QuoteQuantity)
|
||||
|
|
Loading…
Reference in New Issue
Block a user