config

package
v0.0.0-...-c17c338 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2021 License: MIT Imports: 13 Imported by: 0

README

GoCryptoTrader Backtester: Config package

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 progress on this Trello board: https://trello.com/b/ZAhMhpOy/gocryptotrader.

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

Config package overview

What does the config package do?

The config package contains a set of structs which allow for the customisation of the GoCryptoTrader Backtester when running. The GoCryptoTrader Backtester runs from reading config files (.strat files by default under /examples).

What does Simultaneous Processing mean?

GoCryptoTrader Backtester config files may contain multiple ExchangeSettings which defined exchange, asset and currency pairs to iterate through a period of time.

If there are multiple entries to ExchangeSettings and SimultaneousProcessing is disabled, then each individual exchange, asset and currency pair candle event is evaluated individually and does not know about other exchange, asset and currency pair data events. It is a way to test a singular strategy against multiple assets simultaneously. But it isn't defined as Simultaneous Processing Simultaneous Signal Processing is a setting which allows multiple ExchangeSettings data events for a candle event to be considered simultaneously. This means that you can check if the price of BTC-USDT is 5% greater on Binance than it is on Kraken and choose to make signal a BUY event for Kraken and not Binance.

It allows for complex strategical decisions to be made when you consider the scope of the entire market at a given time, rather than in a vacuum when SimultaneousSignalProcessing is disabled.

How do I customise the GoCryptoTrader Backtester?

See below for a set of tables and fields, expected values and what they can do

