mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-16 07:26:47 +00:00
Backtester: mini bug fixes (#1011)
* fixes errors with non-default strategies * actually err = nil was silly * fixes bug on sell side sizing, adjusts RSI strat
This commit is contained in:
@@ -930,26 +930,12 @@ func TestGenerateConfigForRSIAPICustomSettings(t *testing.T) {
|
||||
MakerFee: &makerFee,
|
||||
TakerFee: &takerFee,
|
||||
},
|
||||
{
|
||||
ExchangeName: testExchange,
|
||||
Asset: asset.Spot,
|
||||
Base: currency.ETH,
|
||||
Quote: currency.USDT,
|
||||
SpotDetails: &SpotDetails{
|
||||
InitialBaseFunds: initialFunds10,
|
||||
InitialQuoteFunds: initialFunds1000000,
|
||||
},
|
||||
BuySide: minMax,
|
||||
SellSide: minMax,
|
||||
MakerFee: &makerFee,
|
||||
TakerFee: &takerFee,
|
||||
},
|
||||
},
|
||||
DataSettings: DataSettings{
|
||||
Interval: kline.OneDay,
|
||||
DataType: common.CandleStr,
|
||||
APIData: &APIData{
|
||||
StartDate: startDate,
|
||||
StartDate: time.Date(2021, 5, 1, 0, 0, 0, 0, time.Local),
|
||||
EndDate: endDate,
|
||||
InclusiveEndDate: false,
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"nickname": "Example Cash and Carry",
|
||||
"nickname": "ExampleCashAndCarry",
|
||||
"goal": "To demonstrate a cash and carry strategy",
|
||||
"strategy-settings": {
|
||||
"name": "ftx-cash-carry",
|
||||
|
||||
@@ -41,41 +41,13 @@
|
||||
"skip-candle-volume-fitting": false,
|
||||
"use-exchange-order-limits": false,
|
||||
"use-exchange-pnl-calculation": false
|
||||
},
|
||||
{
|
||||
"exchange-name": "ftx",
|
||||
"asset": "spot",
|
||||
"base": "ETH",
|
||||
"quote": "USDT",
|
||||
"spot-details": {
|
||||
"initial-base-funds": "10",
|
||||
"initial-quote-funds": "1000000"
|
||||
},
|
||||
"buy-side": {
|
||||
"minimum-size": "0.005",
|
||||
"maximum-size": "2",
|
||||
"maximum-total": "40000"
|
||||
},
|
||||
"sell-side": {
|
||||
"minimum-size": "0.005",
|
||||
"maximum-size": "2",
|
||||
"maximum-total": "40000"
|
||||
},
|
||||
"min-slippage-percent": "0",
|
||||
"max-slippage-percent": "0",
|
||||
"maker-fee-override": "0.0002",
|
||||
"taker-fee-override": "0.0007",
|
||||
"maximum-holdings-ratio": "0",
|
||||
"skip-candle-volume-fitting": false,
|
||||
"use-exchange-order-limits": false,
|
||||
"use-exchange-pnl-calculation": false
|
||||
}
|
||||
],
|
||||
"data-settings": {
|
||||
"interval": 86400000000000,
|
||||
"data-type": "candle",
|
||||
"api-data": {
|
||||
"start-date": "2021-08-01T00:00:00+10:00",
|
||||
"start-date": "2021-05-01T00:00:00+10:00",
|
||||
"end-date": "2021-12-01T00:00:00+11:00",
|
||||
"inclusive-end-date": false
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
|
||||
var (
|
||||
errNilConfig = errors.New("unable to setup backtester with nil config")
|
||||
errInvalidConfigAsset = errors.New("invalid asset in config")
|
||||
errAmbiguousDataSource = errors.New("ambiguous settings received. Only one data type can be set")
|
||||
errNoDataSource = errors.New("no data settings set in config")
|
||||
errIntervalUnset = errors.New("candle interval unset")
|
||||
|
||||
@@ -170,10 +170,10 @@ func NewFromConfig(cfg *config.Config, templatePath, output string, verbose bool
|
||||
portfolioRisk.CurrencySettings[cfg.CurrencySettings[i].ExchangeName] = make(map[asset.Item]map[currency.Pair]*risk.CurrencySettings)
|
||||
}
|
||||
a := cfg.CurrencySettings[i].Asset
|
||||
if err != nil {
|
||||
if !a.IsValid() {
|
||||
return nil, fmt.Errorf(
|
||||
"%w for %v %v %v-%v. Err %v",
|
||||
errInvalidConfigAsset,
|
||||
asset.ErrNotSupported,
|
||||
cfg.CurrencySettings[i].ExchangeName,
|
||||
cfg.CurrencySettings[i].Asset,
|
||||
cfg.CurrencySettings[i].Base,
|
||||
@@ -293,7 +293,7 @@ func NewFromConfig(cfg *config.Config, templatePath, output string, verbose bool
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("%w: %v unsupported", errInvalidConfigAsset, a)
|
||||
return nil, fmt.Errorf("%w: %v", asset.ErrNotSupported, a)
|
||||
}
|
||||
} else {
|
||||
var bFunds, qFunds decimal.Decimal
|
||||
|
||||
@@ -208,12 +208,12 @@ func (p *Portfolio) sizeOrder(d common.Directioner, cs *exchange.Settings, origi
|
||||
switch d.GetDirection() {
|
||||
case gctorder.Buy,
|
||||
gctorder.Bid,
|
||||
gctorder.Sell,
|
||||
gctorder.Ask,
|
||||
gctorder.Short,
|
||||
gctorder.Long:
|
||||
sizedOrder.AllocatedFunds = sizedOrder.Amount.Mul(sizedOrder.ClosePrice).Add(estFee)
|
||||
case gctorder.ClosePosition:
|
||||
case gctorder.Sell,
|
||||
gctorder.Ask,
|
||||
gctorder.ClosePosition:
|
||||
sizedOrder.AllocatedFunds = sizedOrder.Amount
|
||||
default:
|
||||
return nil, errInvalidDirection
|
||||
|
||||
@@ -1746,7 +1746,7 @@
|
||||
</td>
|
||||
{{ else if ne $ev.SignalEvent nil}}
|
||||
<td>{{$ev.SignalEvent.GetTime}}</td>
|
||||
<td>{{ $.Prettify.Decimal8 $ev.SignalEvent.GetPrice}} {{if $asset.IsFutures}}{{if ne $ev.PNL nil }}{{$ev.PNL.GetCollateralCurrency}}{{end}}{{else}}{{$pair.Quote}}{{end}}</td>
|
||||
<td>{{ $.Prettify.Decimal8 $ev.SignalEvent.GetClosePrice}} {{if $asset.IsFutures}}{{if ne $ev.PNL nil }}{{$ev.PNL.GetCollateralCurrency}}{{end}}{{else}}{{$pair.Quote}}{{end}}</td>
|
||||
<td>{{$ev.SignalEvent.GetDirection}}</td>
|
||||
<td>
|
||||
<ul>
|
||||
|
||||
Reference in New Issue
Block a user