config

package
v0.0.0-...-b8e8dbd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2018 License: MIT Imports: 20 Imported by: 0

README

GoCryptoTrader package Config

Build Status Software License GoDoc Coverage Status Go Report Card

This config package is part of the GoCryptoTrader codebase.

This is still in active development

You can track ideas, planned features and what's in progresss on this Trello board: https://trello.com/b/ZAhMhpOy/gocryptotrader.

Join our slack to discuss all things related to GoCryptoTrader! GoCryptoTrader Slack

Current Features for config

  • This package deals with configuration utilities.
Please click GoDocs chevron above to view current GoDoc information for this package

Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

  • Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
  • Code must be documented adhering to the official Go commentary guidelines.
  • Code must adhere to our coding style.
  • Pull requests need to be based on and opened against the master branch.

Donations

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:

1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB

Documentation

Index

Constants

View Source
const (
	FXProviderFixer     = "fixer"
	EncryptedConfigFile = "config.dat"
	ConfigFile          = "config.json"
	ConfigTestFile      = "../testdata/configtest.json"
)

Constants declared here are filename strings and test strings

View Source
const (
	// EncryptConfirmString has a the general confirmation string to allow us to
	// see if the file is correctly encrypted
	EncryptConfirmString = "THORS-HAMMER"
	// SaltPrefix string
	SaltPrefix = "~GCT~SO~SALTY~"
	// SaltRandomLength is the number of random bytes to append after the prefix string
	SaltRandomLength = 12
)

Variables

View Source
var (
	ErrExchangeNameEmpty                            = "Exchange #%d in config: Exchange name is empty."
	ErrExchangeAvailablePairsEmpty                  = "Exchange %s: Available pairs is empty."
	ErrExchangeEnabledPairsEmpty                    = "Exchange %s: Enabled pairs is empty."
	ErrExchangeBaseCurrenciesEmpty                  = "Exchange %s: Base currencies is empty."
	ErrExchangeNotFound                             = "Exchange %s: Not found."
	ErrNoEnabledExchanges                           = "No Exchanges enabled."
	ErrCryptocurrenciesEmpty                        = "Cryptocurrencies variable is empty."
	ErrFailureOpeningConfig                         = "Fatal error opening %s file. Error: %s"
	ErrCheckingConfigValues                         = "Fatal error checking config values. Error: %s"
	ErrSavingConfigBytesMismatch                    = "Config file %q bytes comparison doesn't match, read %s expected %s."
	WarningSMSGlobalDefaultOrEmptyValues            = "WARNING -- SMS Support disabled due to default or empty Username/Password values."
	WarningSSMSGlobalSMSContactDefaultOrEmptyValues = "WARNING -- SMS contact #%d Name/Number disabled due to default or empty values."
	WarningSSMSGlobalSMSNoContacts                  = "WARNING -- SMS Support disabled due to no enabled contacts."
	WarningWebserverCredentialValuesEmpty           = "WARNING -- Webserver support disabled due to empty Username/Password values."
	WarningWebserverListenAddressInvalid            = "WARNING -- Webserver support disabled due to invalid listen address."
	WarningWebserverRootWebFolderNotFound           = "WARNING -- Webserver support disabled due to missing web folder."
	WarningExchangeAuthAPIDefaultOrEmptyValues      = "WARNING -- Exchange %s: Authenticated API support disabled due to default/empty APIKey/Secret/ClientID values."
	WarningCurrencyExchangeProvider                 = "WARNING -- Currency exchange provider invalid valid. Reset to Fixer."
	WarningPairsLastUpdatedThresholdExceeded        = "WARNING -- Exchange %s: Last manual update of available currency pairs has exceeded %d days. Manual update required!"
	Cfg                                             Config
	IsInitialSetup                                  bool
)

Variables here are mainly alerts and a configuration object

Functions

func ConfirmConfigJSON