Config
Key Description
Nickname A nickname for the specific config. When running multiple variants of the same strategy, use the nickname to help differentiate between runs
Goal A description of what you would hope the outcome to be. When verifying output, you can review and confirm whether the strategy met that goal
CurrencySettings Currency settings is an array of settings for each individual currency you wish to run the strategy against
StrategySettings Select which strategy to run, what custom settings to load and whether the strategy can assess multiple currencies at once to make more in-depth decisions
PortfolioSettings Contains a list of global rules for the portfolio manager. CurrencySettings contain their own rules on things like how big a position is allowable, the portfolio manager rules are the same, but override any individual currency's settings
StatisticSettings Contains settings that impact statistics calculation. Such as the risk-free rate for the sharpe ratio
GoCryptoTraderConfigPath The filepath for the location of GoCryptoTrader's config path. The Backtester utilises settings from GoCryptoTrader. If unset, will utilise the default filepath via config.DefaultFilePath, implemented here
Strategy Settings
Key Description Example
Name The strategy to use rsi
UsesSimultaneousProcessing This denotes whether multiple currencies are processed simultaneously with the strategy function OnSimultaneousSignals. Eg If you have multiple CurrencySettings and only wish to purchase BTC-USDT when XRP-DOGE is 1337, this setting is useful as you can analyse both signal events to output a purchase call for BTC true
CustomSettings This is a map where you can enter custom settings for a strategy. The RSI strategy allows for customisation of the upper, lower and length variables to allow you to change them from 70, 30 and 14 respectively to 69, 36, 12 "custom-settings": { "rsi-high": 70, "rsi-low": 30, "rsi-period": 14 }
UseExchangeLevelFunding Allows shared funding at an exchange asset level. You can set funding for USDT and all pairs that feature USDT will have access to those funds when making orders. See this for more information false
ExchangeLevelFunding An array of exchange level funding settings. See below, or this for more information []
DisableUSDTracking If false, will track all currencies used in your strategy against USD equivalent candles. For example, if you are running a strategy for BTC/XRP, then the GoCryptoTrader Backtester will also retreive candles data for BTC/USD and XRP/USD to then track strategy performance against a single currency. This also tracks against USDT and other USD tracked stablecoins, so one exchange supporting USDT and another BUSD will still allow unified strategy performance analysis. If disabled, will not track against USD, this can be especially helpful when running strategies under live, database and CSV based data false
Funding Config Settings
Key Description Example
ExchangeName The exchange to set funds. See here for a list of supported exchanges Binance
Asset The asset type to set funds. Typically, this will be spot, however, see this package for the various asset types GoCryptoTrader supports spot
Currency The currency to set funds BTC
InitialFunds The initial funding for the currency 1337
TransferFee If your strategy utilises transferring of funds via the Funding Manager, this is deducted upon doing so 0.005
Currency Settings
Key Description Example
ExchangeName The exchange to load. See here for a list of supported exchanges Binance
Asset The asset type. Typically, this will be spot, however, see this package for the various asset types GoCryptoTrader supports spot
Base The base of a currency BTC
Quote The quote of a currency USDT
InitialFunds A legacy field, will be temporarily migrated to InitialQuoteFunds if present in your strat config ``
InitialBaseFunds The funds that the GoCryptoTraderBacktester has for the base currency. This is only required if the strategy setting UseExchangeLevelFunding is false 2
InitialQuoteFunds The funds that the GoCryptoTraderBacktester has for the quote currency. This is only required if the strategy setting UseExchangeLevelFunding is false 10000
Leverage This struct defines the leverage rules that this specific currency setting must abide by 1
BuySide This struct defines the buying side rules this specific currency setting must abide by such as maximum purchase amount -
SellSide This struct defines the selling side rules this specific currency setting must abide by such as maximum selling amount -
MinimumSlippagePercent Is the lower bounds in a random number generated that make purchases more expensive, or sell events less valuable. If this value is 90, then the most a price can be affected is 10% 90
MaximumSlippagePercent Is the upper bounds in a random number generated that make purchases more expensive, or sell events less valuable. If this value is 99, then the least a price can be affected is 1%. Set both upper and lower to 100 to have no randomness applied to purchase events 100
MakerFee The fee to use when sizing and purchasing currency 0.001
TakerFee Unused fee for when an order is placed in the orderbook, rather than taken from the orderbook 0.002
MaximumHoldingsRatio When multiple currency settings are used, you may set a maximum holdings ratio to prevent having too large a stake in a single currency 0.5
CanUseExchangeLimits Will lookup exchange rules around purchase sizing eg minimum order increments of 0.0005. Note: Will retrieve up-to-date rules which may not have existed for the data you are using. Best to use this when considering to use this strategy live false
SkipCandleVolumeFitting When placing orders, by default the BackTester will shrink an order's size to fit the candle data's volume so as to not rewrite history. Set this to true to ignore this and to set order size at what the portfolio manager prescribes false
PortfolioSettings
Key Description
Leverage This struct defines the leverage rules that this specific currency setting must abide by
BuySide This struct defines the buying side rules this specific currency setting must abide by such as maximum purchase amount
SellSide This struct defines the selling side rules this specific currency setting must abide by such as maximum selling amount
StatisticsSettings
Key Description Example
RiskFreeRate The risk free rate used in the calculation of sharpe and sortino ratios 0.03
APIData
Key Description Example
DataType Choose whether candle or trade data is used. If trades are used, they will be converted to candles trade
Interval The candle interval in time.Duration format eg set as15000000000 for a value of time.Second * 15 15000000000
StartDate The start date to retrieve data 2021-01-23T11:00:00+11:00
EndDate The end date to retrieve data 2021-01-24T11:00:00+11:00
InclusiveEndDate When enabled, the end date's candle is included in the results. ie 2021-01-24T11:00:00+11:00 with a one hour candle, the final candle will be 2021-01-24T11:00:00+11:00 to 2021-01-24T12:00:00+11:00 false
CSVData
Key Description Example
DataType Choose whether candle or trade data is used. If trades are used, they will be converted to candles candle
Interval The candle interval in time.Duration format eg set as15000000000 for a value of time.Second * 15 15000000000
FullPath The file to load /data/exchangelist.csv
DatabaseData
Key Description Example
DataType Choose whether candle or trade data is used. If trades are used, they will be converted to candles trade
Interval The candle interval in time.Duration format eg set as15000000000 for a value of time.Second * 15 15000000000
StartDate The start date to retrieve data 2021-01-23T11:00:00+11:00
EndDate The end date to retrieve data 2021-01-24T11:00:00+11:00
Config This is the same struct used as your GoCryptoTrader database config. See below tables for breakdown see below
Path If using SQLite, the path to the directory, not the file. Leaving blank will use GoCryptoTrader's default database path ``
InclusiveEndDate When enabled, the end date's candle is included in the results. ie 2021-01-24T11:00:00+11:00 with a one hour candle, the final candle will be 2021-01-24T11:00:00+11:00 to 2021-01-24T12:00:00+11:00 false
database
Config Description Example
enabled Enabled or disables the database connection subsystem true
verbose Displays more information to the logger which can be helpful for debugging false
driver The SQL driver to use. Can be postgres or sqlite sqlite
connectionDetails See below
connectionDetails
Config Description Example
host The host address of the database localhost
port The port used to connect to the database 5432
username An optional username to connect to the database username
password An optional password to connect to the database password
database The name of the database database.db
sslmode The connection type of the database for Postgres databases only disable
LiveData
Key Description Example
DataType Choose whether candle or trade data is used. If trades are used, they will be converted to candles candle
Interval The candle interval in time.Duration format eg set as15000000000 for a value of time.Second * 15 15000000000
APIKeyOverride Will set the GoCryptoTrader exchange to use the following API Key 1234
APISecretOverride Will set the GoCryptoTrader exchange to use the following API Secret 5678
APIClientIDOverride Will set the GoCryptoTrader exchange to use the following API Client ID 9012
API2FAOverride Will set the GoCryptoTrader exchange to use the following 2FA seed hello-moto
APISubaccountOverride Will set the GoCryptoTrader exchange to use the following subaccount on supported exchanges subzero
RealOrders Whether to place real orders. You really should never consider using this. Ever ever true
Leverage Settings
Key Description Example
CanUseLeverage Allows the use of leverage false
MaximumOrdersWithLeverageRatio If the ratio of leveraged orders for a currency exceeds this, the order cannot be placed 0.5
MaximumLeverageRate Orders cannot be placed with leverage over this amount 100
Buy/Sell Settings
Key Description Example
MinimumSize If the order's quantity is below this, the order cannot be placed 0.1
MaximumSize If the order's quantity is over this amount, it cannot be placed and will be reduced to the maximum amount 10
MaximumTotal If the order's price * amount exceeds this number, the order cannot be placed and will be reduced to this figure 1337
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:

bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIData

type APIData struct {
	StartDate        time.Time `json:"start-date"`
	EndDate          time.Time `json:"end-date"`
	InclusiveEndDate bool      `json:"inclusive-end-date"`
}

APIData defines all fields to configure API based data

type CSVData

type CSVData struct {
	FullPath string `json:"full-path"`
}

CSVData defines all fields to configure CSV based data

type Config

type Config struct {
	Nickname          string             `json:"nickname"`
	Goal              string             `json:"goal"`
	StrategySettings  StrategySettings   `json:"strategy-settings"`
	CurrencySettings  []CurrencySettings `json:"currency-settings"`
	DataSettings      DataSettings       `json:"data-settings"`
	PortfolioSettings PortfolioSettings  `json:"portfolio-settings"`
	StatisticSettings StatisticSettings  `json:"statistic-settings"`
}

Config defines what is in an individual strategy config

func LoadConfig

func LoadConfig(data []byte) (resp *Config, err error)

LoadConfig unmarshalls byte data into a config struct

func ReadConfigFromFile

func ReadConfigFromFile(path string) (*Config, error)

ReadConfigFromFile will take a config from a path

func (*Config) PrintSetting

func (c *Config) PrintSetting()

PrintSetting prints relevant settings to the console for easy reading

func (*Config) Validate

func (c *Config) Validate() error

Validate checks all config settings

type CurrencySettings

type CurrencySettings struct {
	ExchangeName string `json:"exchange-name"`
	Asset        string `json:"asset"`
	Base         string `json:"base"`
	Quote        string `json:"quote"`
	// USDTrackingPair is used for price tracking data only
	USDTrackingPair bool `json:"-"`

	InitialBaseFunds   *decimal.Decimal `json:"initial-base-funds,omitempty"`
	InitialQuoteFunds  *decimal.Decimal `json:"initial-quote-funds,omitempty"`
	InitialLegacyFunds float64          `json:"initial-funds,omitempty"`

	Leverage Leverage `json:"leverage"`
	BuySide  MinMax   `json:"buy-side"`
	SellSide MinMax   `json:"sell-side"`

	MinimumSlippagePercent decimal.Decimal `json:"min-slippage-percent"`
	MaximumSlippagePercent decimal.Decimal `json:"max-slippage-percent"`

	MakerFee decimal.Decimal `json:"maker-fee-override"`
	TakerFee decimal.Decimal `json:"taker-fee-override"`

	MaximumHoldingsRatio decimal.Decimal `json:"maximum-holdings-ratio"`

	CanUseExchangeLimits          bool `json:"use-exchange-order-limits"`
	SkipCandleVolumeFitting       bool `json:"skip-candle-volume-fitting"`
	ShowExchangeOrderLimitWarning bool `json:"-"`
}

