package
0.0.0-20250311023717-5c21e974eed8
Repository: https://github.com/thrasher-corp/gocryptotrader.git
Documentation: pkg.go.dev

# 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 our GoCryptoTrader Kanban board.

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

Config package overview

This readme contains details for both the GoCryptoTrader Backtester config structure along with the strategy config structure

GoCryptoTrader Backtester Config overview

Below are the details for the GoCryptoTrader Backtester application config. Strategy config overview is below this section

KeyDescriptionExample
print-logoWhether to print the GoCryptoTrader Backtester logo on startup. Recommended because it looks goodtrue
verboseWhether to receive verbose output. If running a GRPC server, it outputs to the server, not to the clientfalse
log-subheadersWhether log output contains a descriptor of what area the log is coming from, for example STRATEGY. Helpful for debuggingtrue
stop-all-tasks-on-closeWhen closing the application, the Backtester will attempt to stop all active taskstrue
plugin-pathWhen using custom strategy plugins, you can enter the path here to automatically load the plugintrue
reportContains details on the output report after a successful backtesting runSee Report table below
grpcContains GRPC server detailsSee GRPC table below
use-cmd-coloursIf enabled, will output pretty colours of your choosing when running the applicationtrue
cmd-coloursContains details on what the colour definitions areSee Colours table below

Backtester Config Report overview

KeyDescriptionExample
output-reportWhether or not to output a report after a successful backtesting runtrue
template-pathThe path for the template to use when generating a report/backtester/report/tpl.gohtml
output-pathThe path where report output is saved/backtester/results
dark-modeWhether or not the report defaults to using dark modetrue

Backtester Config GRPC overview

KeyDescriptionExample
usernameYour username to negotiate a successful connection with the serverrpcuser
passwordYour password to negotiate a successful connection with the serverhelloImTheDefaultPassword
enabledWhether the server is enabled. Setting this to false and SingleRun to false would be inadvisabletrue
listenAddressThe listen address for the GRPC serverlocalhost:9054
grpcProxyEnabledIf enabled, creates a proxy server to interact with the GRPC server via HTTP commandstrue
grpcProxyListenAddressThe address for the proxy to listen onlocalhost:9053
tls-dirThe directory for holding your TLS certifications to make connections to the server. Will be generated by default on startup if not present/backtester/config/location/

Backtester Config Colours overview

KeyDescriptionExample
DefaultThe colour definition for default text output
GreenThe colour definition for when green is warranted, such as the logo
WhiteThe colour definition for when white is warranted such as the logo
GreyThe colour definition for grey
DarkGreyThe colour definition for dark grey
H1The colour definition for main headers
H2The colour definition for sub headers
H3The colour definition for sub sub headers
H4The colour definition for sub sub sub headers
SuccessThe colour definition for successful operations
InfoThe colour definition for when informing you of something
DebugThe colour definition for debug output such as verbose
WarnThe colour definition for when a warning occurs
ErrorThe colour definition for when an error occurs

Strategy Config 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

KeyDescription
nicknameA nickname for the specific config. When running multiple variants of the same strategy, use the nickname to help differentiate between runs
goalA description of what you would hope the outcome to be. When verifying output, you can review and confirm whether the strategy met that goal
strategy-settingsSelect 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
funding-settingsDefines whether individual funding settings can be used. Defines the funding exchange, asset, currencies at an individual level
currency-settingsCurrency settings is an array of settings for each individual currency you wish to run the strategy against
data-settingsHolds data retrieval settings. Determines how the GoCryptoTraderBacktester will fetch data and in what format
portfolio-settingsContains 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
statistic-settingsContains settings that impact statistics calculation. Such as the risk-free rate for the sharpe ratio

Strategy Settings

KeyDescriptionExample
nameThe strategy to usersi
use-simultaneous-signal-processingThis 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 BTCtrue
disable-usd-trackingIf 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 retrieve 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 datafalse
custom-settingsThis 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 }

Funding Config Settings

