types: assign orderID to profit object

This commit is contained in:
c9s 2022-09-07 11:57:09 +08:00
parent 889318ddcb
commit 4c3334c482
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
3 changed files with 9 additions and 0 deletions

View File

@ -106,6 +106,7 @@ func (p *Position) NewProfit(trade Trade, profit, netProfit fixedpoint.Value) Pr
NetProfitMargin: netProfit.Div(trade.QuoteQuantity), NetProfitMargin: netProfit.Div(trade.QuoteQuantity),
// trade related fields // trade related fields
TradeID: trade.ID, TradeID: trade.ID,
OrderID: trade.OrderID,
Side: trade.Side, Side: trade.Side,
IsBuyer: trade.IsBuyer, IsBuyer: trade.IsBuyer,
IsMaker: trade.IsMaker, IsMaker: trade.IsMaker,

View File

@ -38,6 +38,7 @@ type Profit struct {
// -------------------------------------------- // --------------------------------------------
// TradeID is the exchange trade id of that trade // TradeID is the exchange trade id of that trade
TradeID uint64 `json:"tradeID" db:"trade_id"` TradeID uint64 `json:"tradeID" db:"trade_id"`
OrderID uint64 `json:"orderID,omitempty"`
Side SideType `json:"side" db:"side"` Side SideType `json:"side" db:"side"`
IsBuyer bool `json:"isBuyer" db:"is_buyer"` IsBuyer bool `json:"isBuyer" db:"is_buyer"`
IsMaker bool `json:"isMaker" db:"is_maker"` IsMaker bool `json:"isMaker" db:"is_maker"`

View File

@ -169,6 +169,8 @@ type TradeStats struct {
Profits []fixedpoint.Value `json:"profits,omitempty" yaml:"profits,omitempty"` Profits []fixedpoint.Value `json:"profits,omitempty" yaml:"profits,omitempty"`
Losses []fixedpoint.Value `json:"losses,omitempty" yaml:"losses,omitempty"` Losses []fixedpoint.Value `json:"losses,omitempty" yaml:"losses,omitempty"`
orderProfits map[uint64]*Profit
LargestProfitTrade fixedpoint.Value `json:"largestProfitTrade,omitempty" yaml:"largestProfitTrade"` LargestProfitTrade fixedpoint.Value `json:"largestProfitTrade,omitempty" yaml:"largestProfitTrade"`
LargestLossTrade fixedpoint.Value `json:"largestLossTrade,omitempty" yaml:"largestLossTrade"` LargestLossTrade fixedpoint.Value `json:"largestLossTrade,omitempty" yaml:"largestLossTrade"`
AverageProfitTrade fixedpoint.Value `json:"averageProfitTrade" yaml:"averageProfitTrade"` AverageProfitTrade fixedpoint.Value `json:"averageProfitTrade" yaml:"averageProfitTrade"`
@ -241,7 +243,12 @@ func (s *TradeStats) Add(profit *Profit) {
return return
} }
if s.orderProfits == nil {
s.orderProfits = make(map[uint64]*Profit)
}
s.add(profit.Profit) s.add(profit.Profit)
for _, v := range s.IntervalProfits { for _, v := range s.IntervalProfits {
v.Update(profit) v.Update(profit)
} }