mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
stream/websocket: Consolidate fields by using exchange config pointer (#809)
* stream: add exchange config pointer to setup WebsocketSetup struct to reduce and consolidate setting of variables. * config: reduce stutter * config: reduce minor stutter * glorious: nits addr. * Update exchanges/stream/websocket.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * websocket: implement fix * engine/helpers: fix test * exchanges: fix after merge issues * exchange_template: fix output Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
@@ -15,7 +16,7 @@ import (
|
||||
const packageError = "websocket orderbook buffer error: %w"
|
||||
|
||||
var (
|
||||
errUnsetExchangeName = errors.New("exchange name unset")
|
||||
errExchangeConfigNil = errors.New("exchange config is nil")
|
||||
errUnsetDataHandler = errors.New("datahandler unset")
|
||||
errIssueBufferEnabledButNoLimit = errors.New("buffer enabled but no limit set")
|
||||
errUpdateIsNil = errors.New("update is nil")
|
||||
@@ -25,34 +26,35 @@ var (
|
||||
)
|
||||
|
||||
// Setup sets private variables
|
||||
func (w *Orderbook) Setup(obBufferLimit int,
|
||||
bufferEnabled,
|
||||
sortBuffer,
|
||||
sortBufferByUpdateIDs,
|
||||
updateEntriesByID,
|
||||
verbose bool,
|
||||
publishPeriod time.Duration,
|
||||
exchangeName string,
|
||||
dataHandler chan interface{}) error {
|
||||
if exchangeName == "" {
|
||||
return fmt.Errorf(packageError, errUnsetExchangeName)
|
||||
func (w *Orderbook) Setup(cfg *config.Exchange, sortBuffer, sortBufferByUpdateIDs, updateEntriesByID bool, dataHandler chan interface{}) error {
|
||||
if cfg == nil { // exchange config fields are checked in stream package
|
||||
// prior to calling this, so further checks are not needed.
|
||||
return fmt.Errorf(packageError, errExchangeConfigNil)
|
||||
}
|
||||
if dataHandler == nil {
|
||||
return fmt.Errorf(packageError, errUnsetDataHandler)
|
||||
}
|
||||
if bufferEnabled && obBufferLimit < 1 {
|
||||
if cfg.Orderbook.WebsocketBufferEnabled &&
|
||||
cfg.Orderbook.WebsocketBufferLimit < 1 {
|
||||
return fmt.Errorf(packageError, errIssueBufferEnabledButNoLimit)
|
||||
}
|
||||
w.obBufferLimit = obBufferLimit
|
||||
w.bufferEnabled = bufferEnabled
|
||||
|
||||
w.bufferEnabled = cfg.Orderbook.WebsocketBufferEnabled
|
||||
w.obBufferLimit = cfg.Orderbook.WebsocketBufferLimit
|
||||
w.sortBuffer = sortBuffer
|
||||
w.sortBufferByUpdateIDs = sortBufferByUpdateIDs
|
||||
w.updateEntriesByID = updateEntriesByID
|
||||
w.exchangeName = exchangeName
|
||||
w.exchangeName = cfg.Name
|
||||
w.dataHandler = dataHandler
|
||||
w.ob = make(map[currency.Code]map[currency.Code]map[asset.Item]*orderbookHolder)
|
||||
w.verbose = verbose
|
||||
w.publishPeriod = publishPeriod
|
||||
w.verbose = cfg.Verbose
|
||||
|
||||
// set default publish period if missing
|
||||
orderbookPublishPeriod := config.DefaultOrderbookPublishPeriod
|
||||
if cfg.Orderbook.PublishPeriod != nil {
|
||||
orderbookPublishPeriod = *cfg.Orderbook.PublishPeriod
|
||||
}
|
||||
w.publishPeriod = orderbookPublishPeriod
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user