mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
gateio: Fix websocket orderbook incremental updates (#1863)
* gateio: Add websocket orderbook update manager * RM println * glorious: nit * Adds delivery futures update processing as well * Change to const value for delivery * Drop check out of order, can reinstate if required. * Adds in validation methods to ensure config changes are correct when expanding templates and return errors with correct info if not. * fix some things and add in todo when this gets updated * fix spelling * linter: fix * gk: initial nits * gk: nits shift to template only verification with funcmap, rm interface for single sub checking. * rm unused error * linter: fix * update to const frequency * gk: wrap with panic and single invocation in template, change name * gk: nits to check across stored subs with incoming subs * linter: fix * updates names, makes things slightly more efficient and adds tests * linter: fix * gk: sexc patch v2 * glorious: nits * gk: nits * Update exchanges/subscription/template.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * gk: nits * linter: make peace with linter regulations * glorious: Add TODO for future template integration * glorious: commentary nits * fix name * give me a break, have a kit kat * revert whoops * update wording on comment * revert secondary call to expand templates and update tests * misc lint: fix * Add spot orderbook update interval for 20ms, expand tests, piggy back limit/level off loaded subscription. Thanks to @thrasher- * linter/spell: fix * ai nits: drop go routine on mtx RUnlock * Update exchanges/gateio/ws_ob_update_manager.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * gk: revert to 100ms from 20ms waiting for config upgrade patch * test: fix * cranktakular: nits * strings quoted in fmt call * thrasher-: nits * Update exchanges/gateio/gateio_test.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/gateio/gateio_test.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * gk: nits --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
This commit is contained in:
@@ -50,6 +50,7 @@ func createSnapshot(pair currency.Pair, bookVerifiy ...bool) (holder *Orderbook,
|
||||
PriceDuplication: true,
|
||||
LastUpdated: time.Now(),
|
||||
VerifyOrderbook: len(bookVerifiy) > 0 && bookVerifiy[0],
|
||||
LastUpdateID: 69420,
|
||||
}
|
||||
|
||||
newBook := make(map[key.PairAsset]*orderbookHolder)
|
||||
@@ -462,7 +463,7 @@ func TestOrderbookLastUpdateID(t *testing.T) {
|
||||
err = holder.Update(&orderbook.Update{
|
||||
Asks: asks,
|
||||
Pair: cp,
|
||||
UpdateID: int64(i) + 1,
|
||||
UpdateID: int64(i) + 1 + 69420,
|
||||
Asset: asset.Spot,
|
||||
UpdateTime: time.Now(),
|
||||
})
|
||||
@@ -480,7 +481,7 @@ func TestOrderbookLastUpdateID(t *testing.T) {
|
||||
|
||||
ob, err := holder.GetOrderbook(cp, asset.Spot)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(len(itemArray)), ob.LastUpdateID)
|
||||
assert.Equal(t, int64(len(itemArray)+69420), ob.LastUpdateID)
|
||||
}
|
||||
|
||||
// TestRunUpdateWithoutSnapshot logic test
|
||||
@@ -500,7 +501,7 @@ func TestRunUpdateWithoutSnapshot(t *testing.T) {
|
||||
UpdateTime: time.Now(),
|
||||
Asset: asset.Spot,
|
||||
})
|
||||
require.ErrorIs(t, err, errDepthNotFound)
|
||||
require.ErrorIs(t, err, ErrDepthNotFound)
|
||||
}
|
||||
|
||||
// TestRunUpdateWithoutAnyUpdates logic test
|
||||
@@ -723,6 +724,12 @@ func TestGetOrderbook(t *testing.T) {
|
||||
holder, _, _, err := createSnapshot(cp)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = holder.GetOrderbook(currency.EMPTYPAIR, asset.Spot)
|
||||
require.ErrorIs(t, err, currency.ErrCurrencyPairEmpty)
|
||||
|
||||
_, err = holder.GetOrderbook(cp, 0)
|
||||
require.ErrorIs(t, err, asset.ErrInvalidAsset)
|
||||
|
||||
ob, err := holder.GetOrderbook(cp, asset.Spot)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -736,15 +743,35 @@ func TestGetOrderbook(t *testing.T) {
|
||||
bidLen, err := bufferOb.ob.GetBidLength()
|
||||
require.NoError(t, err)
|
||||
|
||||
if askLen != len(ob.Asks) ||
|
||||
bidLen != len(ob.Bids) ||
|
||||
b.Asset != ob.Asset ||
|
||||
b.Exchange != ob.Exchange ||
|
||||
b.LastUpdateID != ob.LastUpdateID ||
|
||||
b.PriceDuplication != ob.PriceDuplication ||
|
||||
b.Pair != ob.Pair {
|
||||
t.Fatal("data on both books should be the same")
|
||||
}
|
||||
assert.Equal(t, askLen, len(ob.Asks), "ask length mismatch")
|
||||
assert.Equal(t, bidLen, len(ob.Bids), "bid length mismatch")
|
||||
assert.Equal(t, b.Asset, ob.Asset, "asset mismatch")
|
||||
assert.Equal(t, b.Exchange, ob.Exchange, "exchange name mismatch")
|
||||
assert.Equal(t, b.LastUpdateID, ob.LastUpdateID, "last update ID mismatch")
|
||||
assert.Equal(t, b.PriceDuplication, ob.PriceDuplication, "price duplication mismatch")
|
||||
assert.Equal(t, b.Pair, ob.Pair, "pair mismatch")
|
||||
}
|
||||
|
||||
func TestLastUpdateID(t *testing.T) {
|
||||
t.Parallel()
|
||||
cp, err := getExclusivePair()
|
||||
require.NoError(t, err)
|
||||
|
||||
holder, _, _, err := createSnapshot(cp)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = holder.LastUpdateID(currency.EMPTYPAIR, asset.Spot)
|
||||
require.ErrorIs(t, err, currency.ErrCurrencyPairEmpty)
|
||||
|
||||
_, err = holder.LastUpdateID(cp, 0)
|
||||
require.ErrorIs(t, err, asset.ErrInvalidAsset)
|
||||
|
||||
_, err = holder.LastUpdateID(cp, asset.FutureCombo)
|
||||
require.ErrorIs(t, err, ErrDepthNotFound)
|
||||
|
||||
ob, err := holder.LastUpdateID(cp, asset.Spot)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(69420), ob)
|
||||
}
|
||||
|
||||
func TestSetup(t *testing.T) {
|
||||
@@ -982,7 +1009,7 @@ func TestFlushOrderbook(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err = w.GetOrderbook(cp, asset.Spot)
|
||||
require.ErrorIs(t, err, errDepthNotFound)
|
||||
require.ErrorIs(t, err, ErrDepthNotFound)
|
||||
|
||||
require.NoError(t, w.LoadSnapshot(&snapShot1))
|
||||
require.NoError(t, w.FlushOrderbook(cp, asset.Spot))
|
||||
|
||||
Reference in New Issue
Block a user