func ConfirmConfigJSON(file []byte, result interface{}) error

ConfirmConfigJSON confirms JSON in file

func ConfirmECS

func ConfirmECS(file []byte) bool

ConfirmECS confirms that the encryption confirmation string is found

func ConfirmSalt

func ConfirmSalt(file []byte) bool

ConfirmSalt checks whether the encrypted data contains a salt

func DecryptConfigFile

func DecryptConfigFile(configData, key []byte) ([]byte, error)

DecryptConfigFile decrypts configuration data with the supplied key and returns the un-encrypted file as a byte array with an error

func EncryptConfigFile

func EncryptConfigFile(configData, key []byte) ([]byte, error)

EncryptConfigFile encrypts configuration data that is parsed in with a key and returns it as a byte array with an error

func GetFilePath

func GetFilePath(file string) (string, error)

GetFilePath returns the desired config file or the default config file name based on if the application is being run under test or normal mode.

func PromptForConfigKey

func PromptForConfigKey(initialSetup bool) ([]byte, error)

PromptForConfigKey asks for configuration key

func RemoveECS

func RemoveECS(file []byte) []byte

RemoveECS removes encryption confirmation string

Types

type CommunicationsConfig

type CommunicationsConfig struct {
	SlackConfig     SlackConfig     `json:"Slack"`
	SMSGlobalConfig SMSGlobalConfig `json:"SMSGlobal"`
	SMTPConfig      SMTPConfig      `json:"SMTP"`
	TelegramConfig  TelegramConfig  `json:"Telegram"`
}

CommunicationsConfig holds all the information needed for each enabled communication package

type Config

type Config struct {
	Name              string
	EncryptConfig     int
	GlobalHTTPTimeout time.Duration        `json:"GlobalHTTPTimeout"`
	Currency          CurrencyConfig       `json:"CurrencyConfig"`
	Communications    CommunicationsConfig `json:"Communications"`
	Portfolio         portfolio.Base       `json:"PortfolioAddresses"`
	Grpc              GrpcServerConfig     `json:"Grpc"`
	Exchanges         []ExchangeConfig     `json:"Exchanges"`

	// Deprecated config settings, will be removed at a future date
	CurrencyPairFormat  *CurrencyPairFormatConfig `json:"CurrencyPairFormat,omitempty"`
	FiatDisplayCurrency string                    `json:"FiatDispayCurrency,omitempty"`
	Cryptocurrencies    string                    `json:"Cryptocurrencies,omitempty"`
	SMS                 *SMSGlobalConfig          `json:"SMSGlobal,omitempty"`
}

Config is the overarching object that holds all the information for prestart management of Portfolio, Communications, Webserver and Enabled Exchanges

func GetConfig

func GetConfig() *Config

GetConfig returns a pointer to a configuration object

func (*Config) CheckCommunicationsConfig

func (c *Config) CheckCommunicationsConfig() error

CheckCommunicationsConfig checks to see if the variables are set correctly from config.json

func (*Config) CheckConfig

func (c *Config) CheckConfig() error

CheckConfig checks all config settings

func (*Config) CheckCurrencyConfigValues

func (c *Config) CheckCurrencyConfigValues() error

CheckCurrencyConfigValues checks to see if the currency config values are correct or not

func (*Config) CheckExchangeConfigValues

func (c *Config) CheckExchangeConfigValues() error

CheckExchangeConfigValues returns configuation values for all enabled exchanges

func (*Config) CheckGrpcServerConfigValues

func (c *Config) CheckGrpcServerConfigValues() error

CheckWebserverConfigValues checks information before webserver starts and returns an error if values are incorrect.

func (*Config) CountEnabledExchanges

func (c *Config) CountEnabledExchanges() int

CountEnabledExchanges returns the number of exchanges that are enabled.

func (*Config) GetAllExchangeConfigs

func (c *Config) GetAllExchangeConfigs() []ExchangeConfig

