mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-06 07:26:47 +00:00
GateIO: Fix account sequence issue, expand structs, add tests (#2011)
* gateio: fix sequence issue, expand structs, add tests (cherry-pick my nose) * Update exchanges/gateio/gateio_websocket_futures.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update exchanges/gateio/gateio_types.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/gateio/gateio_websocket_test.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * gk: nits * GateIO: Avoid nolint on containedctx * Update exchanges/gateio/gateio_websocket_test.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * fixup * Update exchanges/gateio/gateio_websocket_test.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
@@ -396,7 +396,7 @@ func (b *ProtectedBalance) load(change *Balance) error {
|
||||
}
|
||||
b.m.Lock()
|
||||
defer b.m.Unlock()
|
||||
if !b.updatedAt.IsZero() && !b.updatedAt.Before(change.UpdatedAt) {
|
||||
if !b.updatedAt.IsZero() && b.updatedAt.After(change.UpdatedAt) {
|
||||
return errOutOfSequence
|
||||
}
|
||||
if b.total == change.Total &&
|
||||
|
||||
@@ -290,8 +290,11 @@ func TestBalanceInternalLoad(t *testing.T) {
|
||||
|
||||
assert.Equal(t, 3.0, bi.GetFree())
|
||||
|
||||
err = bi.load(&Balance{UpdatedAt: now.Add(-time.Second), Total: 2, Hold: 3, Free: 4, AvailableWithoutBorrow: 5, Borrowed: 6})
|
||||
assert.ErrorIs(t, err, errOutOfSequence, "should error correctly with old update trying to store")
|
||||
|
||||
err = bi.load(&Balance{UpdatedAt: now, Total: 2, Hold: 3, Free: 4, AvailableWithoutBorrow: 5, Borrowed: 6})
|
||||
assert.ErrorIs(t, err, errOutOfSequence, "should error correctly with same UpdatedAt")
|
||||
assert.NoError(t, err, "should not error when timestamps are the same")
|
||||
|
||||
err = bi.load(&Balance{UpdatedAt: now.Add(time.Second), Total: 2, Hold: 3, Free: 4, AvailableWithoutBorrow: 5, Borrowed: 6})
|
||||
assert.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user