CurrencySettings stores pair based variables It contains rules about the specific currency pair you wish to trade with Backtester will load the data of the currencies specified here

type DataSettings

type DataSettings struct {
	Interval     time.Duration `json:"interval"`
	DataType     string        `json:"data-type"`
	APIData      *APIData      `json:"api-data,omitempty"`
	DatabaseData *DatabaseData `json:"database-data,omitempty"`
	LiveData     *LiveData     `json:"live-data,omitempty"`
	CSVData      *CSVData      `json:"csv-data,omitempty"`
}

DataSettings is a container for each type of data retrieval setting. Only ONE can be populated per config

type DatabaseData

type DatabaseData struct {
	StartDate        time.Time       `json:"start-date"`
	EndDate          time.Time       `json:"end-date"`
	Config           database.Config `json:"config"`
	Path             string          `json:"path"`
	InclusiveEndDate bool            `json:"inclusive-end-date"`
}

DatabaseData defines all fields to configure database based data

type ExchangeLevelFunding

type ExchangeLevelFunding struct {
	ExchangeName string          `json:"exchange-name"`
	Asset        string          `json:"asset"`
	Currency     string          `json:"currency"`
	InitialFunds decimal.Decimal `json:"initial-funds"`
	TransferFee  decimal.Decimal `json:"transfer-fee"`
}

ExchangeLevelFunding allows the portfolio manager to access a shared pool. For example, The base currencies BTC and LTC can both access the same USDT funding to make purchasing decisions Similarly, when a BTC is sold, LTC can now utilise the increased funding Importantly, exchange level funding is all-inclusive, you cannot have it for only some uses It also is required to use SimultaneousSignalProcessing, otherwise the first currency processed will have dibs

type Leverage

type Leverage struct {
	CanUseLeverage                 bool            `json:"can-use-leverage"`
	MaximumOrdersWithLeverageRatio decimal.Decimal `json:"maximum-orders-with-leverage-ratio"`
	MaximumLeverageRate            decimal.Decimal `json:"maximum-leverage-rate"`
}

Leverage rules are used to allow or limit the use of leverage in orders when supported

type LiveData

type LiveData struct {
	APIKeyOverride        string `json:"api-key-override"`
	APISecretOverride     string `json:"api-secret-override"`
	APIClientIDOverride   string `json:"api-client-id-override"`
	API2FAOverride        string `json:"api-2fa-override"`
	APISubAccountOverride string `json:"api-sub-account-override"`
	RealOrders            bool   `json:"real-orders"`
}

LiveData defines all fields to configure live data

type MinMax

type MinMax struct {
	MinimumSize  decimal.Decimal `json:"minimum-size"` // will not place an order if under this amount
	MaximumSize  decimal.Decimal `json:"maximum-size"` // can only place an order up to this amount
	MaximumTotal decimal.Decimal `json:"maximum-total"`
}

MinMax are the rules which limit the placement of orders.

type PortfolioSettings

type PortfolioSettings struct {
	Leverage Leverage `json:"leverage"`
	BuySide  MinMax   `json:"buy-side"`
	SellSide MinMax   `json:"sell-side"`
}

PortfolioSettings act as a global protector for strategies these settings will override ExchangeSettings that go against it and assess the bigger picture

type StatisticSettings

type StatisticSettings struct {
	RiskFreeRate decimal.Decimal `json:"risk-free-rate"`
}

StatisticSettings adjusts ratios where proper data is currently lacking

type StrategySettings

type StrategySettings struct {
	Name                         string                 `json:"name"`
	SimultaneousSignalProcessing bool                   `json:"use-simultaneous-signal-processing"`
	UseExchangeLevelFunding      bool                   `json:"use-exchange-level-funding"`
	ExchangeLevelFunding         []ExchangeLevelFunding `json:"exchange-level-funding,omitempty"`
	// If true, won't track USD values against currency pair
	// bool language is opposite to encourage use by default
	DisableUSDTracking bool                   `json:"disable-usd-tracking"`
	CustomSettings     map[string]interface{} `json:"custom-settings,omitempty"`
}

StrategySettings contains what strategy to load, along with custom settings map (variables defined per strategy) along with defining whether the strategy will assess all currencies at once, or individually

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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