Backtester: Live trading upgrades (#1023)

* Modifications for a smoother live run

* Fixes data appending

* Successfully allows multi-currency live trading. Adds multiple currencies to live DCA strategy

* Attempting to get cash and carry working

* Poor attempts at sorting out data and appending it properly with USD in mind

* =designs new live data handler

* Updates cash and carry strat to work

* adds test coverage. begins closeallpositions function

* Updates cash and carry to work live

* New kline.Event type. Cancels orders on close. Rn types

* =Fixes USD funding issue

* =fixes tests

* fixes tests AGAIN

* adds coverage to close all orders

* crummy tests, should override

* more tests

* more tests

* more coverage

* removes scourge of currency.Pair maps. More tests

* missed currency stuff

* Fixes USD data issue & collateral issue. Needs to close ALL orders

* Now triggers updates on the very first data entry

* All my problems are solved now????

* fixes tests, extends coverage

* there is some really funky candle stuff going on

* my brain is melting

* better shutdown management, fixes freezing bug

* fixes data duplication issues, adds retries to requests

* reduces logging, adds verbose options

* expands coverage over all new functionality

* fixes fun bug from curr == curr to curr.Equal(curr)

* fixes setup issues and tests

* starts adding external wallet amounts for funding

* more setup for assets

* setup live fund calcs and placing orders

* successfully performs automated cash and carry

* merge fixes

* funding properly set at all times

* fixes some bugs, need to address currencystatistics still

* adds 'appeneded' trait, attempts to fix some stats

* fixes stat bugs, adds cool new fetchfees feature

* fixes terrible processing bugs

* tightens realorder stats, sadly loses some live stats

* this actually sets everything correctly for bothcd ..cd ..cd ..cd ..cd ..!

* fix tests

* coverage

* beautiful new test coverage

* docs

* adds new fee getter delayer

* commits from the correct directory

* Lint

* adds verbose to fund manager

* Fix bug in t2b2 strat. Update dca live config. Docs

* go mod tidy

* update buf

* buf + test improvement

* Post merge fixes

* fixes surprise offset bug

* fix sizing restrictions for cash and carry

* fix server lints

* merge fixes

* test fixesss

* lintle fixles

* slowloris

* rn run to task, bug fixes, close all on close

* rpc lint and fixes

* bugfix: order manager not processing orders properly

* somewhat addresses nits

* absolutely broken end of day commit

* absolutely massive knockon effects from nits

* massive knockon effects continue

* fixes things

* address remaining nits

* jk now fixes things

* addresses the easier nits

* more nit fixers

* more niterinos addressederinos

* refactors holdings and does some nits

* so buf

* addresses some nits, fixes holdings bugs

* cleanup

* attempts to fix alert chans to prevent many chans waiting?

* terrible code, will revert

* to be reviewed in detail tomorrow

* Fixes up channel system

* smashes those nits

* fixes extra candles, fixes collateral bug, tests

* fixes data races, introduces reflection

* more checks n tests

* Fixes cash and carry issues. Fixes more cool bugs

* fixes ~typer~ typo

* replace spot strats from ftx to binance

* fixes all the tests I just destroyed

* removes example path, rm verbose

* 1) what 2) removes FTX references from the Backtester

* renamed, non-working strategies

* Removes FTX references almost as fast as sbf removes funds

* regen docs, add contrib names,sort contrib names

* fixes merge renamings

* Addresses nits. Fixes setting API credentials. Fixes Binance limit retrieval

* Fixes live order bugs with real orders and without

* Apply suggestions from code review

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>

* Update backtester/engine/live.go

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>

* Update backtester/engine/live.go

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>

* Update backtester/config/strategyconfigbuilder/main.go

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>

* updates docs

* even better docs

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
Scott
2023-01-05 13:03:17 +11:00
committed by GitHub
parent d92ffe6e9e
commit 017cdf1384
195 changed files with 13783 additions and 8048 deletions

View File

