mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
* Initial REST managed order updating
* Apply gloriousCode's changes.go patch
* Update internal order ID handling
* Check error
* Replace string with string pointer
* Avoid nil pointers in upsert
* Update test for UpdateOrderFromDetail()
* Add tests for orders.go
* Remove unnecessary newline
* Address comments
* Add missing nil check
* Add tests for new functions in order_manager.go
* Remove empty line
* Change log level for updates from Info to Debug (keep added orders at Info)
* Initialize orders before running the timer
* [TEMP] Add verbosity for debugging
* Nil checking on exchangeManager in GetExchanges()
- exchangeManager.GetExchanges() and iExchangeManager.GetExchanges() return an error on nil
- bot.GetExchanges() wraps exchangeManager.GetExchanges() and returns an empty slice
* Revert b5afe1a46b
* Do not start the order manager runner thread
Instead, mark the order manager as running
* Remove redundant error.Is() and remove print wrapper on msg
* Add atomic blocker and waitgroup on processOrders()
* Disable unnecessary orderManager runner thread for rpcserver_test
* Remove redundant err from orderStore.getActiveOrders()
* [FIX] Populate requiresProcessing using UpsertResponse data instead of REST return data
.. because the data returned by the REST calls do not include the internal user ID's
* [TEST] Verify that processOrders() actually processes queried order data
* Remove leftover warning and add nil check on wg.Done()
* Apply suggestions from code review
Log category changes - as suggested
Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
* Return when no exchanges available
Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
130 lines
3.2 KiB
Go
130 lines
3.2 KiB
Go
package engine
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/bitfinex"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
|
)
|
|
|
|
func TestSetupExchangeManager(t *testing.T) {
|
|
t.Parallel()
|
|
m := SetupExchangeManager()
|
|
if m == nil {
|
|
t.Fatalf("unexpected response")
|
|
}
|
|
if m.exchanges == nil {
|
|
t.Error("unexpected response")
|
|
}
|
|
}
|
|
|
|
func TestExchangeManagerAdd(t *testing.T) {
|
|
t.Parallel()
|
|
m := SetupExchangeManager()
|
|
b := new(bitfinex.Bitfinex)
|
|
b.SetDefaults()
|
|
m.Add(b)
|
|
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()
|
|
m := SetupExchangeManager()
|
|
exchanges, err := m.GetExchanges()
|
|
if err != nil {
|
|
t.Error("no exchange manager found")
|
|
}
|
|
if exchanges != nil {
|
|
t.Error("unexpected value")
|
|
}
|
|
b := new(bitfinex.Bitfinex)
|
|
b.SetDefaults()
|
|
m.Add(b)
|
|
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()
|
|
m := SetupExchangeManager()
|
|
if err := m.RemoveExchange("Bitfinex"); err != ErrNoExchangesLoaded {
|
|
t.Error("no exchanges should be loaded")
|
|
}
|
|
b := new(bitfinex.Bitfinex)
|
|
b.SetDefaults()
|
|
m.Add(b)
|
|
err := m.RemoveExchange("Bitstamp")
|
|
if !errors.Is(err, ErrExchangeNotFound) {
|
|
t.Errorf("received: %v but expected: %v", err, ErrExchangeNotFound)
|
|
}
|
|
if err := m.RemoveExchange("BiTFiNeX"); err != nil {
|
|
t.Error("exchange should have been removed")
|
|
}
|
|
if m.Len() != 0 {
|
|
t.Error("exchange manager len should be 0")
|
|
}
|
|
}
|
|
|
|
func TestNewExchangeByName(t *testing.T) {
|
|
m := SetupExchangeManager()
|
|
exchanges := []string{"binance", "bitfinex", "bitflyer", "bithumb", "bitmex", "bitstamp", "bittrex", "btc markets", "btse", "coinbene", "coinut", "exmo", "coinbasepro", "ftx", "gateio", "gemini", "hitbtc", "huobi", "itbit", "kraken", "lbank", "localbitcoins", "okcoin international", "okex", "poloniex", "yobit", "zb", "fake"}
|
|
for i := range exchanges {
|
|
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")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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 := SetupExchangeManager()
|
|
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")
|
|
}
|
|
}
|
|
}
|