mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 07:26:48 +00:00
GateIO: Update websocket orderbook manager (#1989)
* gateio: websocket ob manager fix (cherry-pick me)
* fix(gateio): update websocket orderbook manager to support delay and deadline parameters
feat(subscriptions): mv ChannelKey type for subscription management from gateio to subscriptions
test(gateio): enhance tests for orderbook update manager and subscription keys
* ai: nits
* linter: fix
* Fix asset typo and add in case test
* cranktakular: nits
* cranktakular: nits after merge master
* bump time delay for cache
* fix bug where on error it never initiates another orderbook fetch
* lint: fix
* Update exchanges/gateio/ws_ob_update_manager.go
Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
* glorious: nits
* linter: fix
* Update exchanges/gateio/gateio_wrapper_test.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* Update exchanges/gateio/gateio_wrapper.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* Update exchanges/gateio/gateio_wrapper_test.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* Update exchanges/gateio/ws_ob_update_manager.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* Update exchanges/gateio/ws_ob_update_manager.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* Update exchanges/gateio/ws_ob_update_manager.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* Update exchanges/gateio/ws_ob_update_manager_test.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* gk: nits
* Update exchanges/gateio/gateio_wrapper.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* Update exchanges/gateio/ws_ob_update_manager.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* gk: nits
* bossking: nits
* Update exchanges/gateio/ws_ob_update_manager_test.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* gk: nits
* apply patch
* rm error state as this was on the same thread as cacheStateQueuing and had the potential to drop messages, add tests.
* linter: fix
* mock live request
* misc: fix
* Update exchanges/gateio/ws_ob_update_manager.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* Update exchanges/gateio/ws_ob_update_manager.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* Update exchanges/gateio/ws_ob_update_manager.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* Update exchanges/gateio/ws_ob_update_manager.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* Update exchanges/gateio/ws_ob_update_manager.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* gk: nits
* field name from mtx -> m
* lint: fix
* race: check fix
* thrasher-: patch adams
---------
Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
This commit is contained in:
@@ -180,7 +180,7 @@ func (e *Exchange) SetDefaults() {
|
||||
e.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
|
||||
e.WebsocketResponseCheckTimeout = exchange.DefaultWebsocketResponseCheckTimeout
|
||||
e.WebsocketOrderbookBufferLimit = exchange.DefaultWebsocketOrderbookBufferLimit
|
||||
e.wsOBUpdateMgr = newWsOBUpdateManager(defaultWSSnapshotSyncDelay)
|
||||
e.wsOBUpdateMgr = newWsOBUpdateManager(defaultWsOrderbookUpdateTimeDelay, defaultWSOrderbookUpdateDeadline)
|
||||
}
|
||||
|
||||
// Setup sets user configuration
|
||||
@@ -619,21 +619,31 @@ func (e *Exchange) UpdateOrderbook(ctx context.Context, p currency.Pair, a asset
|
||||
|
||||
// UpdateOrderbookWithLimit updates and returns the orderbook for a currency pair with a set orderbook size limit
|
||||
func (e *Exchange) UpdateOrderbookWithLimit(ctx context.Context, p currency.Pair, a asset.Item, limit uint64) (*orderbook.Book, error) {
|
||||
book, err := e.fetchOrderbook(ctx, p, a, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := book.Process(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return orderbook.Get(e.Name, book.Pair, a)
|
||||
}
|
||||
|
||||
func (e *Exchange) fetchOrderbook(ctx context.Context, p currency.Pair, a asset.Item, limit uint64) (*orderbook.Book, error) {
|
||||
p, err := e.FormatExchangeCurrency(p, a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var o *Orderbook
|
||||
switch a {
|
||||
case asset.Spot, asset.Margin, asset.CrossMargin:
|
||||
var available bool
|
||||
available, err = e.checkInstrumentAvailabilityInSpot(p)
|
||||
if err != nil {
|
||||
case asset.Margin, asset.CrossMargin:
|
||||
if available, err := e.checkInstrumentAvailabilityInSpot(p); err != nil {
|
||||
return nil, err
|
||||
} else if !available {
|
||||
return nil, fmt.Errorf("%w: %w for %q %q", errFetchingOrderbook, errNoSpotInstrument, a, p)
|
||||
}
|
||||
if a != asset.Spot && !available {
|
||||
return nil, fmt.Errorf("%v instrument %v does not have orderbook data", a, p)
|
||||
}
|
||||
fallthrough
|
||||
case asset.Spot:
|
||||
o, err = e.GetOrderbook(ctx, p.String(), "", limit, true)
|
||||
case asset.CoinMarginedFutures, asset.USDTMarginedFutures:
|
||||
var settle currency.Code
|
||||
@@ -653,7 +663,7 @@ func (e *Exchange) UpdateOrderbookWithLimit(ctx context.Context, p currency.Pair
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ob := &orderbook.Book{
|
||||
return &orderbook.Book{
|
||||
Exchange: e.Name,
|
||||
Asset: a,
|
||||
ValidateOrderbook: e.ValidateOrderbook,
|
||||
@@ -663,13 +673,7 @@ func (e *Exchange) UpdateOrderbookWithLimit(ctx context.Context, p currency.Pair
|
||||
LastPushed: o.Current.Time(),
|
||||
Bids: o.Bids.Levels(),
|
||||
Asks: o.Asks.Levels(),
|
||||
}
|
||||
|
||||
if err := ob.Process(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return orderbook.Get(e.Name, p, a)
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateAccountBalances retrieves currency balances
|
||||
|
||||
Reference in New Issue
Block a user