mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
improve hot reload
This commit is contained in:
parent
ec839d0dc9
commit
3e573ebb10
|
@ -42,7 +42,10 @@ func (store *KLineStore) AddKLine(kline types.KLine) {
|
|||
var window = store.Windows[interval]
|
||||
window.Add(kline)
|
||||
|
||||
if kline.GetMaxChange() > store.MaxChanges[interval].GetMaxChange() {
|
||||
store.MaxChanges[interval] = kline
|
||||
|
||||
if _, ok := store.MaxChanges[interval] ; ok {
|
||||
if kline.GetMaxChange() > store.MaxChanges[interval].GetMaxChange() {
|
||||
store.MaxChanges[interval] = kline
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,17 +41,20 @@ type Trader struct {
|
|||
|
||||
func NewTrader(db *sqlx.DB, exchange *binance.Exchange, symbol string) *Trader {
|
||||
tradeService := &service.TradeService{DB: db}
|
||||
tradeSync := &service.TradeSync{Service: tradeService, Exchange: exchange}
|
||||
return &Trader{
|
||||
Symbol: symbol,
|
||||
Exchange: exchange,
|
||||
TradeService: tradeService,
|
||||
TradeSync: tradeSync,
|
||||
TradeSync: &service.TradeSync{
|
||||
Service: tradeService,
|
||||
Exchange: exchange,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (trader *Trader) Initialize(ctx context.Context, startTime time.Time) error {
|
||||
|
||||
log.Info("syncing trades...")
|
||||
log.Info("syncing trades from exchange...")
|
||||
if err := trader.TradeSync.Sync(ctx, trader.Symbol, startTime); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -154,7 +157,7 @@ func (trader *Trader) RunStrategy(ctx context.Context, strategy Strategy) (chan
|
|||
}
|
||||
|
||||
trader.reportTimer = time.AfterFunc(1*time.Second, func() {
|
||||
trader.ReportPnL()
|
||||
trader.reportPnL()
|
||||
})
|
||||
|
||||
stream.OnTrade(func(trade *types.Trade) {
|
||||
|
@ -166,7 +169,7 @@ func (trader *Trader) RunStrategy(ctx context.Context, strategy Strategy) (chan
|
|||
log.WithError(err).Error("trade insert error")
|
||||
}
|
||||
|
||||
trader.ReportTrade(trade)
|
||||
trader.Notifier.ReportTrade(trade)
|
||||
trader.ProfitAndLossCalculator.AddTrade(*trade)
|
||||
_, err := trader.Context.StockManager.AddTrades([]types.Trade{*trade})
|
||||
if err != nil {
|
||||
|
@ -178,7 +181,7 @@ func (trader *Trader) RunStrategy(ctx context.Context, strategy Strategy) (chan
|
|||
}
|
||||
|
||||
trader.reportTimer = time.AfterFunc(1*time.Minute, func() {
|
||||
trader.ReportPnL()
|
||||
trader.reportPnL()
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -214,11 +217,7 @@ func (trader *Trader) RunStrategy(ctx context.Context, strategy Strategy) (chan
|
|||
return done, nil
|
||||
}
|
||||
|
||||
func (trader *Trader) ReportTrade(trade *types.Trade) {
|
||||
trader.Notifier.ReportTrade(trade)
|
||||
}
|
||||
|
||||
func (trader *Trader) ReportPnL() {
|
||||
func (trader *Trader) reportPnL() {
|
||||
report := trader.ProfitAndLossCalculator.Calculate()
|
||||
report.Print()
|
||||
trader.Notifier.ReportPnL(report)
|
||||
|
|
|
@ -23,6 +23,10 @@ func FormatFloat(val float64, prec int) string {
|
|||
}
|
||||
|
||||
func MustParseFloat(s string) float64 {
|
||||
if len(s) == 0 {
|
||||
return 0.0
|
||||
}
|
||||
|
||||
v, err := strconv.ParseFloat(s, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
Loading…
Reference in New Issue
Block a user