Skip to content

Commit

Permalink
Exchanges: Include format pair in wrapper functions and test for form…
Browse files Browse the repository at this point in the history
…atting issues via tool wrapper issues (thrasher-corp#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
  • Loading branch information
shazbert authored Oct 26, 2020
1 parent 8a241c2 commit 220245c
Show file tree
Hide file tree
Showing 32 changed files with 428 additions and 198 deletions.
30 changes: 30 additions & 0 deletions cmd/exchange_wrapper_issues/exchange_wrapper_issues_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
}
31 changes: 29 additions & 2 deletions cmd/exchange_wrapper_issues/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"errors"
"flag"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
}
8 changes: 6 additions & 2 deletions cmd/exchange_wrapper_issues/wrapperconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"withdrawWalletAddress": "",
"bankAccount": {
"bankAccountName": "bankAccountName",
"bankAccountNumber": 1337,
"bankAccountNumber": "1337",
"bankAddress": "bankAddress",
"bankCity": "bankCity",
"bankCountry": "bankCountry",
Expand All @@ -33,7 +33,6 @@
"intermediaryBankCode": 1337
},
"exchanges": {
"alphapoint": {},
"binance": {
"key": "Key",
"secret": "Secret",
Expand Down Expand Up @@ -101,6 +100,11 @@
"secret": "Secret",
"otpSecret": "-"
},
"ftx": {
"key": "Key",
"secret": "Secret",
"otpSecret": "-"
},
"gateio": {
"key": "Key",
"secret": "Secret",
Expand Down
Loading

0 comments on commit 220245c

Please sign in to comment.