mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-23 15:10:15 +00:00
modernise: Run new gopls modernise tool against the codebase and fix minor issues (#1826)
* modernise: Run new gopls modernise tool against codebase
* Address shazbert's nits
* apichecker, gctcli: Simplify HTML scraping functions and improve depth limit handling
* refactor: Create minSyncInterval const and update order book limit handling for binance and binanceUS
* refactor: Various slice usage improvements and rename TODO
* tranches: Revert deleteByID changes due to performance decrease
Shazbert was a F1 driver in a past lifetime 🏎️
* tranches: Simply retrieve copy
Thanks to shazbert
* documentation: Sort contributors list by contributions
* tranches: Remove deadcode in deleteByID
This commit is contained in:
@@ -34,7 +34,7 @@ var (
|
||||
)
|
||||
|
||||
// Setup sets private variables
|
||||
func (w *Orderbook) Setup(exchangeConfig *config.Exchange, c *Config, dataHandler chan<- interface{}) error {
|
||||
func (w *Orderbook) Setup(exchangeConfig *config.Exchange, c *Config, dataHandler chan<- any) error {
|
||||
if exchangeConfig == nil { // exchange config fields are checked in stream package
|
||||
// prior to calling this, so further checks are not needed.
|
||||
return fmt.Errorf(packageError, errExchangeConfigNil)
|
||||
|
||||
@@ -54,8 +54,8 @@ func createSnapshot(pair currency.Pair, bookVerifiy ...bool) (holder *Orderbook,
|
||||
|
||||
newBook := make(map[key.PairAsset]*orderbookHolder)
|
||||
|
||||
ch := make(chan interface{})
|
||||
go func(<-chan interface{}) { // reader
|
||||
ch := make(chan any)
|
||||
go func(<-chan any) { // reader
|
||||
for range ch {
|
||||
continue
|
||||
}
|
||||
@@ -529,7 +529,7 @@ func TestRunSnapshotWithNoData(t *testing.T) {
|
||||
|
||||
var obl Orderbook
|
||||
obl.ob = make(map[key.PairAsset]*orderbookHolder)
|
||||
obl.dataHandler = make(chan interface{}, 1)
|
||||
obl.dataHandler = make(chan any, 1)
|
||||
var snapShot1 orderbook.Base
|
||||
snapShot1.Asset = asset.Spot
|
||||
snapShot1.Pair = cp
|
||||
@@ -546,7 +546,7 @@ func TestLoadSnapshot(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
var obl Orderbook
|
||||
obl.dataHandler = make(chan interface{}, 100)
|
||||
obl.dataHandler = make(chan any, 100)
|
||||
obl.ob = make(map[key.PairAsset]*orderbookHolder)
|
||||
var snapShot1 orderbook.Base
|
||||
snapShot1.Exchange = "SnapshotWithOverride"
|
||||
@@ -581,7 +581,7 @@ func TestInsertingSnapShots(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
var holder Orderbook
|
||||
holder.dataHandler = make(chan interface{}, 100)
|
||||
holder.dataHandler = make(chan any, 100)
|
||||
holder.ob = make(map[key.PairAsset]*orderbookHolder)
|
||||
var snapShot1 orderbook.Base
|
||||
snapShot1.Exchange = "WSORDERBOOKTEST1"
|
||||
@@ -762,7 +762,7 @@ func TestSetup(t *testing.T) {
|
||||
require.ErrorIs(t, err, errUnsetDataHandler)
|
||||
|
||||
exchangeConfig.Orderbook.WebsocketBufferEnabled = true
|
||||
err = w.Setup(exchangeConfig, bufferConf, make(chan interface{}))
|
||||
err = w.Setup(exchangeConfig, bufferConf, make(chan any))
|
||||
require.ErrorIs(t, err, errIssueBufferEnabledButNoLimit)
|
||||
|
||||
exchangeConfig.Orderbook.WebsocketBufferLimit = 1337
|
||||
@@ -771,7 +771,7 @@ func TestSetup(t *testing.T) {
|
||||
bufferConf.SortBuffer = true
|
||||
bufferConf.SortBufferByUpdateIDs = true
|
||||
bufferConf.UpdateEntriesByID = true
|
||||
err = w.Setup(exchangeConfig, bufferConf, make(chan interface{}))
|
||||
err = w.Setup(exchangeConfig, bufferConf, make(chan any))
|
||||
require.NoError(t, err)
|
||||
|
||||
if w.obBufferLimit != 1337 ||
|
||||
@@ -963,7 +963,7 @@ func TestFlushOrderbook(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
w := &Orderbook{}
|
||||
err = w.Setup(&config.Exchange{Name: "test"}, &Config{}, make(chan interface{}, 2))
|
||||
err = w.Setup(&config.Exchange{Name: "test"}, &Config{}, make(chan any, 2))
|
||||
require.NoError(t, err)
|
||||
|
||||
var snapShot1 orderbook.Base
|
||||
|
||||
@@ -35,7 +35,7 @@ type Orderbook struct {
|
||||
sortBufferByUpdateIDs bool // When timestamps aren't provided, an id can help sort
|
||||
updateEntriesByID bool // Use the update IDs to match ob entries
|
||||
exchangeName string
|
||||
dataHandler chan<- interface{}
|
||||
dataHandler chan<- any
|
||||
verbose bool
|
||||
|
||||
// updateIDProgression requires that the new update ID be greater than the
|
||||
|
||||
@@ -84,8 +84,8 @@ func SetupGlobalReporter(r Reporter) {
|
||||
// NewWebsocket initialises the websocket struct
|
||||
func NewWebsocket() *Websocket {
|
||||
return &Websocket{
|
||||
DataHandler: make(chan interface{}, jobBuffer),
|
||||
ToRoutine: make(chan interface{}, jobBuffer),
|
||||
DataHandler: make(chan any, jobBuffer),
|
||||
ToRoutine: make(chan any, jobBuffer),
|
||||
ShutdownC: make(chan struct{}),
|
||||
TrafficAlert: make(chan struct{}, 1),
|
||||
// ReadMessageErrors is buffered for an edge case when `Connect` fails
|
||||
|
||||
@@ -43,7 +43,7 @@ type testRequest struct {
|
||||
Event string `json:"event"`
|
||||
RequestID int64 `json:"reqid,omitempty"`
|
||||
Pairs []string `json:"pair"`
|
||||
Subscription testRequestData `json:"subscription,omitempty"`
|
||||
Subscription testRequestData `json:"subscription"`
|
||||
}
|
||||
|
||||
// testRequestData contains details on WS channel
|
||||
@@ -96,7 +96,7 @@ func TestSetup(t *testing.T) {
|
||||
err := w.Setup(nil)
|
||||
assert.ErrorIs(t, err, errWebsocketIsNil)
|
||||
|
||||
w = &Websocket{DataHandler: make(chan interface{})}
|
||||
w = &Websocket{DataHandler: make(chan any)}
|
||||
err = w.Setup(nil)
|
||||
assert.ErrorIs(t, err, errWebsocketSetupIsNil)
|
||||
|
||||
@@ -1455,7 +1455,7 @@ func TestMonitorFrame(t *testing.T) {
|
||||
|
||||
func TestMonitorData(t *testing.T) {
|
||||
t.Parallel()
|
||||
ws := Websocket{ShutdownC: make(chan struct{}), DataHandler: make(chan interface{}, 10)}
|
||||
ws := Websocket{ShutdownC: make(chan struct{}), DataHandler: make(chan any, 10)}
|
||||
// Handle shutdown signal
|
||||
close(ws.ShutdownC)
|
||||
require.True(t, ws.observeData(nil))
|
||||
@@ -1466,7 +1466,7 @@ func TestMonitorData(t *testing.T) {
|
||||
require.False(t, ws.observeData(&dropped))
|
||||
require.Equal(t, 1, dropped)
|
||||
// Handle reinstate of ToRoutine functionality which will reset dropped counter
|
||||
ws.ToRoutine = make(chan interface{}, 10)
|
||||
ws.ToRoutine = make(chan any, 10)
|
||||
go func() { ws.DataHandler <- nil }()
|
||||
require.False(t, ws.observeData(&dropped))
|
||||
require.Empty(t, dropped)
|
||||
@@ -1500,7 +1500,7 @@ func TestMonitorConnection(t *testing.T) {
|
||||
require.False(t, ws.observeConnection(timer)) // Connect is intentionally erroring
|
||||
// Handle error from a connection which will then trigger a reconnect
|
||||
ws.setState(connectedState)
|
||||
ws.DataHandler = make(chan interface{}, 1)
|
||||
ws.DataHandler = make(chan any, 1)
|
||||
ws.ReadMessageErrors <- errConnectionFault
|
||||
timer = time.NewTimer(time.Second)
|
||||
require.False(t, ws.observeConnection(timer))
|
||||
|
||||
@@ -69,8 +69,8 @@ type Websocket struct {
|
||||
|
||||
useMultiConnectionManagement bool
|
||||
|
||||
DataHandler chan interface{}
|
||||
ToRoutine chan interface{}
|
||||
DataHandler chan any
|
||||
ToRoutine chan any
|
||||
|
||||
Match *Match
|
||||
|
||||
|
||||
Reference in New Issue
Block a user