mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
types: group profits by order id
This commit is contained in:
parent
4c3334c482
commit
6b4661783d
|
@ -104,7 +104,9 @@ func (p *Position) NewProfit(trade Trade, profit, netProfit fixedpoint.Value) Pr
|
|||
NetProfit: netProfit,
|
||||
ProfitMargin: profit.Div(trade.QuoteQuantity),
|
||||
NetProfitMargin: netProfit.Div(trade.QuoteQuantity),
|
||||
|
||||
// trade related fields
|
||||
Trade: &trade,
|
||||
TradeID: trade.ID,
|
||||
OrderID: trade.OrderID,
|
||||
Side: trade.Side,
|
||||
|
|
|
@ -37,6 +37,7 @@ type Profit struct {
|
|||
// trade related fields
|
||||
// --------------------------------------------
|
||||
// TradeID is the exchange trade id of that trade
|
||||
Trade *Trade `json:"trade,omitempty" db:"-"`
|
||||
TradeID uint64 `json:"tradeID" db:"trade_id"`
|
||||
OrderID uint64 `json:"orderID,omitempty"`
|
||||
Side SideType `json:"side" db:"side"`
|
||||
|
|
|
@ -169,7 +169,7 @@ type TradeStats struct {
|
|||
Profits []fixedpoint.Value `json:"profits,omitempty" yaml:"profits,omitempty"`
|
||||
Losses []fixedpoint.Value `json:"losses,omitempty" yaml:"losses,omitempty"`
|
||||
|
||||
orderProfits map[uint64]*Profit
|
||||
orderProfits map[uint64][]*Profit
|
||||
|
||||
LargestProfitTrade fixedpoint.Value `json:"largestProfitTrade,omitempty" yaml:"largestProfitTrade"`
|
||||
LargestLossTrade fixedpoint.Value `json:"largestLossTrade,omitempty" yaml:"largestLossTrade"`
|
||||
|
@ -244,7 +244,11 @@ func (s *TradeStats) Add(profit *Profit) {
|
|||
}
|
||||
|
||||
if s.orderProfits == nil {
|
||||
s.orderProfits = make(map[uint64]*Profit)
|
||||
s.orderProfits = make(map[uint64][]*Profit)
|
||||
}
|
||||
|
||||
if profit.OrderID > 0 {
|
||||
s.orderProfits[profit.OrderID] = append(s.orderProfits[profit.OrderID], profit)
|
||||
}
|
||||
|
||||
s.add(profit.Profit)
|
||||
|
|
Loading…
Reference in New Issue
Block a user