Skip to content

Commit

Permalink
Add a new OnEvent strategy callback
Browse files Browse the repository at this point in the history
To be triggered by the application when it needs to communicate relevant events
to strategies (eg. configuration change, pause trading, etc).
  • Loading branch information
lrascao committed Sep 7, 2021
1 parent f8acdd3 commit e7d4cba
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions strategy.go
Expand Up @@ -36,5 +36,6 @@ type Strategy interface {
OnModify(k *Keep, e exchange.IBotExchange, x order.Modify) error
OnBalanceChange(k *Keep, e exchange.IBotExchange, x account.Change) error
OnUnrecognized(k *Keep, e exchange.IBotExchange, x interface{}) error
OnEvent(k *Keep, x interface{}) error
Deinit(k *Keep, e exchange.IBotExchange) error
}
4 changes: 4 additions & 0 deletions strategy_balances.go
Expand Up @@ -139,6 +139,10 @@ func (b *BalancesStrategy) OnUnrecognized(k *Keep, e exchange.IBotExchange, x in
return nil
}

func (b *BalancesStrategy) OnEvent(k *Keep, x interface{}) error {
return nil
}

func (b *BalancesStrategy) Deinit(k *Keep, e exchange.IBotExchange) error {
return b.ticker.Init(k, e)
}
4 changes: 4 additions & 0 deletions strategy_dedicated.go
Expand Up @@ -88,6 +88,10 @@ func (d *DedicatedStrategy) OnUnrecognized(k *Keep, e exchange.IBotExchange, x i
return nil
}

func (d *DedicatedStrategy) OnEvent(k *Keep, x interface{}) error {
return nil
}

func (d *DedicatedStrategy) Deinit(k *Keep, e exchange.IBotExchange) error {
if e.GetName() == d.Exchange {
return d.Wrapped.Deinit(k, e)
Expand Down
4 changes: 4 additions & 0 deletions strategy_history.go
Expand Up @@ -151,6 +151,10 @@ func (r *HistoryStrategy) OnUnrecognized(k *Keep, e exchange.IBotExchange, x int
return nil
}

func (r *HistoryStrategy) OnEvent(k *Keep, x interface{}) error {
return nil
}

func (r *HistoryStrategy) Deinit(k *Keep, e exchange.IBotExchange) error {
return nil
}
Expand Down
4 changes: 4 additions & 0 deletions strategy_root.go
Expand Up @@ -111,6 +111,10 @@ func (m *RootStrategy) OnUnrecognized(k *Keep, e exchange.IBotExchange, x interf
return m.each(func(s Strategy) error { return s.OnUnrecognized(k, e, x) })
}

func (m *RootStrategy) OnEvent(k *Keep, x interface{}) error {
return m.each(func(s Strategy) error { return s.OnEvent(k, x) })
}

func (m *RootStrategy) Deinit(k *Keep, e exchange.IBotExchange) error {
return m.each(func(s Strategy) error { return s.Deinit(k, e) })
}
4 changes: 4 additions & 0 deletions strategy_ticker.go
Expand Up @@ -76,6 +76,10 @@ func (s *TickerStrategy) OnUnrecognized(k *Keep, e exchange.IBotExchange, x inte
return nil
}

func (s *TickerStrategy) OnEvent(k *Keep, x interface{}) error {
return nil
}

func (s *TickerStrategy) Deinit(k *Keep, e exchange.IBotExchange) error {
pointer, loaded := s.tickers.LoadAndDelete(e.GetName())
if !loaded {
Expand Down
6 changes: 6 additions & 0 deletions strategy_verbose.go
Expand Up @@ -91,6 +91,12 @@ func (v VerboseStrategy) OnUnrecognized(k *Keep, e exchange.IBotExchange, x inte
return nil
}

func (v VerboseStrategy) OnEvent(k *Keep, x interface{}) error {
Msg(log.Info().Str("what", "event").Interface("x", x))

return nil
}

func (v VerboseStrategy) Deinit(k *Keep, e exchange.IBotExchange) error {
Msg(log.Info().Str("e", e.GetName()))

Expand Down

0 comments on commit e7d4cba

Please sign in to comment.