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

@@ -39,13 +39,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

@@ -39,13 +39,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

@@ -39,13 +39,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

@@ -38,13 +38,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

@@ -38,13 +38,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

@@ -38,13 +38,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

@@ -39,13 +39,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

@@ -39,13 +39,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

@@ -39,13 +39,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

@@ -39,13 +39,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

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

View File

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

View File

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

View File

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

View File

@@ -17,7 +17,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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -247,24 +247,6 @@ func ({{.Variable}} *{{.CapitalName}}) UpdateTickers(ctx context.Context, assetT
return nil
}
// FetchTicker returns the ticker for a currency pair
func ({{.Variable}} *{{.CapitalName}}) FetchTicker(ctx context.Context, p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
tickerNew, err := ticker.GetTicker({{.Variable}}.Name, p, assetType)
if err != nil {
return {{.Variable}}.UpdateTicker(ctx, p, assetType)
}
return tickerNew, nil
}
// FetchOrderbook returns orderbook base on the currency pair
func ({{.Variable}} *{{.CapitalName}}) FetchOrderbook(ctx context.Context, pair currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
ob, err := orderbook.Get({{.Variable}}.Name, pair, assetType)
if err != nil {
return {{.Variable}}.UpdateOrderbook(ctx, pair, assetType)
}
return ob, nil
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func ({{.Variable}} *{{.CapitalName}}) UpdateOrderbook(ctx context.Context, pair currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
book := &orderbook.Base{
@@ -313,21 +295,6 @@ func ({{.Variable}} *{{.CapitalName}}) UpdateAccountInfo(ctx context.Context, as
return account.Holdings{}, common.ErrNotYetImplemented
}
// FetchAccountInfo retrieves balances for all enabled currencies
func ({{.Variable}} *{{.CapitalName}}) FetchAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
// Example implementation below:
// creds, err := {{.Variable}}.GetCredentials(ctx)
// if err != nil {
// return account.Holdings{}, err
// }
// acc, err := account.GetHoldings({{.Variable}}.Name, creds, assetType)
// if err != nil {
// return {{.Variable}}.UpdateAccountInfo(ctx, assetType)
// }
// return acc, nil
return account.Holdings{}, common.ErrNotYetImplemented
}
// GetFundingHistory returns funding history, deposits and
// withdrawals
func ({{.Variable}} *{{.CapitalName}}) GetAccountFundingHistory(ctx context.Context) ([]exchange.FundingHistory, error) {

View File

@@ -349,20 +349,6 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
log.Printf("Executing wrappers for %v %v %v", base.GetName(), assetTypes[i], p)
if !authenticatedOnly {
var fetchTickerResponse *ticker.Price
fetchTickerResponse, err = e.FetchTicker(context.TODO(), p, assetTypes[i])
msg = ""
if err != nil {
msg = err.Error()
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{p, assetTypes[i]}),
Function: "FetchTicker",
Error: msg,
Response: jsonifyInterface([]interface{}{fetchTickerResponse}),
})
var updateTickerResponse *ticker.Price
updateTickerResponse, err = e.UpdateTicker(context.TODO(), p, assetTypes[i])
msg = ""
@@ -377,8 +363,8 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
Response: jsonifyInterface([]interface{}{updateTickerResponse}),
})
var fetchOrderbookResponse *orderbook.Base
fetchOrderbookResponse, err = e.FetchOrderbook(context.TODO(), p, assetTypes[i])
var GetCachedTickerResponse *ticker.Price
GetCachedTickerResponse, err = e.GetCachedTicker(p, assetTypes[i])
msg = ""
if err != nil {
msg = err.Error()
@@ -386,9 +372,9 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{p, assetTypes[i]}),
Function: "FetchOrderbook",
Function: "GetCachedTicker",
Error: msg,
Response: jsonifyInterface([]interface{}{fetchOrderbookResponse}),
Response: jsonifyInterface([]interface{}{GetCachedTickerResponse}),
})
var updateOrderbookResponse *orderbook.Base
@@ -405,6 +391,20 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
Response: jsonifyInterface([]interface{}{updateOrderbookResponse}),
})
var GetCachedOrderbookResponse *orderbook.Base
GetCachedOrderbookResponse, err = e.GetCachedOrderbook(p, assetTypes[i])
msg = ""
if err != nil {
msg = err.Error()
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{p, assetTypes[i]}),
Function: "GetCachedOrderbook",
Error: msg,
Response: jsonifyInterface([]interface{}{GetCachedOrderbookResponse}),
})
var fetchTradablePairsResponse []currency.Pair
fetchTradablePairsResponse, err = e.FetchTradablePairs(context.TODO(), assetTypes[i])
msg = ""
@@ -553,17 +553,17 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
})
}
var fetchAccountInfoResponse account.Holdings
fetchAccountInfoResponse, err = e.FetchAccountInfo(context.TODO(), assetTypes[i])
var GetCachedAccountInfoResponse account.Holdings
GetCachedAccountInfoResponse, err = e.GetCachedAccountInfo(context.TODO(), assetTypes[i])
msg = ""
if err != nil {
msg = err.Error()
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
Function: "FetchAccountInfo",
Function: "GetCachedAccountInfo",
Error: msg,
Response: jsonifyInterface([]interface{}{fetchAccountInfoResponse}),
Response: jsonifyInterface([]interface{}{GetCachedAccountInfoResponse}),
})
var getFundingHistoryResponse []exchange.FundingHistory

View File

@@ -25,7 +25,9 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
"github.com/thrasher-corp/gocryptotrader/exchanges/margin"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
)
@@ -641,6 +643,9 @@ var acceptableErrors = []error{
order.ErrCannotValidateAsset, // Is thrown when attempting to get order limits from an asset that is not yet loaded
order.ErrCannotValidateBaseCurrency, // Is thrown when attempting to get order limits from an base currency that is not yet loaded
order.ErrCannotValidateQuoteCurrency, // Is thrown when attempting to get order limits from an quote currency that is not yet loaded
account.ErrExchangeHoldingsNotFound,
ticker.ErrTickerNotFound,
orderbook.ErrOrderbookNotFound,
}
// warningErrors will t.Log(err) when thrown to diagnose things, but not necessarily suggest