Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feature) Backtest History #680

Merged
merged 49 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
e7e3481
Restore Recurring order on FE
dmytroshch Jul 28, 2023
b2f3a8e
HistoryButton: moved to separated component
dmytroshch Aug 14, 2023
d85e64c
Backtest: add history/new test toggler
dmytroshch Aug 14, 2023
37a35ba
PanelButton: align text and icon
dmytroshch Aug 14, 2023
e6b136e
fetch strategy backtests
dmytroshch Aug 14, 2023
7b5bd2e
BT history: recieve data from data-server
dmytroshch Aug 15, 2023
22889b6
BT history: layout list
dmytroshch Aug 15, 2023
d14151e
BT history: restructure components and folders
dmytroshch Aug 16, 2023
23ee4e5
BT history: launch to details tab
dmytroshch Aug 16, 2023
fbdb4f0
BT history: details layout"
dmytroshch Aug 16, 2023
36e0519
fix prop validation
dmytroshch Aug 16, 2023
470ee06
BT history: fix styles
dmytroshch Aug 16, 2023
e4804a1
BT history: results
dmytroshch Aug 17, 2023
be620fd
Revert "Merge pull request #394 from dmytroshch/fix/backtest-clear"
dmytroshch Aug 17, 2023
34e3fbc
fixed: new test button
dmytroshch Aug 17, 2023
b115ac7
BT: add bt to history after execution
dmytroshch Aug 17, 2023
1b00c85
BT: log error messages during execution
dmytroshch Aug 17, 2023
6ce9cdf
BT: update initial messages
dmytroshch Aug 17, 2023
f65425c
BT: fix button style
dmytroshch Aug 17, 2023
879bb32
BT: reset tab state when strategy has changed
dmytroshch Aug 17, 2023
d15cecb
BT: change fetching history logic
dmytroshch Aug 17, 2023
a3a80fb
removed duplicated action
dmytroshch Aug 17, 2023
84a1792
rename method
dmytroshch Aug 17, 2023
4536691
BT: remove history on strategy delete
dmytroshch Aug 17, 2023
dc7efe9
BT history: move some component state properties to redux store
dmytroshch Aug 17, 2023
eb3a47b
StrategyLiveChart: unify data
dmytroshch Aug 18, 2023
e7a2ce0
removed unused
dmytroshch Aug 22, 2023
69ad4e5
resolve useCallback dependecies
dmytroshch Aug 22, 2023
727d18b
Show backtest range in results
dmytroshch Aug 22, 2023
23e2247
fix prop validation
dmytroshch Aug 22, 2023
a595aa5
getting recurring ao atomic orders
dmytroshch Aug 22, 2023
d87a29f
fix failed order layout
dmytroshch Aug 23, 2023
562d042
Resolve issue with recurring AO template selection
dmytroshch Aug 24, 2023
570b83f
OrderHistory: add id property for failed order
dmytroshch Aug 24, 2023
3feb5de
improve formatTime fn
dmytroshch Aug 24, 2023
99cf6eb
update ufx-ui to 0.15.3
dmytroshch Aug 25, 2023
79464dc
DatePicker: fix clipping with parent's container
dmytroshch Aug 25, 2023
fa07588
DatePicker: remove unused
dmytroshch Aug 25, 2023
4418667
DatePicker: limit min/max time, improve onChange handler
dmytroshch Aug 25, 2023
ba12763
Recurring: improve end date input
dmytroshch Aug 25, 2023
a32a89d
DatePicker: improve position
dmytroshch Aug 25, 2023
a3743d0
BacktestOptionsPanel: use DatePicker from ui components
dmytroshch Aug 25, 2023
ed68b6d
BacktestOptionsPanel: resolve issue with time period dropdown which i…
dmytroshch Aug 25, 2023
bc7925a
Message for invalid api creds
dmytroshch Aug 25, 2023
884cde6
Merge branch 'feature/restore-recurring' into feature/bt-history
dmytroshch Aug 25, 2023
bc6470a
resolve conflicts
dmytroshch Aug 25, 2023
1607e5b
Merge branch 'main' into feature/bt-history
dmytroshch Sep 6, 2023
411a899
resolve lint
dmytroshch Sep 6, 2023
c78ab6f
resolve lint
dmytroshch Sep 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/components/BacktestOptionsPanel/BacktestResultsOptionsPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ import WSActions from '../../redux/actions/ws'
import { BACKTEST_TAB_SECTIONS } from '../../redux/reducers/ui'
import { getCurrentHistoryBacktest } from '../../redux/selectors/ws'

