add gin and add trades through the trade service

This commit is contained in:
c9s 2020-08-11 09:28:13 +08:00
parent e2339febc2
commit 891bf50101

View File

@ -3,6 +3,7 @@ package bbgo
import (
"context"
"fmt"
"github.com/c9s/bbgo/pkg/service"
"github.com/c9s/bbgo/pkg/util"
"time"
@ -162,6 +163,8 @@ type Trader struct {
reportTimer *time.Timer
ProfitAndLossCalculator *ProfitAndLossCalculator
TradeService *service.TradeService
}
func (trader *Trader) RunStrategy(ctx context.Context, strategy Strategy) (chan struct{}, error) {
@ -201,6 +204,10 @@ func (trader *Trader) RunStrategy(ctx context.Context, strategy Strategy) (chan
return
}
if err := trader.TradeService.Insert(*trade) ; err != nil {
log.WithError(err).Error("trade insert error")
}
trader.ReportTrade(trade)
trader.ProfitAndLossCalculator.AddTrade(*trade)
_ , err := trader.Context.StockManager.AddTrades([]types.Trade{*trade})