mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
* Slight enhance of Coinbase tests Continual enhance of Coinbase tests The revamp continues Oh jeez the Orderbook part's unfinished don't look Coinbase revamp, Orderbook still unfinished * Coinbase revamp; CreateReport is still WIP * More coinbase improvements; onto sandbox testing * Coinbase revamp continues * Coinbase revamp continues * Coinbasepro revamp is ceaseless * Coinbase revamp, starting on advanced trade API * Coinbase Advanced Trade Starts in Ernest V3 done, onto V2 Coinbase revamp nears completion Coinbase revamp nears completion Test commit should fail Coinbase revamp nears completion * Coinbase revamp stage wrapper * Coinbase wrapper coherence continues * Coinbase wrapper continues writhing * Coinbase wrapper & codebase cleanup * Coinbase updates & wrap progress * More Coinbase wrapper progress * Wrapper is wrapped, kinda * Test & type checking * Coinbase REST revamp finished * Post-merge fix * WS revamp begins * WS Main Revamp Done? * CB websocket tidying up * Coinbase WS wrapperupperer * Coinbase revamp done?? * Linter progress * Continued lint cleanup * Further lint cleanup * Increased lint coverage * Does this fix all sloppy reassigns & shadowing? * Undoing retry policy change * Documentation regeneration * Coinbase code improvements * Providing warning about known issue * Updating an error to new format * Making gocritic happy * Review adherence * Endpoints moved to V3 & nil pointer fixes * Removing seemingly superfluous constant * Glorious improvements * Removing unused error * Partial public endpoint addition * Slight improvements * Wrapper improvements; still a few errors left in other packages * A lil Coinbase progress * Json cleaning * Lint appeasement * Config repair * Config fix (real) * Little fix * New public endpoint incorporation * Additional fixes * Improvements & Appeasements * LineSaver * Additional fixes * Another fix * Fixing picked nits * Quick fixies * Lil fixes * Subscriptions: Add List.Enabled * CoinbasePro: Add subscription templating * fixup! CoinbasePro: Add subscription templating * fixup! CoinbasePro: Add subscription templating * Comment fix * Subsequent fixes * Issues hopefully fixed * Lint fix * Glorious fixes * Json formatting * ShazNits * (L/N)i(n/)t * Adding a test * Tiny test improvement * Template patch testing * Fixes * Further shaznits * Lint nit * JWT move and other fixes * Small nits * Shaznit, singular * Post-merge fix * Post-merge fixes * Typo fix * Some glorious nits * Required changes * Stop going * Alias attempt * Alias fix & test cleanup * Test fix * GetDepositAddress logic improvement * Status update: Fixed * Lint fix * Happy birthday to PR 1480 * Cleanups * Necessary nit corrections * Fixing sillybug * As per request * Programming progress * Order fixes * Further fixies * Test fix * Pre-merge fixes * More shaznits * Context * Sonic error handling * Import fix * Better Sonic error handling * Perfect Sonic error handling? * F purge * Coinbase improvements * API Update Conformity * Coinbase continuation * Coinbase order improvements * Coinbase order improvements * CreateOrderConfig improvements * Managing API updates * Coinbase API update progression * jwt rename * Comment link fix * Coinbase v2 cleanup * Post-merge fixes * Review fixes * GK's suggestions * Linter fix * Minor gbjk fixes * Nit fixes * Merge fix * Lint fixes * Coinbase rename stage 1 * Coinbase rename stage 2 * Coinbase rename stage 3 * Coinbase rename stage 4 * Coinbase rename final fix * Coinbase: PoC on converting to request structs * Applying requested changes * Many review fixes, handled * Thrashed by nits * More minor modifications * The last nit!? --------- Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
212 lines
4.6 KiB
Go
212 lines
4.6 KiB
Go
package engine
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/thrasher-corp/gocryptotrader/common"
|
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/bitfinex"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
|
)
|
|
|
|
type broken struct {
|
|
bitfinex.Exchange
|
|
}
|
|
|
|
func (b *broken) Shutdown() error { return errExpectedTestError }
|
|
|
|
func TestNewExchangeManager(t *testing.T) {
|
|
t.Parallel()
|
|
m := NewExchangeManager()
|
|
if m == nil { //nolint:staticcheck,nolintlint // SA5011 Ignore the nil warnings
|
|
t.Fatalf("unexpected response")
|
|
}
|
|
if m.exchanges == nil { //nolint:staticcheck,nolintlint // SA5011 Ignore the nil warnings
|
|
t.Error("unexpected response")
|
|
}
|
|
}
|
|
|
|
func TestExchangeManagerAdd(t *testing.T) {
|
|
t.Parallel()
|
|
var m *ExchangeManager
|
|
err := m.Add(nil)
|
|
require.ErrorIs(t, err, ErrNilSubsystem)
|
|
|
|
m = NewExchangeManager()
|
|
err = m.Add(nil)
|
|
require.ErrorIs(t, err, errExchangeIsNil)
|
|
|
|
b := new(bitfinex.Exchange)
|
|
b.SetDefaults()
|
|
err = m.Add(b)
|
|
require.NoError(t, err)
|
|
|
|
err = m.Add(b)
|
|
require.ErrorIs(t, err, ErrExchangeAlreadyLoaded)
|
|
|
|
exchanges, err := m.GetExchanges()
|
|
if err != nil {
|
|
t.Error("no exchange manager found")
|
|
}
|
|
if exchanges[0].GetName() != "Bitfinex" {
|
|
t.Error("unexpected exchange name")
|
|
}
|
|
}
|
|
|
|
func TestExchangeManagerGetExchanges(t *testing.T) {
|
|
t.Parallel()
|
|
var m *ExchangeManager
|
|
_, err := m.GetExchanges()
|
|
require.ErrorIs(t, err, ErrNilSubsystem)
|
|
|
|
m = NewExchangeManager()
|
|
exchanges, err := m.GetExchanges()
|
|
if err != nil {
|
|
t.Error("no exchange manager found")
|
|
}
|
|
if len(exchanges) != 0 {
|
|
t.Error("unexpected value")
|
|
}
|
|
b := new(bitfinex.Exchange)
|
|
b.SetDefaults()
|
|
err = m.Add(b)
|
|
require.NoError(t, err)
|
|
|
|
exchanges, err = m.GetExchanges()
|
|
if err != nil {
|
|
t.Error("no exchange manager found")
|
|
}
|
|
if exchanges[0].GetName() != "Bitfinex" {
|
|
t.Error("unexpected exchange name")
|
|
}
|
|
}
|
|
|
|
func TestExchangeManagerRemoveExchange(t *testing.T) {
|
|
t.Parallel()
|
|
var m *ExchangeManager
|
|
err := m.RemoveExchange("")
|
|
require.ErrorIs(t, err, ErrNilSubsystem)
|
|
|
|
m = NewExchangeManager()
|
|
|
|
err = m.RemoveExchange("")
|
|
require.ErrorIs(t, err, common.ErrExchangeNameNotSet)
|
|
|
|
err = m.RemoveExchange("Bitfinex")
|
|
require.ErrorIs(t, err, ErrExchangeNotFound)
|
|
|
|
b := new(bitfinex.Exchange)
|
|
b.SetDefaults()
|
|
err = m.Add(b)
|
|
require.NoError(t, err)
|
|
|
|
err = m.RemoveExchange("Bitstamp")
|
|
assert.ErrorIs(t, err, ErrExchangeNotFound)
|
|
|
|
err = m.RemoveExchange("BiTFiNeX")
|
|
require.NoError(t, err)
|
|
|
|
if len(m.exchanges) != 0 {
|
|
t.Error("exchange manager len should be 0")
|
|
}
|
|
|
|
brokenExch := &broken{}
|
|
brokenExch.SetDefaults()
|
|
|
|
err = m.Add(brokenExch)
|
|
require.NoError(t, err)
|
|
|
|
err = m.RemoveExchange("BiTFiNeX")
|
|
require.ErrorIs(t, err, errExpectedTestError)
|
|
}
|
|
|
|
func TestNewExchangeByName(t *testing.T) {
|
|
var m *ExchangeManager
|
|
_, err := m.NewExchangeByName("")
|
|
require.ErrorIs(t, err, ErrNilSubsystem)
|
|
|
|
m = NewExchangeManager()
|
|
_, err = m.NewExchangeByName("")
|
|
require.ErrorIs(t, err, common.ErrExchangeNameNotSet)
|
|
|
|
exchanges := exchange.Exchanges
|
|
exchanges = append(exchanges, "fake")
|
|
for i := range exchanges {
|
|
var exch exchange.IBotExchange
|
|
exch, err = m.NewExchangeByName(exchanges[i])
|
|
if err != nil && exchanges[i] != "fake" {
|
|
t.Fatal(err)
|
|
}
|
|
if err == nil {
|
|
exch.SetDefaults()
|
|
if !strings.EqualFold(exch.GetName(), exchanges[i]) {
|
|
t.Error("did not load expected exchange")
|
|
}
|
|
}
|
|
}
|
|
|
|
load := &bitfinex.Exchange{}
|
|
load.SetDefaults()
|
|
|
|
err = m.Add(load)
|
|
require.NoError(t, err)
|
|
|
|
_, err = m.NewExchangeByName("bitfinex")
|
|
require.ErrorIs(t, err, ErrExchangeAlreadyLoaded)
|
|
}
|
|
|
|
type ExchangeBuilder struct{}
|
|
|
|
func (n ExchangeBuilder) NewExchangeByName(name string) (exchange.IBotExchange, error) {
|
|
var exch exchange.IBotExchange
|
|
|
|
switch name {
|
|
case "customex":
|
|
exch = new(sharedtestvalues.CustomEx)
|
|
default:
|
|
return nil, fmt.Errorf("%s, %w", name, ErrExchangeNotFound)
|
|
}
|
|
|
|
return exch, nil
|
|
}
|
|
|
|
func TestNewCustomExchangeByName(t *testing.T) {
|
|
m := NewExchangeManager()
|
|
m.Builder = ExchangeBuilder{}
|
|
name := "customex"
|
|
exch, err := m.NewExchangeByName(name)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err == nil {
|
|
exch.SetDefaults()
|
|
if !strings.EqualFold(exch.GetName(), name) {
|
|
t.Error("did not load expected exchange")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestExchangeManagerShutdown(t *testing.T) {
|
|
t.Parallel()
|
|
var m *ExchangeManager
|
|
err := m.Shutdown(-1)
|
|
require.ErrorIs(t, err, ErrNilSubsystem)
|
|
|
|
m = NewExchangeManager()
|
|
err = m.Shutdown(-1)
|
|
require.NoError(t, err)
|
|
|
|
brokenExch := &broken{}
|
|
brokenExch.SetDefaults()
|
|
|
|
err = m.Add(brokenExch)
|
|
require.NoError(t, err)
|
|
|
|
err = m.Shutdown(-1)
|
|
require.NoError(t, err)
|
|
}
|