Exchanges: Include format pair in wrapper functions and test for formatting issues via tool wrapper issues (#582)

* Adds formatting of pair within binance wrapper, adds return of error from cli.ShowCommmandHelp

* Add formatting function to submit order wrapper functions

* Remove superfluous functionality

* Updated exchange wrapper issues to create a disruptive pair to see which exchanges require attention, updates currency code generation and matching

* reinstated format check, fixed tests

* fixed niterinos

* fix test

* fix spelling mistake

* make html file more aesthetic

* Add missing format pairs

* add formatting to pair for BTC Markets func

* fix spelling
This commit is contained in:
Ryan O'Hara-Reid
2020-10-26 16:54:51 +11:00
committed by GitHub
parent 8a241c2efa
commit 220245c5a8
32 changed files with 429 additions and 199 deletions

View File

@@ -0,0 +1,30 @@
package main
import (
"testing"
"github.com/thrasher-corp/gocryptotrader/currency"
)
func TestDisruptFormatting(t *testing.T) {
_, err := disruptFormatting(currency.Pair{})
if err == nil {
t.Fatal("error cannot be nil")
}
_, err = disruptFormatting(currency.Pair{Base: currency.BTC})
if err == nil {
t.Fatal("error cannot be nil")
}
p := currency.NewPair(currency.BTC, currency.USDT)
badPair, err := disruptFormatting(p)
if err != nil {
t.Fatal(err)
}
if badPair.String() != "BTC-TEST-DELIM-usdt" {
t.Fatal("incorrect disrupted pair")
}
}

View File

@@ -2,6 +2,7 @@ package main
import (
"encoding/json"
"errors"
"flag"
"fmt"
"io/ioutil"
@@ -94,6 +95,7 @@ func main() {
exchs := bot.GetExchanges()
for x := range exchs {
exchs[x].SetDefaults()
base := exchs[x].GetBase()
if !base.Config.Enabled {
log.Printf("Exchange %v not enabled, skipping", base.GetName())
@@ -289,12 +291,12 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
}
for i := range assetTypes {
var msg string
var p currency.Pair
log.Printf("%v %v", base.GetName(), assetTypes[i])
if _, ok := base.Config.CurrencyPairs.Pairs[assetTypes[i]]; !ok {
continue
}
var p currency.Pair
switch {
case currencyPairOverride != "":
var err error
@@ -314,13 +316,19 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
p = base.Config.CurrencyPairs.Pairs[assetTypes[i]].Enabled.GetRandomPair()
}
var err error
p, err = disruptFormatting(p)
if err != nil {
log.Println("failed to disrupt currency pair formatting:", err)
}
responseContainer := ExchangeAssetPairResponses{
AssetType: assetTypes[i],
Pair: p,
}
log.Printf("Setup config for %v %v %v", base.GetName(), assetTypes[i], p)
err := e.Setup(base.Config)
err = e.Setup(base.Config)
if err != nil {
log.Printf("%v Encountered error reloading config: '%v'", base.GetName(), err)
}
@@ -883,3 +891,22 @@ func outputToConsole(exchangeResponses []ExchangeResponses) {
log.Println()
}
}
// disruptFormatting adds in an unused delimiter and strange casing features to
// ensure format currency pair is used throughout the code base.
func disruptFormatting(p currency.Pair) (currency.Pair, error) {
base := p.Base.String()
if base == "" {
return currency.Pair{}, errors.New("cannot disrupt formatting as base is not populated")
}
quote := p.Quote.String()
if quote == "" {
return currency.Pair{}, errors.New("cannot disrupt formatting as quote is not populated")
}
return currency.Pair{
Base: p.Base.Upper(),
Quote: p.Quote.Lower(),
Delimiter: "-TEST-DELIM-",
}, nil
}

View File

@@ -9,7 +9,7 @@
"withdrawWalletAddress": "",
"bankAccount": {
"bankAccountName": "bankAccountName",
"bankAccountNumber": 1337,
"bankAccountNumber": "1337",
"bankAddress": "bankAddress",
"bankCity": "bankCity",
"bankCountry": "bankCountry",
@@ -33,7 +33,6 @@
"intermediaryBankCode": 1337
},
"exchanges": {
"alphapoint": {},
"binance": {
"key": "Key",
"secret": "Secret",
@@ -101,6 +100,11 @@
"secret": "Secret",
"otpSecret": "-"
},
"ftx": {
"key": "Key",
"secret": "Secret",
"otpSecret": "-"
},
"gateio": {
"key": "Key",
"secret": "Secret",