Expose auth validator functionality for wrapper (#416)

* expose auth validator functionality for wrapper

* Add REST validation after keys set, package account types for future syncing

* Add transient error checking for initial creddemtial validation

* fix command types

* Addressed nits from glorious person

* Amalgamate body within error when not between 2xx status, added btcmarket specific auth error check

* nit fix for glorious person

* Format fix

* removed unused code

* check transient first then validate if its an exchange specific authentication error, all others will be disregarded

* Addressed glorious nits

* Addressed glorious nits

* Moved account processing to updateaccountinfo func and added in fetch account info

* Add GRPC Account streaming (NOTE: could not complete until sync item added)

* RM exchange check

* Address xtda nits

* RM comment code

* Fix linter issues

* used most recent protoc version

* lbank linter issues fixed

* Addressed nits and changed len check to range in for loops

* Fixed timeout issue

* thrasher nits addressed

* add string holdings
This commit is contained in:
Ryan O'Hara-Reid
2020-01-31 12:09:24 +11:00
committed by GitHub
parent db23af2ed6
commit a32d16e1f5
75 changed files with 2010 additions and 857 deletions

View File

@@ -12,6 +12,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
@@ -279,19 +280,19 @@ func (e *EXMO) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderboo
return orderbook.Get(e.Name, p, assetType)
}
// GetAccountInfo retrieves balances for all enabled currencies for the
// UpdateAccountInfo retrieves balances for all enabled currencies for the
// Exmo exchange
func (e *EXMO) GetAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
func (e *EXMO) UpdateAccountInfo() (account.Holdings, error) {
var response account.Holdings
response.Exchange = e.Name
result, err := e.GetUserInfo()
if err != nil {
return response, err
}
var currencies []exchange.AccountCurrencyInfo
var currencies []account.Balance
for x, y := range result.Balances {
var exchangeCurrency exchange.AccountCurrencyInfo
var exchangeCurrency account.Balance
exchangeCurrency.CurrencyName = currency.NewCode(x)
for z, w := range result.Reserved {
if z == x {
@@ -304,13 +305,28 @@ func (e *EXMO) GetAccountInfo() (exchange.AccountInfo, error) {
currencies = append(currencies, exchangeCurrency)
}
response.Accounts = append(response.Accounts, exchange.Account{
response.Accounts = append(response.Accounts, account.SubAccount{
Currencies: currencies,
})
err = account.Process(&response)
if err != nil {
return account.Holdings{}, err
}
return response, nil
}
// FetchAccountInfo retrieves balances for all enabled currencies
func (e *EXMO) FetchAccountInfo() (account.Holdings, error) {
acc, err := account.GetHoldings(e.Name)
if err != nil {
return e.UpdateAccountInfo()
}
return acc, nil
}
// GetFundingHistory returns funding history, deposits and
// withdrawals
func (e *EXMO) GetFundingHistory() ([]exchange.FundHistory, error) {
@@ -542,3 +558,10 @@ func (e *EXMO) GetSubscriptions() ([]wshandler.WebsocketChannelSubscription, err
func (e *EXMO) AuthenticateWebsocket() error {
return common.ErrFunctionNotSupported
}
// ValidateCredentials validates current credentials used for wrapper
// functionality
func (e *EXMO) ValidateCredentials() error {
_, err := e.UpdateAccountInfo()
return e.CheckTransientError(err)
}