mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
* 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
315 lines
14 KiB
Go
315 lines
14 KiB
Go
package config
|
|
|
|
import (
|
|
"errors"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/thrasher-corp/gocryptotrader/communications/base"
|
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
|
"github.com/thrasher-corp/gocryptotrader/database"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/protocol"
|
|
gctscript "github.com/thrasher-corp/gocryptotrader/gctscript/vm"
|
|
"github.com/thrasher-corp/gocryptotrader/log"
|
|
"github.com/thrasher-corp/gocryptotrader/portfolio"
|
|
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
|
)
|
|
|
|
// Constants declared here are filename strings and test strings
|
|
const (
|
|
FXProviderFixer = "fixer"
|
|
EncryptedFile = "config.dat"
|
|
File = "config.json"
|
|
TestFile = "../testdata/configtest.json"
|
|
fileEncryptionPrompt = 0
|
|
fileEncryptionEnabled = 1
|
|
fileEncryptionDisabled = -1
|
|
pairsLastUpdatedWarningThreshold = 30 // 30 days
|
|
defaultHTTPTimeout = time.Second * 15
|
|
defaultWebsocketResponseCheckTimeout = time.Millisecond * 30
|
|
defaultWebsocketResponseMaxLimit = time.Second * 7
|
|
defaultWebsocketOrderbookBufferLimit = 5
|
|
defaultWebsocketTrafficTimeout = time.Second * 30
|
|
maxAuthFailures = 3
|
|
defaultNTPAllowedDifference = 50000000
|
|
defaultNTPAllowedNegativeDifference = 50000000
|
|
DefaultAPIKey = "Key"
|
|
DefaultAPISecret = "Secret"
|
|
DefaultAPIClientID = "ClientID"
|
|
)
|
|
|
|
// Constants here hold some messages
|
|
const (
|
|
ErrExchangeNameEmpty = "exchange #%d name is empty"
|
|
ErrNoEnabledExchanges = "no exchanges enabled"
|
|
ErrFailureOpeningConfig = "fatal error opening %s file. Error: %s"
|
|
ErrCheckingConfigValues = "fatal error checking config values. Error: %s"
|
|
WarningExchangeAuthAPIDefaultOrEmptyValues = "exchange %s authenticated API support disabled due to default/empty APIKey/Secret/ClientID values"
|
|
WarningPairsLastUpdatedThresholdExceeded = "exchange %s last manual update of available currency pairs has exceeded %d days. Manual update required!"
|
|
)
|
|
|
|
// Constants here define unset default values displayed in the config.json
|
|
// file
|
|
const (
|
|
APIURLNonDefaultMessage = "NON_DEFAULT_HTTP_LINK_TO_EXCHANGE_API"
|
|
WebsocketURLNonDefaultMessage = "NON_DEFAULT_HTTP_LINK_TO_WEBSOCKET_EXCHANGE_API"
|
|
DefaultUnsetAPIKey = "Key"
|
|
DefaultUnsetAPISecret = "Secret"
|
|
DefaultUnsetAccountPlan = "accountPlan"
|
|
DefaultForexProviderExchangeRatesAPI = "ExchangeRateHost"
|
|
)
|
|
|
|
// Variables here are used for configuration
|
|
var (
|
|
Cfg Config
|
|
m sync.Mutex
|
|
ErrExchangeNotFound = errors.New("exchange not found")
|
|
)
|
|
|
|
// Config is the overarching object that holds all the information for
|
|
// prestart management of Portfolio, Communications, Webserver and Enabled
|
|
// Exchanges
|
|
type Config struct {
|
|
Name string `json:"name"`
|
|
DataDirectory string `json:"dataDirectory"`
|
|
EncryptConfig int `json:"encryptConfig"`
|
|
GlobalHTTPTimeout time.Duration `json:"globalHTTPTimeout"`
|
|
Database database.Config `json:"database"`
|
|
Logging log.Config `json:"logging"`
|
|
ConnectionMonitor ConnectionMonitorConfig `json:"connectionMonitor"`
|
|
Profiler Profiler `json:"profiler"`
|
|
NTPClient NTPClientConfig `json:"ntpclient"`
|
|
GCTScript gctscript.Config `json:"gctscript"`
|
|
Currency CurrencyConfig `json:"currencyConfig"`
|
|
Communications base.CommunicationsConfig `json:"communications"`
|
|
RemoteControl RemoteControlConfig `json:"remoteControl"`
|
|
Portfolio portfolio.Base `json:"portfolioAddresses"`
|
|
Exchanges []ExchangeConfig `json:"exchanges"`
|
|
BankAccounts []banking.Account `json:"bankAccounts"`
|
|
|
|
// Deprecated config settings, will be removed at a future date
|
|
Webserver *WebserverConfig `json:"webserver,omitempty"`
|
|
CurrencyPairFormat *CurrencyPairFormatConfig `json:"currencyPairFormat,omitempty"`
|
|
FiatDisplayCurrency *currency.Code `json:"fiatDispayCurrency,omitempty"`
|
|
Cryptocurrencies *currency.Currencies `json:"cryptocurrencies,omitempty"`
|
|
SMS *base.SMSGlobalConfig `json:"smsGlobal,omitempty"`
|
|
// encryption session values
|
|
storedSalt []byte
|
|
sessionDK []byte
|
|
}
|
|
|
|
// ConnectionMonitorConfig defines the connection monitor variables to ensure
|
|
// that there is internet connectivity
|
|
type ConnectionMonitorConfig struct {
|
|
DNSList []string `json:"preferredDNSList"`
|
|
PublicDomainList []string `json:"preferredDomainList"`
|
|
CheckInterval time.Duration `json:"checkInterval"`
|
|
}
|
|
|
|
// ExchangeConfig holds all the information needed for each enabled Exchange.
|
|
type ExchangeConfig struct {
|
|
Name string `json:"name"`
|
|
Enabled bool `json:"enabled"`
|
|
Verbose bool `json:"verbose"`
|
|
UseSandbox bool `json:"useSandbox,omitempty"`
|
|
HTTPTimeout time.Duration `json:"httpTimeout"`
|
|
HTTPUserAgent string `json:"httpUserAgent,omitempty"`
|
|
HTTPDebugging bool `json:"httpDebugging,omitempty"`
|
|
WebsocketResponseCheckTimeout time.Duration `json:"websocketResponseCheckTimeout"`
|
|
WebsocketResponseMaxLimit time.Duration `json:"websocketResponseMaxLimit"`
|
|
WebsocketTrafficTimeout time.Duration `json:"websocketTrafficTimeout"`
|
|
ProxyAddress string `json:"proxyAddress,omitempty"`
|
|
BaseCurrencies currency.Currencies `json:"baseCurrencies"`
|
|
CurrencyPairs *currency.PairsManager `json:"currencyPairs"`
|
|
API APIConfig `json:"api"`
|
|
Features *FeaturesConfig `json:"features"`
|
|
BankAccounts []banking.Account `json:"bankAccounts,omitempty"`
|
|
OrderbookConfig `json:"orderbook"`
|
|
|
|
// Deprecated settings which will be removed in a future update
|
|
AvailablePairs *currency.Pairs `json:"availablePairs,omitempty"`
|
|
EnabledPairs *currency.Pairs `json:"enabledPairs,omitempty"`
|
|
AssetTypes *string `json:"assetTypes,omitempty"`
|
|
PairsLastUpdated *int64 `json:"pairsLastUpdated,omitempty"`
|
|
ConfigCurrencyPairFormat *currency.PairFormat `json:"configCurrencyPairFormat,omitempty"`
|
|
RequestCurrencyPairFormat *currency.PairFormat `json:"requestCurrencyPairFormat,omitempty"`
|
|
AuthenticatedAPISupport *bool `json:"authenticatedApiSupport,omitempty"`
|
|
AuthenticatedWebsocketAPISupport *bool `json:"authenticatedWebsocketApiSupport,omitempty"`
|
|
APIKey *string `json:"apiKey,omitempty"`
|
|
APISecret *string `json:"apiSecret,omitempty"`
|
|
APIAuthPEMKeySupport *bool `json:"apiAuthPemKeySupport,omitempty"`
|
|
APIAuthPEMKey *string `json:"apiAuthPemKey,omitempty"`
|
|
APIURL *string `json:"apiUrl,omitempty"`
|
|
APIURLSecondary *string `json:"apiUrlSecondary,omitempty"`
|
|
ClientID *string `json:"clientId,omitempty"`
|
|
SupportsAutoPairUpdates *bool `json:"supportsAutoPairUpdates,omitempty"`
|
|
Websocket *bool `json:"websocket,omitempty"`
|
|
WebsocketURL *string `json:"websocketUrl,omitempty"`
|
|
}
|
|
|
|
// Profiler defines the profiler configuration to enable pprof
|
|
type Profiler struct {
|
|
Enabled bool `json:"enabled"`
|
|
MutexProfileFraction int `json:"mutex_profile_fraction"`
|
|
}
|
|
|
|
// NTPClientConfig defines a network time protocol configuration to allow for
|
|
// positive and negative differences
|
|
type NTPClientConfig struct {
|
|
Level int `json:"enabled"`
|
|
Pool []string `json:"pool"`
|
|
AllowedDifference *time.Duration `json:"allowedDifference"`
|
|
AllowedNegativeDifference *time.Duration `json:"allowedNegativeDifference"`
|
|
}
|
|
|
|
// GRPCConfig stores the gRPC settings
|
|
type GRPCConfig struct {
|
|
Enabled bool `json:"enabled"`
|
|
ListenAddress string `json:"listenAddress"`
|
|
GRPCProxyEnabled bool `json:"grpcProxyEnabled"`
|
|
GRPCProxyListenAddress string `json:"grpcProxyListenAddress"`
|
|
}
|
|
|
|
// DepcrecatedRPCConfig stores the deprecatedRPCConfig settings
|
|
type DepcrecatedRPCConfig struct {
|
|
Enabled bool `json:"enabled"`
|
|
ListenAddress string `json:"listenAddress"`
|
|
}
|
|
|
|
// WebsocketRPCConfig stores the websocket config info
|
|
type WebsocketRPCConfig struct {
|
|
Enabled bool `json:"enabled"`
|
|
ListenAddress string `json:"listenAddress"`
|
|
ConnectionLimit int `json:"connectionLimit"`
|
|
MaxAuthFailures int `json:"maxAuthFailures"`
|
|
AllowInsecureOrigin bool `json:"allowInsecureOrigin"`
|
|
}
|
|
|
|
// RemoteControlConfig stores the RPC services config
|
|
type RemoteControlConfig struct {
|
|
Username string `json:"username"`
|
|
Password string `json:"password"`
|
|
|
|
GRPC GRPCConfig `json:"gRPC"`
|
|
DeprecatedRPC DepcrecatedRPCConfig `json:"deprecatedRPC"`
|
|
WebsocketRPC WebsocketRPCConfig `json:"websocketRPC"`
|
|
}
|
|
|
|
// WebserverConfig stores the old webserver config
|
|
type WebserverConfig struct {
|
|
Enabled bool `json:"enabled"`
|
|
AdminUsername string `json:"adminUsername"`
|
|
AdminPassword string `json:"adminPassword"`
|
|
ListenAddress string `json:"listenAddress"`
|
|
WebsocketConnectionLimit int `json:"websocketConnectionLimit"`
|
|
WebsocketMaxAuthFailures int `json:"websocketMaxAuthFailures"`
|
|
WebsocketAllowInsecureOrigin bool `json:"websocketAllowInsecureOrigin"`
|
|
}
|
|
|
|
// Post holds the bot configuration data
|
|
type Post struct {
|
|
Data Config `json:"data"`
|
|
}
|
|
|
|
// CurrencyPairFormatConfig stores the users preferred currency pair display
|
|
type CurrencyPairFormatConfig struct {
|
|
Uppercase bool `json:"uppercase"`
|
|
Delimiter string `json:"delimiter,omitempty"`
|
|
Separator string `json:"separator,omitempty"`
|
|
Index string `json:"index,omitempty"`
|
|
}
|
|
|
|
// BankTransaction defines a related banking transaction
|
|
type BankTransaction struct {
|
|
ReferenceNumber string `json:"referenceNumber"`
|
|
TransactionNumber string `json:"transactionNumber"`
|
|
PaymentInstructions string `json:"paymentInstructions"`
|
|
}
|
|
|
|
// CurrencyConfig holds all the information needed for currency related manipulation
|
|
type CurrencyConfig struct {
|
|
ForexProviders []currency.FXSettings `json:"forexProviders"`
|
|
CryptocurrencyProvider CryptocurrencyProvider `json:"cryptocurrencyProvider"`
|
|
Cryptocurrencies currency.Currencies `json:"cryptocurrencies"`
|
|
CurrencyPairFormat *CurrencyPairFormatConfig `json:"currencyPairFormat"`
|
|
FiatDisplayCurrency currency.Code `json:"fiatDisplayCurrency"`
|
|
CurrencyFileUpdateDuration time.Duration `json:"currencyFileUpdateDuration"`
|
|
ForeignExchangeUpdateDuration time.Duration `json:"foreignExchangeUpdateDuration"`
|
|
}
|
|
|
|
// CryptocurrencyProvider defines coinmarketcap tools
|
|
type CryptocurrencyProvider struct {
|
|
Name string `json:"name"`
|
|
Enabled bool `json:"enabled"`
|
|
Verbose bool `json:"verbose"`
|
|
APIkey string `json:"apiKey"`
|
|
AccountPlan string `json:"accountPlan"`
|
|
}
|
|
|
|
// FeaturesSupportedConfig stores the exchanges supported features
|
|
type FeaturesSupportedConfig struct {
|
|
REST bool `json:"restAPI"`
|
|
RESTCapabilities protocol.Features `json:"restCapabilities,omitempty"`
|
|
Websocket bool `json:"websocketAPI"`
|
|
WebsocketCapabilities protocol.Features `json:"websocketCapabilities,omitempty"`
|
|
}
|
|
|
|
// FeaturesEnabledConfig stores the exchanges enabled features
|
|
type FeaturesEnabledConfig struct {
|
|
AutoPairUpdates bool `json:"autoPairUpdates"`
|
|
Websocket bool `json:"websocketAPI"`
|
|
SaveTradeData bool `json:"saveTradeData"`
|
|
}
|
|
|
|
// FeaturesConfig stores the exchanges supported and enabled features
|
|
type FeaturesConfig struct {
|
|
Supports FeaturesSupportedConfig `json:"supports"`
|
|
Enabled FeaturesEnabledConfig `json:"enabled"`
|
|
}
|
|
|
|
// APIEndpointsConfig stores the API endpoint addresses
|
|
type APIEndpointsConfig struct {
|
|
URL string `json:"url"`
|
|
URLSecondary string `json:"urlSecondary"`
|
|
WebsocketURL string `json:"websocketURL"`
|
|
}
|
|
|
|
// APICredentialsConfig stores the API credentials
|
|
type APICredentialsConfig struct {
|
|
Key string `json:"key,omitempty"`
|
|
Secret string `json:"secret,omitempty"`
|
|
ClientID string `json:"clientID,omitempty"`
|
|
PEMKey string `json:"pemKey,omitempty"`
|
|
OTPSecret string `json:"otpSecret,omitempty"`
|
|
}
|
|
|
|
// APICredentialsValidatorConfig stores the API credentials validator settings
|
|
type APICredentialsValidatorConfig struct {
|
|
// For Huobi (optional)
|
|
RequiresPEM bool `json:"requiresPEM,omitempty"`
|
|
|
|
RequiresKey bool `json:"requiresKey,omitempty"`
|
|
RequiresSecret bool `json:"requiresSecret,omitempty"`
|
|
RequiresClientID bool `json:"requiresClientID,omitempty"`
|
|
RequiresBase64DecodeSecret bool `json:"requiresBase64DecodeSecret,omitempty"`
|
|
}
|
|
|
|
// APIConfig stores the exchange API config
|
|
type APIConfig struct {
|
|
AuthenticatedSupport bool `json:"authenticatedSupport"`
|
|
AuthenticatedWebsocketSupport bool `json:"authenticatedWebsocketApiSupport"`
|
|
PEMKeySupport bool `json:"pemKeySupport,omitempty"`
|
|
|
|
Credentials APICredentialsConfig `json:"credentials"`
|
|
CredentialsValidator *APICredentialsValidatorConfig `json:"credentialsValidator,omitempty"`
|
|
OldEndPoints *APIEndpointsConfig `json:"endpoints,omitempty"`
|
|
Endpoints map[string]string `json:"urlEndpoints"`
|
|
}
|
|
|
|
// OrderbookConfig stores the orderbook configuration variables
|
|
type OrderbookConfig struct {
|
|
VerificationBypass bool `json:"verificationBypass"`
|
|
WebsocketBufferLimit int `json:"websocketBufferLimit"`
|
|
WebsocketBufferEnabled bool `json:"websocketBufferEnabled"`
|
|
}
|