tool/exchange_wrapper_coverage: fix regression and implement reflection (#837)

* cmd/tools/exchange: fix regression and implement reflection so as this can dynamically scale to our interface

* exchanges: add comment and fix whoopsie

* exchanges: fix linter issues

* wrapper_cov_tool: add actual full interface method count to get a better perceived deployment

* exchanges/tool: addr glorious nits

* kraken: remove string in test

* exchange_template_tool: fix tmpl issue
This commit is contained in:
Ryan O'Hara-Reid
2021-11-17 15:41:21 +11:00
committed by GitHub
parent 7c7aebe22f
commit da3402476e
67 changed files with 878 additions and 239 deletions

View File

@@ -2,9 +2,11 @@ package itbit
import (
"context"
"errors"
"log"
"net/url"
"os"
"sync"
"testing"
"time"
@@ -52,6 +54,20 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}
func TestStart(t *testing.T) {
t.Parallel()
err := i.Start(nil)
if !errors.Is(err, common.ErrNilPointer) {
t.Fatalf("received: '%v' but expected: '%v'", err, common.ErrNilPointer)
}
var testWg sync.WaitGroup
err = i.Start(&testWg)
if err != nil {
t.Fatal(err)
}
testWg.Wait()
}
func TestGetTicker(t *testing.T) {
t.Parallel()
_, err := i.GetTicker(context.Background(), "XBTUSD")

View File

@@ -107,6 +107,9 @@ func (i *ItBit) SetDefaults() {
// Setup sets the exchange parameters from exchange config
func (i *ItBit) Setup(exch *config.Exchange) error {
if err := exch.Validate(); err != nil {
return err
}
if !exch.Enabled {
i.SetEnabled(false)
return nil
@@ -115,12 +118,16 @@ func (i *ItBit) Setup(exch *config.Exchange) error {
}
// Start starts the ItBit go routine
func (i *ItBit) Start(wg *sync.WaitGroup) {
func (i *ItBit) Start(wg *sync.WaitGroup) error {
if wg == nil {
return fmt.Errorf("%T %w", wg, common.ErrNilPointer)
}
wg.Add(1)
go func() {
i.Run()
wg.Done()
}()
return nil
}
// Run implements the ItBit wrapper
@@ -505,6 +512,9 @@ func (i *ItBit) WithdrawFiatFundsToInternationalBank(_ context.Context, _ *withd
// GetFeeByType returns an estimate of fee based on type of transaction
func (i *ItBit) GetFeeByType(ctx context.Context, feeBuilder *exchange.FeeBuilder) (float64, error) {
if feeBuilder == nil {
return 0, fmt.Errorf("%T %w", feeBuilder, common.ErrNilPointer)
}
if !i.AllowAuthenticatedRequest() && // Todo check connection status
feeBuilder.FeeType == exchange.CryptocurrencyTradeFee {
feeBuilder.FeeType = exchange.OfflineTradeFee