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:
Ryan O'Hara-Reid
2025-09-11 13:58:46 +10:00
committed by GitHub
parent de72208024
commit fed4b1bb14
7 changed files with 217 additions and 50 deletions

View File

@@ -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 &&

View File

@@ -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)