mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +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"`
|
TodaySince int64 `json:"todaySince,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ProfitStats) AddProfit(profit, netProfit fixedpoint.Value) {
|
func (s *ProfitStats) AddProfit(profit Profit) {
|
||||||
s.AccumulatedPnL += profit
|
s.AccumulatedPnL += profit.Profit
|
||||||
s.AccumulatedNetProfit += netProfit
|
s.AccumulatedNetProfit += profit.NetProfit
|
||||||
|
|
||||||
s.TodayPnL += profit
|
s.TodayPnL += profit.Profit
|
||||||
s.TodayNetProfit += netProfit
|
s.TodayNetProfit += profit.NetProfit
|
||||||
|
|
||||||
if profit < 0 {
|
if profit.Profit < 0 {
|
||||||
s.AccumulatedLoss += profit
|
s.AccumulatedLoss += profit.Profit
|
||||||
s.TodayLoss += profit
|
s.TodayLoss += profit.Profit
|
||||||
} else if profit > 0 {
|
} else if profit.Profit > 0 {
|
||||||
s.AccumulatedProfit += profit
|
s.AccumulatedProfit += profit.Profit
|
||||||
s.TodayProfit += profit
|
s.TodayProfit += profit.Profit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ type State struct {
|
||||||
HedgePosition fixedpoint.Value `json:"hedgePosition"`
|
HedgePosition fixedpoint.Value `json:"hedgePosition"`
|
||||||
CoveredPosition fixedpoint.Value `json:"coveredPosition,omitempty"`
|
CoveredPosition fixedpoint.Value `json:"coveredPosition,omitempty"`
|
||||||
Position *bbgo.Position `json:"position,omitempty"`
|
Position *bbgo.Position `json:"position,omitempty"`
|
||||||
ProfitStats bbgo.ProfitStats `json:"profitStats,omitempty"`
|
ProfitStats ProfitStats `json:"profitStats,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProfitStats struct {
|
type ProfitStats struct {
|
||||||
|
@ -623,7 +623,10 @@ func (s *Strategy) processTrade(trade types.Trade) {
|
||||||
s.state.ProfitStats.AddTrade(trade)
|
s.state.ProfitStats.AddTrade(trade)
|
||||||
|
|
||||||
if profit, netProfit, madeProfit := s.state.Position.AddTrade(trade); madeProfit {
|
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)
|
profitMargin := profit.DivFloat64(trade.QuoteQuantity)
|
||||||
netProfitMargin := netProfit.DivFloat64(trade.QuoteQuantity)
|
netProfitMargin := netProfit.DivFloat64(trade.QuoteQuantity)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user