mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 08:15:15 +00:00
all: add trade converter to trade pnl fixer
This commit is contained in:
parent
473a6bc108
commit
1b0d4599e2
|
@ -134,7 +134,7 @@ func (c *TradeCollector) BindStreamForBackground(stream types.Stream) {
|
|||
|
||||
func (c *TradeCollector) BindStream(stream types.Stream) {
|
||||
stream.OnTradeUpdate(func(trade types.Trade) {
|
||||
c.processTrade(trade)
|
||||
c.ProcessTrade(trade)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/bbgo"
|
||||
"github.com/c9s/bbgo/pkg/core"
|
||||
"github.com/c9s/bbgo/pkg/exchange/batch"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
@ -22,6 +23,8 @@ type ProfitFixerConfig struct {
|
|||
// ProfitFixer implements a trade-history-based profit fixer
|
||||
type ProfitFixer struct {
|
||||
sessions map[string]types.ExchangeTradeHistoryService
|
||||
|
||||
core.ConverterManager
|
||||
}
|
||||
|
||||
func NewProfitFixer() *ProfitFixer {
|
||||
|
@ -106,6 +109,8 @@ func (f *ProfitFixer) Fix(
|
|||
|
||||
func (f *ProfitFixer) FixFromTrades(allTrades []types.Trade, stats *types.ProfitStats, position *types.Position) error {
|
||||
for _, trade := range allTrades {
|
||||
trade = f.ConverterManager.ConvertTrade(trade)
|
||||
|
||||
profit, netProfit, madeProfit := position.AddTrade(trade)
|
||||
if madeProfit {
|
||||
p := position.NewProfit(trade, profit, netProfit)
|
||||
|
|
|
@ -160,6 +160,7 @@ type Strategy struct {
|
|||
|
||||
Environment *bbgo.Environment
|
||||
|
||||
// Symbol is the maker exchange symbol
|
||||
Symbol string `json:"symbol"`
|
||||
|
||||
// HedgeSymbol is the symbol for the hedge exchange
|
||||
|
@ -262,6 +263,7 @@ func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession) {
|
|||
})
|
||||
|
||||
hedgeSession.Subscribe(types.KLineChannel, s.HedgeSymbol, types.SubscribeOptions{Interval: "1m"})
|
||||
|
||||
makerSession.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: "1m"})
|
||||
}
|
||||
|
||||
|
@ -355,6 +357,8 @@ func (s *Strategy) CrossRun(
|
|||
s.CrossExchangeMarketMakingStrategy.ProfitStats = types.NewProfitStats(makerMarket)
|
||||
|
||||
fixer := common.NewProfitFixer()
|
||||
fixer.ConverterManager = s.ConverterManager
|
||||
|
||||
if ss, ok := makerSession.Exchange.(types.ExchangeTradeHistoryService); ok {
|
||||
log.Infof("adding makerSession %s to profitFixer", makerSession.Name)
|
||||
fixer.AddExchange(makerSession.Name, ss)
|
||||
|
|
Loading…
Reference in New Issue
Block a user