GetAllExchangeConfigs returns all exchange configurations

func (*Config) GetAvailablePairs

func (c *Config) GetAvailablePairs(exchName string) ([]pair.CurrencyPair, error)

GetAvailablePairs returns a list of currency pairs for a specifc exchange

func (*Config) GetCommunicationsConfig

func (c *Config) GetCommunicationsConfig() CommunicationsConfig

GetCommunicationsConfig returns the communications configuration

func (*Config) GetConfigCurrencyPairFormat

func (c *Config) GetConfigCurrencyPairFormat(exchName string) (*CurrencyPairFormatConfig, error)

GetConfigCurrencyPairFormat returns the config currency pair format for a specific exchange

func (*Config) GetCurrencyConfig

func (c *Config) GetCurrencyConfig() CurrencyConfig

GetCurrencyConfig returns currency configurations

func (*Config) GetCurrencyPairDisplayConfig

func (c *Config) GetCurrencyPairDisplayConfig() *CurrencyPairFormatConfig

GetCurrencyPairDisplayConfig retrieves the currency pair display preference

func (*Config) GetDisabledExchanges

func (c *Config) GetDisabledExchanges() []string

GetDisabledExchanges returns a list of disabled exchanges

func (*Config) GetEnabledExchanges

func (c *Config) GetEnabledExchanges() []string

GetEnabledExchanges returns a list of enabled exchanges

func (*Config) GetEnabledPairs

func (c *Config) GetEnabledPairs(exchName string) ([]pair.CurrencyPair, error)

GetEnabledPairs returns a list of currency pairs for a specifc exchange

func (*Config) GetExchangeConfig

func (c *Config) GetExchangeConfig(name string) (ExchangeConfig, error)

GetExchangeConfig returns exchange configurations by its indivdual name

func (*Config) GetForexProviderConfig

func (c *Config) GetForexProviderConfig(name string) (base.Settings, error)

GetForexProviderConfig returns a forex provider configuration by its name

func (*Config) GetPrimaryForexProvider

func (c *Config) GetPrimaryForexProvider() string

GetPrimaryForexProvider returns the primary forex provider

func (*Config) GetRequestCurrencyPairFormat

func (c *Config) GetRequestCurrencyPairFormat(exchName string) (*CurrencyPairFormatConfig, error)

GetRequestCurrencyPairFormat returns the request currency pair format for a specific exchange

func (*Config) LoadConfig

func (c *Config) LoadConfig(configPath string) error

LoadConfig loads your configuration file into your configuration object

func (*Config) PromptForConfigEncryption

func (c *Config) PromptForConfigEncryption() bool

PromptForConfigEncryption asks for encryption key

func (*Config) ReadConfig

func (c *Config) ReadConfig(configPath string) error

ReadConfig verifies and checks for encryption and verifies the unencrypted file contains JSON.

func (*Config) RetrieveConfigCurrencyPairs

func (c *Config) RetrieveConfigCurrencyPairs(enabledOnly bool) error

RetrieveConfigCurrencyPairs splits, assigns and verifies enabled currency pairs either cryptoCurrencies or fiatCurrencies

func (*Config) SaveConfig

func (c *Config) SaveConfig(configPath string) error

SaveConfig saves your configuration to your desired path

func (*Config) SupportsPair

func (c *Config) SupportsPair(exchName string, p pair.CurrencyPair) (bool, error)

SupportsPair returns true or not whether the exchange supports the supplied pair

func (*Config) UpdateCommunicationsConfig

func (c *Config) UpdateCommunicationsConfig(config CommunicationsConfig)

UpdateCommunicationsConfig sets a new updated version of a Communications configuration

func (*Config) UpdateConfig

func (c *Config) UpdateConfig(configPath string, newCfg Config) error

UpdateConfig updates the config with a supplied config file

func (*Config) UpdateExchangeConfig