const renderBacktestRange = (backtest, formatTime, t) => (
<p>
{t('strategyEditor.backtestHistoryResults')}
&nbsp;
<b>{renderDate(_get(backtest, 'start', 0), formatTime, false)}</b>
&nbsp; - &nbsp;
<b>{renderDate(_get(backtest, 'end', 0), formatTime, false)}</b>
</p>
)

const BacktestResultsOptionsPanel = ({ showFullscreenChart }) => {
const formatTime = useSelector(getFormatTimeFn)
const backtest = useSelector(getCurrentHistoryBacktest)
Expand Down Expand Up @@ -45,13 +55,7 @@ const BacktestResultsOptionsPanel = ({ showFullscreenChart }) => {
isActive={false}
icon={<Icon name='arrow-left' className='icon' />}
/>
<p>
{t('strategyEditor.backtestHistoryResults')}
&nbsp;
<b>
{renderDate(_get(backtest, 'timestamp', 0), formatTime, false)}
</b>
</p>
{renderBacktestRange(backtest, formatTime, t)}
<Button
className='hfui-strategy-options__option-btn'
label={t('strategyEditor.newTest')}
Expand All @@ -62,6 +66,7 @@ const BacktestResultsOptionsPanel = ({ showFullscreenChart }) => {
) : (
<div className='hfui-strategy-options__results-container'>
<p>{t('strategyEditor.backtestSuccessful')}</p>
{renderBacktestRange(backtest, formatTime, t)}
<Button
className='hfui-strategy-options__option-btn'
label={t('strategyEditor.newTest')}
Expand Down
6 changes: 5 additions & 1 deletion src/components/BacktestProgressBar/BacktestProgressBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ const BacktestProgressBar = ({ percent, startedOn }) => {

BacktestProgressBar.propTypes = {
percent: PropTypes.number.isRequired,
startedOn: PropTypes.number.isRequired,
startedOn: PropTypes.number,
}

BacktestProgressBar.defaultProps = {
startedOn: new Date().getTime(),
}

export default BacktestProgressBar
19 changes: 17 additions & 2 deletions src/components/StrategyEditor/tabs/BacktestTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import UIActions from '../../../redux/actions/ui'
import WSTypes from '../../../redux/constants/ws'
import {
getBacktestState,
getCurrentHistoryBacktest,
getCurrentStrategyBacktestsList,
} from '../../../redux/selectors/ws'
import { BACKTEST_TAB_SECTIONS } from '../../../redux/reducers/ui'
Expand Down Expand Up @@ -65,6 +66,7 @@ const BacktestTab = (props) => {
)
const activeSection = useSelector(getBacktestActiveSection)
const backtestState = useSelector(getBacktestState)
const currentHistoryBacktest = useSelector(getCurrentHistoryBacktest)

const {
finished = false,
Expand Down Expand Up @@ -105,7 +107,7 @@ const BacktestTab = (props) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [finished])

// If a strategy has changed, reset tab state
// Fetch BT history list
useEffect(() => {
if (!isBacktestListFetched) {
dispatch(
Expand All @@ -120,6 +122,18 @@ const BacktestTab = (props) => {

const renderGridComponents = useCallback(
(i) => {
const {
timeframe, symbol, candleSeed, start, end, executionId,
} = currentHistoryBacktest
const chartOptions = {
timeframe,
symbol,
candleSeed,
executionId,
start,
end,
}

switch (i) {
case COMPONENTS_KEYS.OPTIONS:
return showBacktestResults ? (
Expand All @@ -141,7 +155,7 @@ const BacktestTab = (props) => {
<StrategyLiveChart
indicators={indicators}
markets={markets}
strategy={strategy}
options={chartOptions}
fullscreenChart={fullscreenChart}
exitFullscreenChart={hideFullscreenChart}
trades={trades}
Expand Down Expand Up @@ -189,6 +203,7 @@ const BacktestTab = (props) => {
results,
positions,
layoutConfig,
currentHistoryBacktest,
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ const StrategyLiveTab = (props) => {

const renderGridComponents = useCallback(
(i) => {
const chartOptions = {
candleSeed: strategy.strategyOptions.candleSeed,
symbol: strategy.strategyOptions.symbol.wsID,
executionId: strategy.executionId || strategy.id,
start: strategy.startedOn,
end: strategy.stoppedOn,
}
switch (i) {
case COMPONENTS_KEYS.OPTIONS:
return (
Expand All @@ -91,11 +98,10 @@ const StrategyLiveTab = (props) => {
indicators={indicators}
lastOpenPosition={lastOpenPosition}
markets={markets}
strategy={strategy}
options={chartOptions}
fullscreenChart={fullscreenChart}
exitFullscreenChart={unsetFullScreenChart}
trades={trades}
isExecuting={executing}
/>
)

Expand Down
42 changes: 20 additions & 22 deletions src/components/StrategyLiveChart/StrategyLiveChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { getPositionTooltip } from '../../util/chart'
import {
INDICATORS_ARRAY_SHAPE,
MARKET_SHAPE,
STRATEGY_SHAPE,
STRATEGY_TRADE_SHAPE,
} from '../../constants/prop-types-shapes'
import PanelIconButton from '../../ui/Panel/Panel.IconButton'
Expand All @@ -28,36 +27,30 @@ const StrategyLiveChart = ({
markets,
fullscreenChart,
exitFullscreenChart,
strategy,
options,
lastOpenPosition,
trades,
isBacktest,
isExecuting,
}) => {
const {
strategyOptions: {
timeframe, symbol, startDate, endDate,
},
id,
executionId = id,
startedOn,
stoppedOn,
} = strategy
const start = isBacktest ? new Date(startDate).getTime() : startedOn
const end = isBacktest
? new Date(endDate).getTime()
: isExecuting
? null
: stoppedOn
timeframe,
symbol,
candleSeed,
executionId,
start,
end,
} = options

const chartRange = useMemo(() => {
if (start || end) {
return {
start,
end,
candleSeed,
}
}
return {}
}, [end, start])
}, [end, start, candleSeed])
const { t } = useTranslation()
const settingsTheme = useSelector(getThemeSetting)
const chartIndicators = useMemo(
Expand All @@ -70,7 +63,7 @@ const StrategyLiveChart = ({

const {
wsID, uiID, base, quote,
} = getStrategyMarket(markets, symbol?.wsID)
} = getStrategyMarket(markets, symbol)
const chartMarket = useMemo(
() => ({
wsID,
Expand Down Expand Up @@ -152,21 +145,26 @@ const StrategyLiveChart = ({

StrategyLiveChart.propTypes = {
markets: PropTypes.arrayOf(PropTypes.shape(MARKET_SHAPE)).isRequired,
strategy: PropTypes.shape(STRATEGY_SHAPE).isRequired,
options: PropTypes.shape({
timeframe: PropTypes.string,
symbol: PropTypes.string,
end: PropTypes.number,
start: PropTypes.number,
candleSeed: PropTypes.number,
executionId: PropTypes.string,
}).isRequired,
indicators: INDICATORS_ARRAY_SHAPE,
trades: PropTypes.arrayOf(PropTypes.shape(STRATEGY_TRADE_SHAPE)).isRequired,
fullscreenChart: PropTypes.bool.isRequired,
exitFullscreenChart: PropTypes.func.isRequired,
lastOpenPosition: PropTypes.object, // eslint-disable-line
isBacktest: PropTypes.bool,
isExecuting: PropTypes.bool,
}

StrategyLiveChart.defaultProps = {
indicators: [],
isBacktest: false,
lastOpenPosition: null,
isExecuting: false,
}

export default memo(StrategyLiveChart)
1 change: 1 addition & 0 deletions src/redux/reducers/ws/backtestHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const reducer = (state = getInitialState(), action = {}) => {
...state.mappedKeysByStrategyIds,
[strategyId]: [...strategyMappedKeys, executionId],
},
backtestId: executionId,
}
}

Expand Down
Loading