exchanges/wrappers: Refactor fetch orderbook/ticker/account info funcs (#1440)

* acrost: Pull thread, examine

* fix tests

* linter

* fix_linter

* revert rm ctx param to limit breakages when merging usptream

* linter fix

* Add in priority update grouping so that tests pass

* Update cmd/exchange_wrapper_standards/exchange_wrapper_standards_test.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* glorious nits

* fixed spelling

* whoopsie

* aanother whoops

* glorious: NITTERS!

* glorious: further nitters

* srry linter gods

* glorious: nits continued

* sub test p ara lel

* drop main t.Parallel

* fix whoops

* wrappertests: use context with cancel (test)

* linter: fix

* ensure primary execution

* kucoin test fix

* revert standards test changes and bypass non critical errors

* rm single override

* wrap exported error for accounts

* thrasher: nits ch name

* gk: nits

* gk: nits FetchTickerCached -> GetCachedTicker

* gk: nits rn FetchOrderbookCached -> GetCachedOrderbook

* gk: nits rn FetchAccountInfoCached -> GetCachedAccountInfo

* linter: fix

* gk: nits

* thrasher: nitters 1

* thrasher: nitters tmpls

* gk: nitter

---------

Co-authored-by: shazbert <ryan.oharareid@thrasher.io>
Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
Ryan O'Hara-Reid
2025-02-19 10:47:10 +11:00
committed by GitHub
parent 2fc7e8e3e3
commit 08e015a125
122 changed files with 545 additions and 1962 deletions

View File

@@ -35,7 +35,7 @@ exchange interface system set by exchange wrapper orderbook functions in
Examples below:
```go
tick, err := yobitExchange.FetchTicker()
tick, err := yobitExchange.UpdateTicker(...)
if err != nil {
// Handle error
}

View File

@@ -13,16 +13,15 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
)
// Public errors
var (
// ErrNoTickerFound is when a ticker is not found
ErrNoTickerFound = errors.New("no ticker found")
// ErrBidEqualsAsk error for locked markets
ErrBidEqualsAsk = errors.New("bid equals ask this is a crossed or locked market")
// ErrExchangeNameIsEmpty is an error for when an exchange name is empty
ErrTickerNotFound = errors.New("no ticker found")
ErrBidEqualsAsk = errors.New("bid equals ask this is a crossed or locked market")
ErrExchangeNameIsEmpty = errors.New("exchange name is empty")
)
var (
errInvalidTicker = errors.New("invalid ticker")
errTickerNotFound = errors.New("ticker not found")
errBidGreaterThanAsk = errors.New("bid greater than ask this is a crossed or locked market")
errExchangeNotFound = errors.New("exchange not found")
)
@@ -90,8 +89,7 @@ func GetTicker(exchange string, p currency.Pair, a asset.Item) (*Price, error) {
Asset: a,
}]
if !ok {
return nil, fmt.Errorf("%w %s %s %s",
ErrNoTickerFound, exchange, p, a)
return nil, fmt.Errorf("%w %s %s %s", ErrTickerNotFound, exchange, p, a)
}
cpy := tick.Price // Don't let external functions have access to underlying
@@ -138,7 +136,7 @@ func FindLast(p currency.Pair, a asset.Item) (float64, error) {
}
return t.Last, nil
}
return 0, fmt.Errorf("%w %s %s", errTickerNotFound, p, a)
return 0, fmt.Errorf("%w %s %s", ErrTickerNotFound, p, a)
}
// ProcessTicker processes incoming tickers, creating or updating the Tickers list

View File

@@ -12,6 +12,7 @@ import (
"github.com/gofrs/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/thrasher-corp/gocryptotrader/common/key"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/dispatch"
@@ -205,33 +206,20 @@ func TestGetTicker(t *testing.T) {
func TestFindLast(t *testing.T) {
cp := currency.NewPair(currency.BTC, currency.XRP)
_, err := FindLast(cp, asset.Spot)
if !errors.Is(err, errTickerNotFound) {
t.Errorf("received: %v but expected: %v", err, errTickerNotFound)
}
assert.ErrorIs(t, err, ErrTickerNotFound)
err = service.update(&Price{Last: 0, ExchangeName: "testerinos", Pair: cp, AssetType: asset.Spot})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err, "service update must not error")
_, err = FindLast(cp, asset.Spot)
if !errors.Is(err, errInvalidTicker) {
t.Errorf("received: %v but expected: %v", err, errInvalidTicker)
}
assert.ErrorIs(t, err, errInvalidTicker)
err = service.update(&Price{Last: 1337, ExchangeName: "testerinos", Pair: cp, AssetType: asset.Spot})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err, "service update must not error")
last, err := FindLast(cp, asset.Spot)
if !errors.Is(err, nil) {
t.Errorf("received: %v but expected: %v", err, nil)
}
if last != 1337 {
t.Fatal("unexpected value")
}
assert.NoError(t, err)
assert.Equal(t, 1337.0, last)
}
func TestProcessTicker(t *testing.T) { // non-appending function to tickers