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

@@ -57,13 +57,13 @@ for i := range bot.Exchanges {
// Public calls - wrapper functions
// Fetches current ticker information
tick, err := b.FetchTicker()
tick, err := b.UpdateTicker(...)
if err != nil {
// Handle error
}
// Fetches current orderbook information
ob, err := b.FetchOrderbook()
ob, err := b.UpdateOrderbook(...)
if err != nil {
// Handle error
}

View File

@@ -79,8 +79,8 @@ func (b *BTSE) GetRawMarketSummary(ctx context.Context, symbol string, spot bool
return m, b.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, path, &m, spot, queryFunc)
}
// FetchOrderBook gets orderbook data for a given pair
func (b *BTSE) FetchOrderBook(ctx context.Context, symbol string, group, limitBids, limitAsks int, spot bool) (*Orderbook, error) {
// FetchOrderbook gets orderbook data for a given symbol
func (b *BTSE) FetchOrderbook(ctx context.Context, symbol string, group, limitBids, limitAsks int, spot bool) (*Orderbook, error) {
var o Orderbook
urlValues := url.Values{}
urlValues.Add("symbol", symbol)
@@ -97,8 +97,8 @@ func (b *BTSE) FetchOrderBook(ctx context.Context, symbol string, group, limitBi
common.EncodeURLValues(btseOrderbook, urlValues), &o, spot, queryFunc)
}
// FetchOrderBookL2 retrieve level 2 orderbook for requested symbol and depth
func (b *BTSE) FetchOrderBookL2(ctx context.Context, symbol string, depth int) (*Orderbook, error) {
// FetchOrderbookL2 retrieve level 2 orderbook for requested symbol and depth
func (b *BTSE) FetchOrderbookL2(ctx context.Context, symbol string, depth int) (*Orderbook, error) {
var o Orderbook
urlValues := url.Values{}
urlValues.Add("symbol", symbol)

View File

@@ -96,13 +96,13 @@ func TestGetMarketsSummary(t *testing.T) {
func TestFetchOrderBook(t *testing.T) {
t.Parallel()
_, err := b.FetchOrderBook(context.Background(), spotPair.String(), 0, 1, 1, true)
_, err := b.FetchOrderbook(context.Background(), spotPair.String(), 0, 1, 1, true)
assert.NoError(t, err, "FetchOrderBook should not error")
_, err = b.FetchOrderBook(context.Background(), futuresPair.String(), 0, 1, 1, false)
_, err = b.FetchOrderbook(context.Background(), futuresPair.String(), 0, 1, 1, false)
assert.NoError(t, err, "FetchOrderBook should not error")
_, err = b.FetchOrderBook(context.Background(), spotPair.String(), 1, 1, 1, true)
_, err = b.FetchOrderbook(context.Background(), spotPair.String(), 1, 1, 1, true)
assert.NoError(t, err, "FetchOrderBook should not error")
}
@@ -117,7 +117,7 @@ func TestUpdateOrderbook(t *testing.T) {
func TestFetchOrderBookL2(t *testing.T) {
t.Parallel()
_, err := b.FetchOrderBookL2(context.Background(), spotPair.String(), 20)
_, err := b.FetchOrderbookL2(context.Background(), spotPair.String(), 20)
assert.NoError(t, err, "FetchOrderBookL2 should not error")
}

View File

@@ -307,24 +307,6 @@ func (b *BTSE) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item)
return ticker.GetTicker(b.Name, p, a)
}
// FetchTicker returns the ticker for a currency pair
func (b *BTSE) FetchTicker(ctx context.Context, p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
tickerNew, err := ticker.GetTicker(b.Name, p, assetType)
if err != nil {
return b.UpdateTicker(ctx, p, assetType)
}
return tickerNew, nil
}
// FetchOrderbook returns orderbook base on the currency pair
func (b *BTSE) FetchOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
ob, err := orderbook.Get(b.Name, p, assetType)
if err != nil {
return b.UpdateOrderbook(ctx, p, assetType)
}
return ob, nil
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (b *BTSE) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
if p.IsEmpty() {
@@ -343,7 +325,7 @@ func (b *BTSE) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType a
if err != nil {
return book, err
}
a, err := b.FetchOrderBook(ctx, fPair.String(), 0, 0, 0, assetType == asset.Spot)
a, err := b.FetchOrderbook(ctx, fPair.String(), 0, 0, 0, assetType == asset.Spot)
if err != nil {
return book, err
}
@@ -417,20 +399,6 @@ func (b *BTSE) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (acc
return a, nil
}
// FetchAccountInfo retrieves balances for all enabled currencies
func (b *BTSE) FetchAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
creds, err := b.GetCredentials(ctx)
if err != nil {
return account.Holdings{}, err
}
acc, err := account.GetHoldings(b.Name, creds, assetType)
if err != nil {
return b.UpdateAccountInfo(ctx, assetType)
}
return acc, nil
}
// GetAccountFundingHistory returns funding history, deposits and
// withdrawals
func (b *BTSE) GetAccountFundingHistory(_ context.Context) ([]exchange.FundingHistory, error) {