KeyDescriptionExample
use-exchange-level-fundingAllows 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 informationfalse
exchange-level-fundingAn array of exchange level funding settings. See below, or this for more information[]
Funding Item Config Settings
KeyDescriptionExample
exchange-nameThe exchange to set funds. See here for a list of supported exchangesBinance
assetThe asset type to set funds. Typically, this will be spot, however, see this package for the various asset types GoCryptoTrader supportsspot
currencyThe currency to set fundsBTC
initial-fundsThe initial funding for the currency1337
transfer-feeIf your strategy utilises transferring of funds via the Funding Manager, this is deducted upon doing so0.005

Currency Settings

KeyDescriptionExample
exchange-nameThe exchange to load. See here for a list of supported exchangesBinance
assetThe asset type. Typically, this will be spot, however, see this package for the various asset types GoCryptoTrader supportsspot
baseThe base of a currencyBTC
quoteThe quote of a currencyUSDT
spot-detailsAn optional field which contains initial funding data for SPOT currency pairsSee SpotSettings table below
future-detailssAn optional field which contains leverage data for FUTURES currency pairsSee FuturesSettings table below
buy-sideThis struct defines the buying side rules this specific currency setting must abide by such as maximum purchase amount--
sell-sideThis struct defines the selling side rules this specific currency setting must abide by such as maximum selling amount--
min-slippage-percentIs 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
max-slippage-percentIs 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 events100
maker-fee-overrideThe fee to use when sizing and purchasing currency. If nil, will lookup an exchange's fee details0.001
taker-fee-overrideUnused fee for when an order is placed in the orderbook, rather than taken from the orderbook. If nil, will lookup an exchange's fee details0.002
maximum-holdings-ratioWhen multiple currency settings are used, you may set a maximum holdings ratio to prevent having too large a stake in a single currency0.5
skip-candle-volume-fittingWhen 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 prescribesfalse
use-exchange-order-limitsWill 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 livefalse
use-exchange-pnl-calculationInstead of simulating the exchange's own way of calculating PNL, use a default method which calculates the value of an assetfalse
SpotSettings
KeyDescriptionExample
initial-base-fundsThe funds that the GoCryptoTraderBacktester has for the base currency. This is only required if the strategy setting UseExchangeLevelFunding is false2
initial-quote-fundsThe funds that the GoCryptoTraderBacktester has for the quote currency. This is only required if the strategy setting UseExchangeLevelFunding is false10000
FuturesSettings
KeyDescriptionExample
leverageThis struct defines the leverage rules that this specific currency setting must abide by1

DataSettings

KeyDescriptionExample
intervalThe candle interval in time.Duration format eg set as15000000000 for a value of time.Second * 1515000000000
data-typeChoose whether candle or trade data is used. If trades are used, they will be converted to candlestrade
verbose-exchange-requestsWhen retrieving candle data from an exchange, print verbose request/response detailsfalse
api-dataHolds API data settings. See table APIData
database-dataHolds database data settings. See table DatabaseData
live-dataHolds API data settings. See table LiveData
csv-dataHolds CSV data settings. See table CSVData

APIData

KeyDescriptionExample
start-dateThe start date to retrieve data2021-01-23T11:00:00+11:00
end-dateThe end date to retrieve data2021-01-24T11:00:00+11:00
inclusive-end-dateWhen 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:00false

CSVData

KeyDescriptionExample
full-pathThe file to load/data/exchangelist.csv

DatabaseData

KeyDescriptionExample
start-dateThe start date to retrieve data2021-01-23T11:00:00+11:00
end-dateThe end date to retrieve data2021-01-24T11:00:00+11:00
configThis is the same struct used as your GoCryptoTrader database config. See below tables for breakdownsee below
pathIf using SQLite, the path to the directory, not the file. Leaving blank will use GoCryptoTrader's default database path``
inclusive-end-dateWhen 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:00false
database
ConfigDescriptionExample
enabledEnabled or disables the database connection subsystemtrue
verboseDisplays more information to the logger which can be helpful for debuggingfalse
driverThe SQL driver to use. Can be postgres or sqlitesqlite
connectionDetailsSee below
connectionDetails
ConfigDescriptionExample
hostThe host address of the databaselocalhost
portThe port used to connect to the database5432
usernameAn optional username to connect to the databaseusername
passwordAn optional password to connect to the databasepassword
databaseThe name of the databasedatabase.db
sslmodeThe connection type of the database for Postgres databases onlydisable

