mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
all: use tradeStats constructor
This commit is contained in:
parent
bfd64813f8
commit
193703a9a0
|
@ -53,7 +53,8 @@ func (e *GeneralOrderExecutor) BindTradeStats(tradeStats *types.TradeStats) {
|
||||||
if profit == nil {
|
if profit == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tradeStats.Add(profit.Profit)
|
|
||||||
|
tradeStats.Add(profit)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -235,7 +235,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.TradeStats == nil {
|
if s.TradeStats == nil {
|
||||||
s.TradeStats = &types.TradeStats{}
|
s.TradeStats = types.NewTradeStats(s.Symbol)
|
||||||
}
|
}
|
||||||
|
|
||||||
// StrategyController
|
// StrategyController
|
||||||
|
|
|
@ -413,7 +413,7 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.TradeStats == nil {
|
if s.TradeStats == nil {
|
||||||
s.TradeStats = &types.TradeStats{}
|
s.TradeStats = types.NewTradeStats(s.Symbol)
|
||||||
}
|
}
|
||||||
|
|
||||||
// initial required information
|
// initial required information
|
||||||
|
|
|
@ -334,7 +334,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
|
|
||||||
// trade stats
|
// trade stats
|
||||||
if s.TradeStats == nil {
|
if s.TradeStats == nil {
|
||||||
s.TradeStats = &types.TradeStats{}
|
s.TradeStats = types.NewTradeStats(s.Symbol)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.orderExecutor = bbgo.NewGeneralOrderExecutor(session, s.Symbol, ID, instanceID, s.Position)
|
s.orderExecutor = bbgo.NewGeneralOrderExecutor(session, s.Symbol, ID, instanceID, s.Position)
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
// TODO: Add more stats from the reference:
|
// TODO: Add more stats from the reference:
|
||||||
// See https://www.metatrader5.com/en/terminal/help/algotrading/testing_report
|
// See https://www.metatrader5.com/en/terminal/help/algotrading/testing_report
|
||||||
type TradeStats struct {
|
type TradeStats struct {
|
||||||
|
Symbol string `json:"symbol"`
|
||||||
WinningRatio fixedpoint.Value `json:"winningRatio" yaml:"winningRatio"`
|
WinningRatio fixedpoint.Value `json:"winningRatio" yaml:"winningRatio"`
|
||||||
NumOfLossTrade int `json:"numOfLossTrade" yaml:"numOfLossTrade"`
|
NumOfLossTrade int `json:"numOfLossTrade" yaml:"numOfLossTrade"`
|
||||||
NumOfProfitTrade int `json:"numOfProfitTrade" yaml:"numOfProfitTrade"`
|
NumOfProfitTrade int `json:"numOfProfitTrade" yaml:"numOfProfitTrade"`
|
||||||
|
@ -22,7 +23,19 @@ type TradeStats struct {
|
||||||
TotalNetProfit fixedpoint.Value `json:"totalNetProfit" yaml:"totalNetProfit"`
|
TotalNetProfit fixedpoint.Value `json:"totalNetProfit" yaml:"totalNetProfit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TradeStats) Add(pnl fixedpoint.Value) {
|
func NewTradeStats(symbol string) *TradeStats {
|
||||||
|
return &TradeStats{Symbol: symbol}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TradeStats) Add(profit *Profit) {
|
||||||
|
if profit.Symbol != s.Symbol {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
s.add(profit.Profit)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TradeStats) add(pnl fixedpoint.Value) {
|
||||||
if pnl.Sign() > 0 {
|
if pnl.Sign() > 0 {
|
||||||
s.NumOfProfitTrade++
|
s.NumOfProfitTrade++
|
||||||
s.Profits = append(s.Profits, pnl)
|
s.Profits = append(s.Profits, pnl)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user