mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 07:26:48 +00:00
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:
@@ -57,13 +57,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
|
||||
}
|
||||
|
||||
@@ -3349,23 +3349,6 @@ func TestUpdateTickers(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestFetchTicker(t *testing.T) {
|
||||
t.Parallel()
|
||||
result, err := ok.FetchTicker(contextGenerate(), currency.NewPair(currency.BTC, currency.NewCode("USDT-SWAP")), asset.PerpetualSwap)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, result)
|
||||
result, err = ok.FetchTicker(contextGenerate(), currency.NewPair(currency.BTC, currency.USDT), asset.Spot)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, result)
|
||||
}
|
||||
|
||||
func TestFetchOrderbook(t *testing.T) {
|
||||
t.Parallel()
|
||||
result, err := ok.FetchOrderbook(contextGenerate(), currency.NewPair(currency.BTC, currency.USDT), asset.Spot)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, result)
|
||||
}
|
||||
|
||||
func TestUpdateOrderbook(t *testing.T) {
|
||||
t.Parallel()
|
||||
result, err := ok.UpdateOrderbook(contextGenerate(), currency.NewPair(currency.BTC, currency.NewCode("USDT-SWAP")), asset.Spot)
|
||||
@@ -3385,14 +3368,6 @@ func TestUpdateAccountInfo(t *testing.T) {
|
||||
assert.NotNil(t, result)
|
||||
}
|
||||
|
||||
func TestFetchAccountInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, ok)
|
||||
result, err := ok.FetchAccountInfo(contextGenerate(), asset.Spot)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, result)
|
||||
}
|
||||
|
||||
func TestGetAccountFundingHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, ok)
|
||||
|
||||
@@ -519,28 +519,6 @@ func (ok *Okx) UpdateTickers(ctx context.Context, assetType asset.Item) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// FetchTicker returns the ticker for a currency pair
|
||||
func (ok *Okx) FetchTicker(ctx context.Context, p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
|
||||
formattedPair, err := ok.FormatExchangeCurrency(p, assetType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tickerNew, err := ticker.GetTicker(ok.Name, formattedPair, assetType)
|
||||
if err != nil {
|
||||
return ok.UpdateTicker(ctx, p, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
|
||||
// FetchOrderbook returns orderbook base on the currency pair
|
||||
func (ok *Okx) FetchOrderbook(ctx context.Context, pair currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
ob, err := orderbook.Get(ok.Name, pair, assetType)
|
||||
if err != nil {
|
||||
return ok.UpdateOrderbook(ctx, pair, assetType)
|
||||
}
|
||||
return ob, nil
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (ok *Okx) UpdateOrderbook(ctx context.Context, pair currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
if pair.IsEmpty() {
|
||||
@@ -687,19 +665,6 @@ func (ok *Okx) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (acc
|
||||
return info, nil
|
||||
}
|
||||
|
||||
// FetchAccountInfo retrieves balances for all enabled currencies
|
||||
func (ok *Okx) FetchAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
|
||||
creds, err := ok.GetCredentials(ctx)
|
||||
if err != nil {
|
||||
return account.Holdings{}, err
|
||||
}
|
||||
acc, err := account.GetHoldings(ok.Name, creds, assetType)
|
||||
if err != nil {
|
||||
return ok.UpdateAccountInfo(ctx, assetType)
|
||||
}
|
||||
return acc, nil
|
||||
}
|
||||
|
||||
// GetAccountFundingHistory returns funding history, deposits and withdrawals
|
||||
func (ok *Okx) GetAccountFundingHistory(ctx context.Context) ([]exchange.FundingHistory, error) {
|
||||
depositHistories, err := ok.GetCurrencyDepositHistory(ctx, currency.EMPTYCODE, "", "", "", "", time.Time{}, time.Time{}, -1, 0)
|
||||
|
||||
Reference in New Issue
Block a user