@@ -1,4 +1,4 @@
{{define "backtester config examples" -}}
{{define "backtester config strategyexamples" -}}
{{template "backtester-header" .}}
## {{.CapitalName}} package overview
@@ -16,7 +16,8 @@
| dca-database-candles.strat | The same DCA strategy, but uses a database to retrieve candle data |
| rsi-api-candles.strat | Runs a strategy using rsi figures to make buy or sell orders based on market figures |
| t2b2-api-candles-exchange-funding.strat | Runs a more complex strategy using simultaneous signal processing, exchange level funding and MFI values to make buy or sell signals based on the two strongest and weakest MFI values |
| ftx-cash-carry.strat | Executes a cash and carry trade on FTX, buying BTC-USD while shorting the long dated futures contract BTC-20210924 |
| binance-cash-and-carry.strat | Executes a cash and carry trade on Binance, buying BTC-USD while shorting the long dated futures contract. Is not currently implemented |
| binance-live-cash-and-carry.strat | Executes a cash and carry trade on Binance using realtime 15 second candles, buying BTC-USD while shorting the long dated futures contract. Is not currently implemented |
### Want to make your own configs?
Use the provided config builder under `/backtester/config/configbuilder` or modify tests under `/backtester/config/config_test.go` to generates strategy files quickly

View File