func (c *Config) UpdateExchangeConfig(e ExchangeConfig) error

UpdateExchangeConfig updates exchange configurations

type CurrencyConfig

type CurrencyConfig struct {
	ForexProviders      []base.Settings           `json:"ForexProviders"`
	Cryptocurrencies    string                    `json:"Cryptocurrencies"`
	CurrencyPairFormat  *CurrencyPairFormatConfig `json:"CurrencyPairFormat"`
	FiatDisplayCurrency string
}

CurrencyConfig holds all the information needed for currency related manipulation

type CurrencyPairFormatConfig

type CurrencyPairFormatConfig struct {
	Uppercase bool
	Delimiter string `json:",omitempty"`
	Separator string `json:",omitempty"`
	Index     string `json:",omitempty"`
}

CurrencyPairFormatConfig stores the users preferred currency pair display

type ExchangeConfig

type ExchangeConfig struct {
	Name                      string
	Enabled                   bool
	Verbose                   bool
	Websocket                 bool
	UseSandbox                bool
	RESTPollingDelay          time.Duration
	HTTPTimeout               time.Duration
	AuthenticatedAPISupport   bool
	APIKey                    string
	APISecret                 string
	ClientID                  string `json:",omitempty"`
	AvailablePairs            string
	EnabledPairs              string
	BaseCurrencies            string
	AssetTypes                string
	SupportsAutoPairUpdates   bool
	PairsLastUpdated          int64                     `json:",omitempty"`
	ConfigCurrencyPairFormat  *CurrencyPairFormatConfig `json:"ConfigCurrencyPairFormat"`
	RequestCurrencyPairFormat *CurrencyPairFormatConfig `json:"RequestCurrencyPairFormat"`
}

ExchangeConfig holds all the information needed for each enabled Exchange.

type GrpcServerConfig

type GrpcServerConfig struct {
	Enabled       bool
	AdminUsername string
	AdminPassword string
	ListenAddress string
}

GrpcServerConfig struct holds the prestart variables for the grpc server.

type Post

type Post struct {
	Data Config `json:"Data"`
}

Post holds the bot configuration data

type SMSContact

type SMSContact struct {
	Name    string `json:"Name"`
	Number  string `json:"Number"`
	Enabled bool   `json:"Enabled"`
}

SMSContact stores the SMS contact info

type SMSGlobalConfig

type SMSGlobalConfig struct {
	Name     string       `json:"Name"`
	Enabled  bool         `json:"Enabled"`
	Verbose  bool         `json:"Verbose"`
	Username string       `json:"Username"`
	Password string       `json:"Password"`
	Contacts []SMSContact `json:"Contacts"`
}

SMSGlobalConfig structure holds all the variables you need for instant messaging and broadcast used by SMSGlobal

type SMTPConfig

type SMTPConfig struct {
	Name            string `json:"Name"`
	Enabled         bool   `json:"Enabled"`
	Verbose         bool   `json:"Verbose"`
	Host            string `json:"Host"`
	Port            string `json:"Port"`
	AccountName     string `json:"AccountName"`
	AccountPassword string `json:"AccountPassword"`
	RecipientList   string `json:"RecipientList"`
}

SMTPConfig holds all variables to start and run the SMTP package

type SlackConfig

type SlackConfig struct {
	Name              string `json:"Name"`
	Enabled           bool   `json:"Enabled"`
	Verbose           bool   `json:"Verbose"`
	TargetChannel     string `json:"TargetChannel"`
	VerificationToken string `json:"VerificationToken"`
}

SlackConfig holds all variables to start and run the Slack package

type TelegramConfig

type TelegramConfig struct {
	Name              string `json:"Name"`
	Enabled           bool   `json:"Enabled"`
	Verbose           bool   `json:"Verbose"`
	VerificationToken string `json:"VerificationToken"`
}

TelegramConfig holds all variables to start and run the Telegram package

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL