From 2a549d7a7aad3fa67aca39a62e4c735d441bda9c Mon Sep 17 00:00:00 2001 From: Dmytro Shcherbonos Date: Thu, 21 Sep 2023 12:28:51 +0300 Subject: [PATCH] run backtest with derivatives --- .../StrategyEditor.container.js | 6 ++++ .../StrategyEditor/StrategyEditor.helpers.js | 28 +++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/components/StrategyEditor/StrategyEditor.container.js b/src/components/StrategyEditor/StrategyEditor.container.js index 98586b4ca..49760a874 100644 --- a/src/components/StrategyEditor/StrategyEditor.container.js +++ b/src/components/StrategyEditor/StrategyEditor.container.js @@ -104,6 +104,9 @@ const mapDispatchToProps = (dispatch) => ({ constraints, label, id, + leverageSettings, + stopOrderSettings, + margin, } = data const processedStrategy = _omitBy(strategyContent, _isEmpty) const sync = true @@ -125,9 +128,12 @@ const mapDispatchToProps = (dispatch) => ({ trades, candleSeed, sync, + margin, processedStrategy, uuidv4(), constraints, + leverageSettings, + stopOrderSettings, ], ], }), diff --git a/src/components/StrategyEditor/StrategyEditor.helpers.js b/src/components/StrategyEditor/StrategyEditor.helpers.js index c49889955..bf1691e96 100644 --- a/src/components/StrategyEditor/StrategyEditor.helpers.js +++ b/src/components/StrategyEditor/StrategyEditor.helpers.js @@ -149,13 +149,20 @@ export const prepareStrategyBacktestingArgs = (strategy) => { maxDrawdownPerc, startDate, endDate, + margin, + useMaxLeverage, + increaseLeverage, + leverage, + addStopOrder, + stopOrderPercent, }, strategyContent, id, } = strategy - return { + const args = { symbol: symbol?.wsID, + label, startNum: new Date(startDate).getTime(), endNum: new Date(endDate).getTime(), [STRATEGY_OPTIONS_KEYS.TIMEFRAME]: timeframe, @@ -164,13 +171,30 @@ export const prepareStrategyBacktestingArgs = (strategy) => { id, [STRATEGY_OPTIONS_KEYS.CANDLES]: candles, [STRATEGY_OPTIONS_KEYS.CANDLE_SEED]: candleSeed, + [STRATEGY_OPTIONS_KEYS.MARGIN]: margin, constraints: { [STRATEGY_OPTIONS_KEYS.CAPITAL_ALLOCATION]: Number(capitalAllocation), [STRATEGY_OPTIONS_KEYS.STOP_LOSS_PERC]: Number(stopLossPerc), [STRATEGY_OPTIONS_KEYS.MAX_DRAWDOWN_PERC]: Number(maxDrawdownPerc), }, - label, + leverageSettings: {}, + stopOrderSettings: { + addStopOrder, + }, + } + + if (margin) { + args.leverageSettings.useMaxLeverage = useMaxLeverage + if (!useMaxLeverage) { + args.leverageSettings.leverage = Number(leverage) + args.leverageSettings.increaseLeverage = increaseLeverage + } } + if (addStopOrder && stopOrderPercent) { + args.stopOrderSettings.stopOrderPercent = Number(stopOrderPercent) + } + + return args } export const prepareStrategyToLoad = (strategyToLoad, markets, strategies) => {