Files
gocryptotrader/gctscript/wrappers/validator/validator.go
Ryan O'Hara-Reid a32d16e1f5 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
2020-01-31 12:09:24 +11:00

212 lines
4.9 KiB
Go

package validator
import (
"time"
"github.com/thrasher-corp/gocryptotrader/currency"
"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"
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
)
// Exchanges validator for test execution/scripts
func (w Wrapper) Exchanges(enabledOnly bool) []string {
if enabledOnly {
return []string{
"hello world",
}
}
return []string{
"nope",
}
}
// IsEnabled returns if requested exchange is enabled or disabled
func (w Wrapper) IsEnabled(exch string) (v bool) {
if exch == exchError.String() {
return
}
return true
}
// Orderbook validator for test execution/scripts
func (w Wrapper) Orderbook(exch string, pair currency.Pair, item asset.Item) (*orderbook.Base, error) {
if exch == exchError.String() {
return nil, errTestFailed
}
return &orderbook.Base{
ExchangeName: exch,
AssetType: item,
Pair: pair,
Bids: []orderbook.Item{
{
Amount: 1,
Price: 1,
},
},
Asks: []orderbook.Item{
{
Amount: 1,
Price: 1,
},
},
}, nil
}
// Ticker validator for test execution/scripts
func (w Wrapper) Ticker(exch string, pair currency.Pair, item asset.Item) (*ticker.Price, error) {
if exch == exchError.String() {
return nil, errTestFailed
}
return &ticker.Price{
Last: 1,
High: 2,
Low: 3,
Bid: 4,
Ask: 5,
Volume: 6,
QuoteVolume: 7,
PriceATH: 8,
Open: 9,
Close: 10,
Pair: pair,
ExchangeName: exch,
AssetType: item,
LastUpdated: time.Now(),
}, nil
}
// Pairs validator for test execution/scripts
func (w Wrapper) Pairs(exch string, _ bool, _ asset.Item) (*currency.Pairs, error) {
if exch == exchError.String() {
return nil, errTestFailed
}
pairs := currency.NewPairsFromStrings([]string{"btc_usd", "btc_aud", "btc_ltc"})
return &pairs, nil
}
// QueryOrder validator for test execution/scripts
func (w Wrapper) QueryOrder(exch, _ string) (*order.Detail, error) {
if exch == exchError.String() {
return nil, errTestFailed
}
return &order.Detail{
Exchange: exch,
AccountID: "hello",
ID: "1",
CurrencyPair: currency.NewPairFromString("BTCAUD"),
OrderSide: "ask",
OrderType: "limit",
OrderDate: time.Now(),
Status: "cancelled",
Price: 1,
Amount: 2,
ExecutedAmount: 1,
RemainingAmount: 0,
Fee: 0,
Trades: []order.TradeHistory{
{
Timestamp: time.Now(),
TID: "",
Price: 1,
Amount: 2,
Exchange: exch,
Type: "limit",
Side: "ask",
Fee: 0,
Description: "",
},
},
}, nil
}
// SubmitOrder validator for test execution/scripts
func (w Wrapper) SubmitOrder(exch string, _ *order.Submit) (*order.SubmitResponse, error) {
if exch == exchError.String() {
return nil, errTestFailed
}
tempOrder := &order.SubmitResponse{
IsOrderPlaced: false,
OrderID: exch,
}
if exch == "true" {
tempOrder.IsOrderPlaced = true
}
return tempOrder, nil
}
// CancelOrder validator for test execution/scripts
func (w Wrapper) CancelOrder(exch, orderid string) (bool, error) {
if exch == exchError.String() {
return false, errTestFailed
}
return orderid != "false", nil
}
// AccountInformation validator for test execution/scripts
func (w Wrapper) AccountInformation(exch string) (account.Holdings, error) {
if exch == exchError.String() {
return account.Holdings{}, errTestFailed
}
return account.Holdings{
Exchange: exch,
Accounts: []account.SubAccount{
{
ID: exch,
Currencies: []account.Balance{
{
CurrencyName: currency.Code{
Item: &currency.Item{
ID: 0,
FullName: "Bitcoin",
Symbol: "BTC",
Role: 1,
AssocChain: "",
AssocExchange: nil,
},
},
TotalValue: 100,
Hold: 0,
},
},
},
},
}, nil
}
// DepositAddress validator for test execution/scripts
func (w Wrapper) DepositAddress(exch string, _ currency.Code) (string, error) {
if exch == exchError.String() {
return exch, errTestFailed
}
return exch, nil
}
// WithdrawalCryptoFunds validator for test execution/scripts
func (w Wrapper) WithdrawalCryptoFunds(exch string, _ *withdraw.CryptoRequest) (out string, err error) {
if exch == exchError.String() {
return exch, errTestFailed
}
return "", nil
}
// WithdrawalFiatFunds validator for test execution/scripts
func (w Wrapper) WithdrawalFiatFunds(exch, _ string, _ *withdraw.FiatRequest) (out string, err error) {
if exch == exchError.String() {
return exch, errTestFailed
}
return "123", nil
}