mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Improvement: Subsystem separation (#664)
* Initial codes for a trade tracker * Moving everything in a broken fashion * Removes tradetracker. Removes some errors for subsystems * Cleans up some subsystems, renames stuttering types. Removes some global Bot usage * More basic subsystem renaming and file moving * Removes engine dependency from events,ntpserver,ordermanager,comms manager * Exports eventManager, fixes rpcserver. puts rpcserver back for now * Removes redundant error message, further removes engine dependencies * experimental end of day interface usage * adds ability to build the application * Withdraw and event manager handling * cleans up apiserver and communications manager * Cleans up some start/setup processes. Though should separate * More consistency with Setup Start Stop IsRunning funcs * Final consistency pass before testing phase * Fixes engine tests. Fixes stop nil issue * api server tests * Communications manager testing * Connection manager tests and nilsubsystem error * End of day currencypairsyncer tests * Adds databaseconnection/databaseconnection_test.go * Adds withdrawal manager tests * Deposit address testing. Moved orderbook sync first as its more important * Adds test for event manager * More full eventmanager testing * Adds testfile. Enables skipped test. * ntp manager tests * Adds ordermanager tests, Extracts a whole new subsystem from engine and fanangles import cycles * Adds websocket routine manager tests * Basic portfolio manager testing * Fixes issue with currency pair sync startup * Fixes issue with event manager startup * Starts the order manager before backtester starts * Fixes fee tests. Expands testing. Doesnt fix races * Fixes most test races * Resolves data races * Fixes subsystem test issues * currency pair syncer coverage tests * Refactors portfolio. Fixes tests. Withdraw validation Portfolio didn't need to exist with a portfolio manager. Now the porfolio manager is in charge how the portfolio is handled and all portfolio functions are attached to the base instead of just exported at the package level Withdrawal validation occurred at the exchange level when it can just be run at the withdrawal manager level. All withdrawal requests go through that endpoint * lint -fix * golang lint fixes * lints and comments everything * Updates GCT logo, adds documentation for some subsystems * More documentation and more logo updates * Fixes backtesting and apiserver errors encountered * Fixes errors and typos from reviewing * More minor fixes * Changes %h verb to %w * reverbs to %s * Humbly begins reverting to more flat engine package The main reasoning for this is that the subsystem split doesn't make sense in a golang environment. The subsystems are only meant to be used with engine and so by placing them in a non-engine area, it does not work and is inconsistent with the rest of the application's package layout. This will begin salvaging the changes made by reverting to a flat engine package, but maintaining the consistent designs introduced. Further, I will look to remove any TestMains and decrease the scope of testing to be more local and decrease the issues that have been caused from our style of testing. * Manages to re-flatten things. Everything is within its own file * mini fixes * Fixes tests and data races and lints * Updates docs tool for engine to create filename readmes * os -> ioutil * remove err * Appveyor version increase test * Removes tCleanup as its unsupported on appveyor * Adds stuff that I thought was in previous merge master commit * Removes cancel from test * Fixes really fun test-exclusive data race * minor nit fixes * niterinos * docs gen * rm;rf test * Remove typoline. expands startstop helper. Splits apiserver * Removes accidental folder * Uses update instead of replace for order upsert * addresses nits. Renames files. Regenerates documentation. * lint and removal of comments * Add new test for default scenario * Fixes typo * regen docs
This commit is contained in:
@@ -44,7 +44,7 @@ func LoadData(dataType int64, startDate, endDate time.Time, interval time.Durati
|
||||
return nil, fmt.Errorf("could not convert trade data to candles for %v %v %v, %v", exch.GetName(), a, fPair, err)
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("could not retrieve data for %v %v %v, invalid data type received", exch.GetName(), a, fPair)
|
||||
return nil, fmt.Errorf("could not retrieve data for %v %v %v, %w", exch.GetName(), a, fPair, common.ErrInvalidDataType)
|
||||
}
|
||||
candles.Exchange = strings.ToLower(candles.Exchange)
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -33,6 +33,7 @@ func TestMain(m *testing.M) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
bot.ExchangeManager = engine.SetupExchangeManager()
|
||||
err = bot.LoadExchange(testExchange, false, nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -62,15 +63,15 @@ func TestLoadCandles(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err = LoadData(-1, tt1, tt2, interval.Duration(), exch, p, a)
|
||||
if err != nil && !strings.Contains(err.Error(), "could not retrieve data for Binance spot BTCUSDT, invalid data type received") {
|
||||
t.Error(err)
|
||||
if !errors.Is(err, common.ErrInvalidDataType) {
|
||||
t.Errorf("expected '%v' received '%v'", err, common.ErrInvalidDataType)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadTrades(t *testing.T) {
|
||||
t.Parallel()
|
||||
interval := gctkline.FifteenMin
|
||||
tt1 := time.Now().Add(-time.Minute * 60).Round(interval.Duration())
|
||||
tt1 := time.Now().Add(-time.Minute * 15).Round(interval.Duration())
|
||||
tt2 := time.Now().Round(interval.Duration())
|
||||
a := asset.Spot
|
||||
p := currency.NewPair(currency.BTC, currency.USDT)
|
||||
|
||||
@@ -149,7 +149,7 @@ func LoadData(dataType int64, filepath, exchangeName string, interval time.Durat
|
||||
return nil, fmt.Errorf("could not read csv trade data for %v %v %v, %v", exchangeName, a, fPair, err)
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("could not process csv data for %v %v %v, invalid data type received", exchangeName, a, fPair)
|
||||
return nil, fmt.Errorf("could not process csv data for %v %v %v, %w", exchangeName, a, fPair, common.ErrInvalidDataType)
|
||||
}
|
||||
resp.Item.Exchange = strings.ToLower(exchangeName)
|
||||
resp.Item.Pair = fPair
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package csv
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/backtester/common"
|
||||
@@ -56,7 +56,7 @@ func TestLoadDataInvalid(t *testing.T) {
|
||||
gctkline.FifteenMin.Duration(),
|
||||
p,
|
||||
a)
|
||||
if err != nil && !strings.Contains(err.Error(), "could not process csv data for binance spot BTCUSDT, invalid data type received") {
|
||||
t.Error(err)
|
||||
if !errors.Is(err, common.ErrInvalidDataType) {
|
||||
t.Errorf("expected '%v' received '%v'", err, common.ErrInvalidDataType)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func LoadData(startDate, endDate time.Time, interval time.Duration, exchangeName
|
||||
}
|
||||
resp.Item = klineItem
|
||||
default:
|
||||
return nil, fmt.Errorf("could not retrieve database data for %v %v %v, invalid data type received", exchangeName, a, fPair)
|
||||
return nil, fmt.Errorf("could not retrieve database data for %v %v %v, %w", exchangeName, a, fPair, common.ErrInvalidDataType)
|
||||
}
|
||||
resp.Item.Exchange = strings.ToLower(resp.Item.Exchange)
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -86,7 +86,11 @@ func TestLoadDataCandles(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = bot.DatabaseManager.Start(bot)
|
||||
bot.DatabaseManager, err = engine.SetupDatabaseConnectionManager(&bot.Config.Database)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
err = bot.DatabaseManager.Start(&bot.ServicesWG)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -161,7 +165,11 @@ func TestLoadDataTrades(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = bot.DatabaseManager.Start(bot)
|
||||
bot.DatabaseManager, err = engine.SetupDatabaseConnectionManager(&bot.Config.Database)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
err = bot.DatabaseManager.Start(&bot.ServicesWG)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -202,7 +210,7 @@ func TestLoadDataInvalid(t *testing.T) {
|
||||
dStart := time.Date(2020, 1, 0, 0, 0, 0, 0, time.UTC)
|
||||
dEnd := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
_, err := LoadData(dStart, dEnd, gctkline.FifteenMin.Duration(), exch, -1, p, a)
|
||||
if err != nil && !strings.Contains(err.Error(), "could not retrieve database data for binance spot BTCUSDT, invalid data type received") {
|
||||
t.Error(err)
|
||||
if !errors.Is(err, common.ErrInvalidDataType) {
|
||||
t.Errorf("expected '%v' received '%v'", err, common.ErrInvalidDataType)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func LoadData(exch exchange.IBotExchange, dataType int64, interval time.Duration
|
||||
}
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("could not retrieve live data for %v %v %v, invalid data type received", exch.GetName(), a, fPair)
|
||||
return nil, fmt.Errorf("could not retrieve live data for %v %v %v, %w", exch.GetName(), a, fPair, common.ErrInvalidDataType)
|
||||
}
|
||||
candles.Exchange = strings.ToLower(exch.GetName())
|
||||
return &candles, nil
|
||||
|
||||
@@ -1,40 +1,38 @@
|
||||
package live
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/backtester/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/engine"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
gctkline "github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
||||
)
|
||||
|
||||
const testExchange = "binance"
|
||||
const testExchange = "FTX"
|
||||
|
||||
func TestLoadCandles(t *testing.T) {
|
||||
t.Parallel()
|
||||
interval := gctkline.FifteenMin
|
||||
bot, err := engine.NewFromSettings(&engine.Settings{
|
||||
ConfigFile: filepath.Join("..", "..", "..", "..", "testdata", "configtest.json"),
|
||||
EnableDryRun: true,
|
||||
}, nil)
|
||||
bot := new(engine.Engine)
|
||||
bot.Config = &config.Config{}
|
||||
err := bot.Config.LoadConfig(filepath.Join("..", "..", "..", "..", "testdata", "configtest.json"), true)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.Fatalf("SetupTest: Failed to load config: %s", err)
|
||||
}
|
||||
|
||||
bot.ExchangeManager = engine.SetupExchangeManager()
|
||||
err = bot.LoadExchange(testExchange, false, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
exch := bot.GetExchangeByName(testExchange)
|
||||
if exch == nil {
|
||||
t.Fatal("expected binance")
|
||||
log.Fatal(err)
|
||||
}
|
||||
exch := bot.ExchangeManager.GetExchangeByName(testExchange)
|
||||
a := asset.Spot
|
||||
p := currency.NewPair(currency.BTC, currency.USDT)
|
||||
p := currency.NewPair(currency.BTC, currency.USD)
|
||||
var data *gctkline.Item
|
||||
data, err = LoadData(exch, common.DataCandle, interval.Duration(), p, a)
|
||||
if err != nil {
|
||||
@@ -45,8 +43,8 @@ func TestLoadCandles(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err = LoadData(exch, -1, interval.Duration(), p, a)
|
||||
if err != nil && !strings.Contains(err.Error(), "could not retrieve live data for Binance spot BTCUSDT, invalid data type received") {
|
||||
t.Error(err)
|
||||
if !errors.Is(err, common.ErrInvalidDataType) {
|
||||
t.Errorf("expected '%v' received '%v'", err, common.ErrInvalidDataType)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +58,7 @@ func TestLoadTrades(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
bot.ExchangeManager = engine.SetupExchangeManager()
|
||||
|
||||
err = bot.LoadExchange(testExchange, false, nil)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user