Merge pull request #256 from zenixls2/fix_nil_indicator_exception

This commit is contained in:
Yo-An Lin 2021-05-26 11:38:33 +08:00 committed by GitHub
commit f5cd84bc65
2 changed files with 23 additions and 10 deletions

View File

@ -16,7 +16,7 @@ import (
"github.com/c9s/bbgo/pkg/util"
)
var fiatCurrencies = []string{"USDC", "USDT", "USD", "TWD", "EUR", "GBP"}
var fiatCurrencies = []string{"USDC", "USDT", "USD", "TWD", "EUR", "GBP", "BUSD"}
type StandardIndicatorSet struct {
Symbol string
@ -25,6 +25,7 @@ type StandardIndicatorSet struct {
sma map[types.IntervalWindow]*indicator.SMA
ewma map[types.IntervalWindow]*indicator.EWMA
boll map[types.IntervalWindow]*indicator.BOLL
stoch map[types.IntervalWindow]*indicator.STOCH
store *MarketDataStore
}
@ -35,6 +36,7 @@ func NewStandardIndicatorSet(symbol string, store *MarketDataStore) *StandardInd
sma: make(map[types.IntervalWindow]*indicator.SMA),
ewma: make(map[types.IntervalWindow]*indicator.EWMA),
boll: make(map[types.IntervalWindow]*indicator.BOLL),
stoch: make(map[types.IntervalWindow]*indicator.STOCH),
store: store,
}
@ -65,7 +67,7 @@ func NewStandardIndicatorSet(symbol string, store *MarketDataStore) *StandardInd
func (set *StandardIndicatorSet) BOLL(iw types.IntervalWindow, bandWidth float64) *indicator.BOLL {
inc, ok := set.boll[iw]
if !ok {
inc := &indicator.BOLL{IntervalWindow: iw, K: bandWidth}
inc = &indicator.BOLL{IntervalWindow: iw, K: bandWidth}
inc.Bind(set.store)
set.boll[iw] = inc
}
@ -77,7 +79,7 @@ func (set *StandardIndicatorSet) BOLL(iw types.IntervalWindow, bandWidth float64
func (set *StandardIndicatorSet) SMA(iw types.IntervalWindow) *indicator.SMA {
inc, ok := set.sma[iw]
if !ok {
inc := &indicator.SMA{IntervalWindow: iw}
inc = &indicator.SMA{IntervalWindow: iw}
inc.Bind(set.store)
set.sma[iw] = inc
}
@ -89,7 +91,7 @@ func (set *StandardIndicatorSet) SMA(iw types.IntervalWindow) *indicator.SMA {
func (set *StandardIndicatorSet) EWMA(iw types.IntervalWindow) *indicator.EWMA {
inc, ok := set.ewma[iw]
if !ok {
inc := &indicator.EWMA{IntervalWindow: iw}
inc = &indicator.EWMA{IntervalWindow: iw}
inc.Bind(set.store)
set.ewma[iw] = inc
}
@ -97,6 +99,17 @@ func (set *StandardIndicatorSet) EWMA(iw types.IntervalWindow) *indicator.EWMA {
return inc
}
func (set *StandardIndicatorSet) STOCH(iw types.IntervalWindow) *indicator.STOCH {
inc, ok := set.stoch[iw]
if !ok {
inc = &indicator.STOCH{IntervalWindow: iw}
inc.Bind(set.store)
set.stoch[iw] = inc
}
return inc
}
// ExchangeSession presents the exchange connection Session
// It also maintains and collects the data returned from the stream.
type ExchangeSession struct {

View File

@ -164,7 +164,7 @@ func (f *DepthFrame) PushEvent(e DepthEvent) {
go f.once.Do(func() {
if err := f.loadDepthSnapshot(); err != nil {
log.WithError(err).Error("%s depth snapshot load failed, resetting..", f.Symbol)
log.WithError(err).Errorf("%s depth snapshot load failed, resetting..", f.Symbol)
f.emitReset()
}
})