LiveData

KeyDescriptionExample
new-event-timeoutThe time allowed to wait for new data before exiting the strategy. Ensures new data is always coming in60000000000
data-check-timerThe interval in which to check exchange API's for new data1000000000
real-ordersWhether to place real orders with real money. Its likely you should never want to set this to truefalse
close-positions-on-stopAs live trading doesn't stop until you tell it to, you can trigger a close of your position(s) when you stop the strategytrue
data-request-retry-toleranceRather than immediately closing a strategy on failure to retrieve candle data, having a retry tolerance allows multiple attempts to return data3
data-request-retry-wait-timeHow long to wait in between request retries500000000
exchange-credentialsA list of exchange credentials. See table named ExchangeCredentials
ExchangeCredentials Settings
KeyDescriptionExample
exchangeThe exchange to apply credentials tobinance
credentialsThe API credentials to use. See table named Credentials
Credentials Settings
KeyDescriptionExample
KeyWill set the GoCryptoTrader exchange to use the following API Key1234
SecretWill set the GoCryptoTrader exchange to use the following API Secret5678
ClientIDWill set the GoCryptoTrader exchange to use the following API Client ID9012
PEMKeyPrivate key for certain API requests. If you don't know it, you probably don't need ithello-moto
SubAccountWill set the GoCryptoTrader exchange to use the following subaccount on supported exchangessubzero
OneTimePasswordWill set the GoCryptoTrader exchange to use the following 2FA seedsubzero

PortfolioSettings

KeyDescription
leverageThis struct defines the leverage rules that this specific currency setting must abide by
buy-sideThis struct defines the buying side rules this specific currency setting must abide by such as maximum purchase amount
sell-sideThis struct defines the selling side rules this specific currency setting must abide by such as maximum selling amount
Leverage Settings
KeyDescriptionExample
can-use-leverageAllows the use of leveragefalse
maximum-orders-with-leverage-ratiocurrently unused0.5
maximum-leverage-ratecurrently unused100
maximum-collateral-leverage-ratecurrently unused100
Buy/Sell Settings
KeyDescriptionExample
minimum-sizeIf the order's quantity is below this, the order cannot be placed0.1
maximum-sizeIf the order's quantity is over this amount, it cannot be placed and will be reduced to the maximum amount10
maximum-totalIf the order's price * amount exceeds this number, the order cannot be placed and will be reduced to this figure1337

StatisticsSettings

KeyDescriptionExample
risk-free-rateThe risk free rate used in the calculation of sharpe and sortino ratios0.03

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

# Packages

# Functions

GenerateDefaultConfig will return the default backtester config.
ReadBacktesterConfigFromPath will take a config from a path.
ReadStrategyConfigFromFile will take a config from a path.

# Variables

DefaultBTConfigDir is the default backtester config file.
DefaultBTDir is the default backtester config directory.

# Structs

APIData defines all fields to configure API based data.
BacktesterConfig contains the configuration for the backtester.
Config defines what is in an individual strategy config.
Credentials holds each exchanges credentials.
CSVData defines all fields to configure CSV based data.
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.
DatabaseData defines all fields to configure database based data.
DataSettings is a container for each type of data retrieval setting.
ExchangeLevelFunding allows the portfolio manager to access a shared pool.
FundingSettings contains funding details for individual currencies.
FuturesDetails contains data relevant to futures currency pairs.
GRPC holds the GRPC configuration.
Leverage rules are used to allow or limit the use of leverage in orders when supported.
LiveData defines all fields to configure live data.
MinMax are the rules which limit the placement of orders.
PortfolioSettings act as a global protector for strategies these settings will override ExchangeSettings that go against it and assess the bigger picture.
Report contains the report settings.
SpotDetails contains funding information that cannot be shared with another pair during the backtesting run.
StatisticSettings adjusts ratios where proper data is currently lacking.
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.