@@ -1,42 +1,43 @@
{{define "backtester config" -}}
{{template "backtester-header" .}}
## {{.CapitalName}} package overview
This readme contains details for both the GoCryptoTrader Backtester config structure along with the strategy config structure
## Backtester Config overview
## GoCryptoTrader Backtester Config overview
Below are the details for the GoCryptoTrader Backtester _application_ config. Strategy config overview is below this section
| Key | Description | Example |
|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------|
| PrintLogo | Whether to print the GoCryptoTrader Backtester logo on startup. Recommended because it looks good | `true` |
| Verbose | Whether to receive verbose output. If running a GRPC server, it outputs to the server, not to the client | `false` |
| LogSubheaders | Whether log output contains a descriptor of what area the log is coming from, for example `STRATEGY`. Helpful for debugging | `true` |
| SingleRun | Whether or not to run the GoCryptoTrader Backtester to read the `SingleRunStrategyConfig` strategy and exit afterwards. If false, will run a GRPC server | `false` |
| SingleRunStrategyConfig | The path to the strategy to run when `SingleRun` is `true` | `path\to\strategy\example.strat` |
| Report | Contains details on the output report after a successful backtesting run | See Report table below |
| GRPC | Contains GRPC server details | See GRPC table below |
| UseCMDColours | If enabled, will output pretty colours of your choosing when running the application | `true` |
| Colours | Contains details on what the colour definitions are | See Colours table below |
| print-logo | Whether to print the GoCryptoTrader Backtester logo on startup. Recommended because it looks good | `true` |
| verbose | Whether to receive verbose output. If running a GRPC server, it outputs to the server, not to the client | `false` |
| log-subheaders | Whether log output contains a descriptor of what area the log is coming from, for example `STRATEGY`. Helpful for debugging | `true` |
| stop-all-tasks-on-close | When closing the application, the Backtester will attempt to stop all active tasks | `true` |
| plugin-path | When using custom strategy plugins, you can enter the path here to automatically load the plugin | `true` |
| report | Contains details on the output report after a successful backtesting run | See Report table below |
| grpc | Contains GRPC server details | See GRPC table below |
| use-cmd-colours | If enabled, will output pretty colours of your choosing when running the application | `true` |
| cmd-colours | Contains details on what the colour definitions are | See Colours table below |
### Backtester Config Report overview
| Key | Description | Example |
|----------------|----------------------------------------------------------------------|---------------------------------|
| GenerateReport | Whether or not to output a report after a successful backtesting run | `true` |
| TemplatePath | The path for the template to use when generating a report | `/backtester/report/tpl.gohtml` |
| OutputPath | The path where report output is saved | `/backtester/results` |
| DarkMode | Whether or not the report defaults to using dark mode | `true` |
| output-report | Whether or not to output a report after a successful backtesting run | `true` |
| template-path | The path for the template to use when generating a report | `/backtester/report/tpl.gohtml` |
| output-path | The path where report output is saved | `/backtester/results` |
| dark-mode | Whether or not the report defaults to using dark mode | `true` |
### Backtester Config GRPC overview
| Key | Description | Example |
|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------|
| Username | Your username to negotiate a successful connection with the server | `rpcuser` |
| Password | Your password to negotiate a successful connection with the server | `helloImTheDefaultPassword` |
| Enabled | Whether the server is enabled. Setting this to `false` and `SingleRun` to `false` would be inadvisable | `true` |
| ListenAddress | The listen address for the GRPC server | `localhost:42069` |
| GRPCProxyEnabled | If enabled, creates a proxy server to interact with the GRPC server via HTTP commands | `true` |
| GRPCProxyListenAddress | The address for the proxy to listen on | `localhost:9053` |
| TLSDir | The 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/` |
| username | Your username to negotiate a successful connection with the server | `rpcuser` |
| password | Your password to negotiate a successful connection with the server | `helloImTheDefaultPassword` |
| enabled | Whether the server is enabled. Setting this to `false` and `SingleRun` to `false` would be inadvisable | `true` |
| listenAddress | The listen address for the GRPC server | `localhost:9054` |
| grpcProxyEnabled | If enabled, creates a proxy server to interact with the GRPC server via HTTP commands | `true` |
| grpcProxyListenAddress | The address for the proxy to listen on | `localhost:9053` |
| tls-dir | The 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
@@ -79,123 +80,111 @@ 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 |
| FundingSettings | Defines whether individual funding settings can be used. Defines the funding exchange, asset, currencies at an individual level |
| 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 |
| 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 |
| strategy-settings | 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 |
| funding-settings | Defines whether individual funding settings can be used. Defines the funding exchange, asset, currencies at an individual level |
| currency-settings | Currency settings is an array of settings for each individual currency you wish to run the strategy against |
| data-settings | Holds data retrieval settings. Determines how the GoCryptoTraderBacktester will fetch data and in what format |
| portfolio-settings | 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 |
| statistic-settings | Contains settings that impact statistics calculation. Such as the risk-free rate for the sharpe ratio |
#### 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 } ` |
| 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` |
| Key | Description | Example |
|------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------|
| name | The strategy to use | `rsi` |
| use-simultaneous-signal-processing | 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` |
| disable-usd-tracking | 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` |
| custom-settings | 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 } ` |
#### Funding Config Settings
| Key | Description | Example |
|-------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|
| 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](/backtester/funding/README.md) for more information | `false` |
| ExchangeLevelFunding | An array of exchange level funding settings. See below, or [this](/backtester/funding/README.md) for more information | `[]` |
| Key | Description | Example |
|----------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|
| use-exchange-level-funding | 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](/backtester/funding/README.md) for more information | `false` |
| exchange-level-funding | An array of exchange level funding settings. See below, or [this](/backtester/funding/README.md) for more information | `[]` |
##### Funding Item Config Settings
| Key | Description | Example |
|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------|
| ExchangeName | The exchange to set funds. See [here](https://github.com/thrasher-corp/gocryptotrader/blob/master/README.md) for a list of supported exchanges | `Binance` |
| Asset | The asset type to set funds. Typically, this will be `spot`, however, see [this package](https://github.com/thrasher-corp/gocryptotrader/blob/master/exchanges/asset/asset.go) 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` |
| Key | Description | Example |
|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------|
| exchange-name | The exchange to set funds. See [here](https://github.com/thrasher-corp/gocryptotrader/blob/master/README.md) for a list of supported exchanges | `Binance` |
| asset | The asset type to set funds. Typically, this will be `spot`, however, see [this package](https://github.com/thrasher-corp/gocryptotrader/blob/master/exchanges/asset/asset.go) for the various asset types GoCryptoTrader supports | `spot` |
| currency | The currency to set funds | `BTC` |
| initial-funds | The initial funding for the currency | `1337` |
| transfer-fee | 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](https://github.com/thrasher-corp/gocryptotrader/blob/master/README.md) for a list of supported exchanges | `Binance` |
| Asset | The asset type. Typically, this will be `spot`, however, see [this package](https://github.com/thrasher-corp/gocryptotrader/blob/master/exchanges/asset/asset.go) 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 | `` |
| 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. If `nil`, will lookup an exchange's fee details | `0.001` |
| TakerFee | Unused fee for when an order is placed in the orderbook, rather than taken from the orderbook. If `nil`, will lookup an exchange's fee details | `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` |
| SpotSettings | An optional field which contains initial funding data for SPOT currency pairs | See SpotSettings table below |
| FuturesSettings | An optional field which contains leverage data for FUTURES currency pairs | See FuturesSettings table below |
| Key | Description | Example |
|------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------|
| exchange-name | The exchange to load. See [here](https://github.com/thrasher-corp/gocryptotrader/blob/master/README.md) for a list of supported exchanges | `Binance` |
| asset | The asset type. Typically, this will be `spot`, however, see [this package](https://github.com/thrasher-corp/gocryptotrader/blob/master/exchanges/asset/asset.go) for the various asset types GoCryptoTrader supports | `spot` |
| base | The base of a currency | `BTC` |
| quote | The quote of a currency | `USDT` |
| spot-details | An optional field which contains initial funding data for SPOT currency pairs | See SpotSettings table below |
| future-detailss | An optional field which contains leverage data for FUTURES currency pairs | See FuturesSettings table below |
| buy-side | This struct defines the buying side rules this specific currency setting must abide by such as maximum purchase amount |-- |
| sell-side | This struct defines the selling side rules this specific currency setting must abide by such as maximum selling amount |-- |
| min-slippage-percent | 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` |
| max-slippage-percent | 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` |
| maker-fee-override | The fee to use when sizing and purchasing currency. If `nil`, will lookup an exchange's fee details | `0.001` |
| taker-fee-override | Unused fee for when an order is placed in the orderbook, rather than taken from the orderbook. If `nil`, will lookup an exchange's fee details | `0.002` |
| maximum-holdings-ratio | 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` |
| skip-candle-volume-fitting | 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` |
| use-exchange-order-limits | 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` |
| use-exchange-pnl-calculation | Instead of simulating the exchange's own way of calculating PNL, use a default method which calculates the value of an asset | `false` |
##### SpotSettings
| Key | Description | Example |
|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|
| 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` |
| Key | Description | Example |
|---------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|
| initial-base-funds | The funds that the GoCryptoTraderBacktester has for the base currency. This is only required if the strategy setting `UseExchangeLevelFunding` is `false` | `2` |
| initial-quote-funds | The funds that the GoCryptoTraderBacktester has for the quote currency. This is only required if the strategy setting `UseExchangeLevelFunding` is `false` | `10000` |
##### FuturesSettings
| Key | Description | Example |
|----------|------------------------------------------------------------------------------------------|---------|
| Leverage | This struct defines the leverage rules that this specific currency setting must abide by | `1` |
| leverage | This struct defines the leverage rules that this specific currency setting must abide by | `1` |
#### 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` |
### DataSettings
| Key | Description | Example |
|---------------------------|--------------------------------------------------------------------------------------------------------|---------------|
| interval | The candle interval in `time.Duration` format eg set as`15000000000` for a value of `time.Second * 15` | `15000000000` |
| data-type | Choose whether `candle` or `trade` data is used. If trades are used, they will be converted to candles | `trade` |
| verbose-exchange-requests | When retrieving candle data from an exchange, print verbose request/response details | `false` |
| api-data | Holds API data settings. See table `APIData` | |
| database-data | Holds database data settings. See table `DatabaseData` | |
| live-data | Holds API data settings. See table `LiveData` | |
| csv-data | Holds CSV data settings. See table `CSVData` | |
#### 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 as`15000000000` 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` |
| Key | Description | Example |
|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| start-date | The start date to retrieve data | `2021-01-23T11:00:00+11:00` |
| end-date | The end date to retrieve data | `2021-01-24T11:00:00+11:00` |
| inclusive-end-date | 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 as`15000000000` for a value of `time.Second * 15` | `15000000000` |
| FullPath | The file to load | `/data/exchangelist.csv` |
| Key | Description | Example |
|-----------|------------------|--------------------------|
| full-path | 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 as`15000000000` 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` |
| Key | Description | Example |
|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| start-date | The start date to retrieve data | `2021-01-23T11:00:00+11:00` |
| end-date | 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 | `` |
| inclusive-end-date | 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
@@ -219,32 +208,65 @@ See below for a set of tables and fields, expected values and what they can do
#### 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 as`15000000000` 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` |
| Key | Description | Example |
|------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|---------------|
| new-event-timeout | The time allowed to wait for new data before exiting the strategy. Ensures new data is always coming in | `60000000000` |
| data-check-timer | The interval in which to check exchange API's for new data | `1000000000` |
| real-orders | Whether to place real orders with real money. Its likely you should never want to set this to true | `false` |
| close-positions-on-stop | As live trading doesn't stop until you tell it to, you can trigger a close of your position(s) when you stop the strategy | `true` |
| data-request-retry-tolerance | Rather than immediately closing a strategy on failure to retreive candle data, having a retry tolerance allows multiple attempts to return data | `3` |
| data-request-retry-wait-time | How long to wait in between request retries | `500000000` |
| exchange-credentials | A list of exchange credentials. See table named `ExchangeCredentials` | |
##### ExchangeCredentials Settings
| Key | Description | Example |
|-------------|-----------------------------------------------------------|-----------|
| exchange | The exchange to apply credentials to | `binance` |
| credentials | The API credentials to use. See table named `Credentials` | |
##### Credentials Settings
| Key | Description | Example |
|-----------------|---------------------------------------------------------------------------------------------|--------------|
| Key | Will set the GoCryptoTrader exchange to use the following API Key | `1234` |
| Secret | Will set the GoCryptoTrader exchange to use the following API Secret | `5678` |
| ClientID | Will set the GoCryptoTrader exchange to use the following API Client ID | `9012` |
| PEMKey | Private key for certain API requests. If you don't know it, you probably don't need it | `hello-moto` |
| SubAccount | Will set the GoCryptoTrader exchange to use the following subaccount on supported exchanges | `subzero` |
| OneTimePassword | Will set the GoCryptoTrader exchange to use the following 2FA seed | `subzero` |
#### PortfolioSettings
| Key | Description |
|-----------|------------------------------------------------------------------------------------------------------------------------|
| leverage | This struct defines the leverage rules that this specific currency setting must abide by |
| buy-side | This struct defines the buying side rules this specific currency setting must abide by such as maximum purchase amount |
| sell-side | This struct defines the selling side rules this specific currency setting must abide by such as maximum selling amount |
##### 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` |
| Key | Description | Example |
|------------------------------------|-------------------------------|---------|
| can-use-leverage | Allows the use of leverage | `false` |
| maximum-orders-with-leverage-ratio | currently unused | `0.5` |
| maximum-leverage-rate | currently unused | `100` |
| maximum-collateral-leverage-rate | currently unused | `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` |
| Key | Description | Example |
|---------------|------------------------------------------------------------------------------------------------------------------|---------|
| minimum-size | If the order's quantity is below this, the order cannot be placed | `0.1` |
| maximum-size | If the order's quantity is over this amount, it cannot be placed and will be reduced to the maximum amount | `10` |
| maximum-total | If the order's price * amount exceeds this number, the order cannot be placed and will be reduced to this figure | `1337` |
#### StatisticsSettings
| Key | Description | Example |
|----------------|-------------------------------------------------------------------------|---------|
| risk-free-rate | The risk free rate used in the calculation of sharpe and sortino ratios | `0.03` |
### Please click GoDocs chevron above to view current GoDoc information for this package
{{template "contributions"}}

View File

@@ -5,7 +5,7 @@
This package will retrieve data for the backtester via continuous requests to live endpoints
## Important notice
Live trading is not fully implemented and you should never consider setting `RealOrders` to `true` in a config. *Past performance is no guarantee of future results*
Its incredibly risky to enable `real-orders`. *Past performance is no guarantee of future results*
### Please click GoDocs chevron above to view current GoDoc information for this package
{{template "contributions"}}

View File

@@ -1,21 +1,24 @@
{{define "backtester eventhandlers strategies ftxcashandcarry" -}}
{{define "backtester eventhandlers strategies binancecashandcarry" -}}
{{template "backtester-header" .}}
## FTX Cash and carry strategy overview
## Binance Cash and carry strategy overview
## Important
This strategy was initially designed for the exchange FTX. It is currently being ported to Binance. It does not work at present.
### Description
Cash and carry is a strategy which takes advantage of the difference in pricing between a long-dated futures contract and a SPOT asset.
By default, this cash and carry strategy will, upon the first data event, purchase BTC-USD SPOT asset from FTX exchange and then, once filled, raise a SHORT for BTC-20210924 FUTURES contract.
By default, this cash and carry strategy will, upon the first data event, purchase BTC-USD SPOT asset from Binance exchange and then, once filled, raise a SHORT for BTC-20210924 FUTURES contract.
On the last event, the strategy will close the SHORT position by raising a LONG of the same contract amount, thereby netting the difference in prices
### Requirements
- At this time of writing, this strategy is only compatible with FTX
- At this time of writing, this strategy is only compatible with Binance
- This strategy *requires* `Simultaneous Signal Processing` aka [use-simultaneous-signal-processing](/backtester/config/README.md).
- This strategy *requires* `Exchange Level Funding` aka [use-exchange-level-funding](/backtester/config/README.md).
### Creating a strategy config
- The long-dated futures contract will need to be part of the `currency-settings` of the contract
- Funding for purchasing SPOT assets will need to be part of `funding-settings`
- See the [example config](./config/examples/ftx-cash-carry.strat)
- See the [example config](./config/strategyexamples/binance-cash-carry.strat)
### Customisation
This strategy does support strategy customisation in the following ways:
@@ -31,4 +34,5 @@ This strategy does support strategy customisation in the following ways:
### Please click GoDocs chevron above to view current GoDoc information for this package
{{template "contributions"}}
{{template "donations" .}}
{{end}}
{{end}}

View File

@@ -39,7 +39,7 @@ Yes! Though it does use some things to consider.
- For example, if an indicator is very strong on one exchange, but not another, you may wish to transfer funds to the strongest exchange to act upon
- It comes with the assumption that a transfer is actually possible in the candle timeframe your strategy runs on.
- For example, a 1 minute candle strategy likely would not be able to process a transfer of funds and have another exchange use it in that timeframe. So any positive results from such a strategy may not be reflected in real-world scenarios
- You can only transfer to the same currency eg BTC from Binance to FTX, no conversions
- You can only transfer to the same currency eg BTC from Binance to Kraken, no conversions
- You set the transfer fee in your config
### Do I need to add funding settings to my config if Exchange Level Funding is disabled?
@@ -47,28 +47,29 @@ No. The already existing `CurrencySettings` will populate the funding manager wi
#### 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 } ` |
#### Funding Settings
| Key | Description | Example |
| --- | ------- | --- |
| UseExchangeLevelFunding | This allows shared exchange funds to be used in your strategy. Requires `UsesSimultaneousProcessing` to be set to `true` to use | `false` |
| ExchangeLevelFunding | This is a list of funding definitions if `UseExchangeLevelFunding` is set to true | See below table |
| Key | Description | Example |
|------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------|
| name | The strategy to use | `rsi` |
| use-simultaneous-signal-processing | 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` |
| disable-usd-tracking | 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` |
| custom-settings | 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 } ` |
#### Funding Config Settings
| Key | Description | Example |
| --- | ------- | ----- |
| ExchangeName | The exchange to set funds. See [here](https://github.com/thrasher-corp/gocryptotrader/blob/master/README.md) for a list of supported exchanges | `Binance` |
| Asset | The asset type to set funds. Typically, this will be `spot`, however, see [this package](https://github.com/thrasher-corp/gocryptotrader/blob/master/exchanges/asset/asset.go) 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` |
| Key | Description | Example |
|----------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|
| use-exchange-level-funding | 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](/backtester/funding/README.md) for more information | `false` |
| exchange-level-funding | An array of exchange level funding settings. See below, or [this](/backtester/funding/README.md) for more information | `[]` |
##### Funding Item Config Settings
| Key | Description | Example |
|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------|
| exchange-name | The exchange to set funds. See [here](https://github.com/thrasher-corp/gocryptotrader/blob/master/README.md) for a list of supported exchanges | `Binance` |
| asset | The asset type to set funds. Typically, this will be `spot`, however, see [this package](https://github.com/thrasher-corp/gocryptotrader/blob/master/exchanges/asset/asset.go) for the various asset types GoCryptoTrader supports | `spot` |
| currency | The currency to set funds | `BTC` |
| initial-funds | The initial funding for the currency | `1337` |
| transfer-fee | If your strategy utilises transferring of funds via the Funding Manager, this is deducted upon doing so | `0.005` |
### Please click GoDocs chevron above to view current GoDoc information for this package
{{template "contributions"}}

View File

@@ -27,20 +27,23 @@ An event-driven backtesting tool to test and iterate trading strategies using hi
- Fund transfer. At a strategy level, transfer funds between exchanges to allow for complex strategy design
- Backtesting support for futures asset types
- Example cash and carry spot futures strategy
- Long-running application
- GRPC server implementation
- Long-running application as a GRPC server
- Custom strategy plugins
- Live data source trading. Traders can move their back tested strategies and use them against current live data
## Planned Features
We welcome pull requests on any feature for the Backtester! We will be especially appreciative of any contribution towards the following planned features:
| Feature | Description |
|---------|-------------|
| Perpetual futures support | Accounting for hourly funding rates in user's overall positions allows for much greater strategic depth |
| Margin borrowing support | Allowing strategies to utilise margin borrowing to have larger positions and handling borrow rate payments |
| Leverage support | Leverage is a good way to enhance profit and loss and is important to include in strategies |
| Live ticker data | A potential feature as live trading works off candle data which is only processed at intervals. Adding ticker data as a strategic source allows for faster decision making |
| Live orderbook data | Processing orders based off the latest orderbook data allows for much more accurate order placement and reduces surprise slippage |
| Enhance config-builder | Create an application that can create strategy configs in a more visual manner and execute them via GRPC to allow for faster customisation of strategies |
| Save Backtester results to database | This will allow for easier comparison of results over time |
| Backtester result comparison report | Providing an executive summary of Backtester database results |
| Currency correlation | Compare multiple exchange, asset, currencies for a candle interval against indicators to highlight correlated pairs for use in pairs trading |
| Improve live trading functionality | Live trading is currently only a proof Of concept. Adding live support for running multiple currencies and running off orderbook data will allow for esteemed traders to use their backtested strategies |
## How does it work?

View File

@@ -171,11 +171,26 @@ func main() {
// Github API missing contributors
contributors = append(contributors, []Contributor{
{
Login: "cornelk",
URL: "https://github.com/cornelk",
Contributions: 2,
},
{
Login: "herenow",
URL: "https://github.com/herenow",
Contributions: 2,
},
{
Login: "if1live",
URL: "https://github.com/if1live",
Contributions: 2,
},
{
Login: "lozdog245",
URL: "https://github.com/lozdog245",
Contributions: 2,
},
{
Login: "mshogin",
URL: "https://github.com/mshogin",
@@ -191,6 +206,31 @@ func main() {
URL: "https://github.com/tk42",
Contributions: 2,
},
{
Login: "blombard",
URL: "https://github.com/blombard",
Contributions: 1,
},
{
Login: "cavapoo2",
URL: "https://github.com/cavapoo2",
Contributions: 1,
},
{
Login: "CodeLingoTeam",
URL: "https://github.com/CodeLingoTeam",
Contributions: 1,
},
{
Login: "CodeLingoBot",
URL: "https://github.com/CodeLingoBot",
Contributions: 1,
},
{
Login: "Daanikus",
URL: "https://github.com/Daanikus",
Contributions: 1,
},
{
Login: "daniel-cohen",
URL: "https://github.com/daniel-cohen",
@@ -213,36 +253,6 @@ func main() {
URL: "https://github.com/idoall",
Contributions: 1,
},
{
Login: "mattkanwisher",
URL: "https://github.com/mattkanwisher",
Contributions: 1,
},
{
Login: "mKurrels",
URL: "https://github.com/mKurrels",
Contributions: 1,
},
{
Login: "m1kola",
URL: "https://github.com/m1kola",
Contributions: 1,
},
{
Login: "cavapoo2",
URL: "https://github.com/cavapoo2",
Contributions: 1,
},
{
Login: "zeldrinn",
URL: "https://github.com/zeldrinn",
Contributions: 1,
},
{
Login: "starit",
URL: "https://github.com/starit",
Contributions: 1,
},
{
Login: "Jimexist",
URL: "https://github.com/Jimexist",
@@ -253,45 +263,36 @@ func main() {
URL: "https://github.com/lookfirst",
Contributions: 1,
},
{
Login: "m1kola",
URL: "https://github.com/m1kola",
Contributions: 1,
},
{
Login: "mattkanwisher",
URL: "https://github.com/mattkanwisher",
Contributions: 1,
},
{
Login: "merkeld",
URL: "https://github.com/merkeld",
Contributions: 1,
},
{
Login: "CodeLingoTeam",
URL: "https://github.com/CodeLingoTeam",
Login: "mKurrels",
URL: "https://github.com/mKurrels",
Contributions: 1,
},
{
Login: "Daanikus",
URL: "https://github.com/Daanikus",
Contributions: 1,
}, {
Login: "CodeLingoBot",
URL: "https://github.com/CodeLingoBot",
Login: "starit",
URL: "https://github.com/starit",
Contributions: 1,
},
{
Login: "blombard",
URL: "https://github.com/blombard",
Login: "zeldrinn",
URL: "https://github.com/zeldrinn",
Contributions: 1,
},
{
Login: "soxipy",
URL: "https://github.com/soxipy",
Contributions: 2,
},
{
Login: "lozdog245",
URL: "https://github.com/lozdog245",
Contributions: 2,
},
{
Login: "if1live",
URL: "https://github.com/if1live",
Contributions: 2,
},
}...)
if verbose {