Skip to content

Commit

Permalink
Merge pull request bitfinexcom#394 from dmytroshch/fix/backtest-clear
Browse files Browse the repository at this point in the history
(fix): When strategy changed, backtest results should be clear
  • Loading branch information
bhoomij authored Jun 14, 2022
2 parents 7e41af4 + 2a1261f commit 755f7dd
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 7 deletions.
5 changes: 4 additions & 1 deletion public/locales/en-US/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@
"disconnected": "Disconnected"
},
"strategyEditor": {
"clearBacktestResultsModalTitle": "Confirmation Required",
"clearBacktestResultsModalText": "If you choose to continue, the current backtest results will be cleared. Do you wish to proceed?",
"unsavedChanges": "Unsaved changes",
"unsavedChangesModalTitle": "Do you need to save changes in the strategy before closing?",
"cancelThisProcess": "Cancel this process",
Expand Down Expand Up @@ -773,7 +775,8 @@
"name": "Name",
"notSelected": "Not selected",
"e.g.": "e.g. {{value}}",
"required": "REQUIRED"
"required": "REQUIRED",
"proceed": "Proceed"
},
"crashHandler": {
"text1": "An error occurred that caused the HoneyFramework UI to halt. Please, restart the application to proceed working with it",
Expand Down
3 changes: 0 additions & 3 deletions src/components/StrategyEditor/StrategyEditor.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ const mapDispatchToProps = (dispatch) => ({
gaCreateStrategy: () => {
dispatch(GAActions.createStrategy())
},
clearBacktestOptions: () => {
dispatch(WSActions.resetBacktestData())
},
dsExecuteLiveStrategy: ({
authToken,
label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ StrategyPerfomanceMetrics.propTypes = {
returnPerc: PropTypes.string,
drawdown: PropTypes.string,
}),
isExecuting: PropTypes.bool.isRequired,
isExecuting: PropTypes.bool,
isBacktest: PropTypes.bool,
startedOn: PropTypes.number,
}
Expand All @@ -186,6 +186,7 @@ StrategyPerfomanceMetrics.defaultProps = {
},
isBacktest: false,
startedOn: 0,
isExecuting: false,
}

export default StrategyPerfomanceMetrics
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React, { memo } from 'react'
import PropTypes from 'prop-types'
import { useTranslation } from 'react-i18next'
import { useDispatch } from 'react-redux'
import Modal from '../../../ui/Modal'
import WSActions from '../../../redux/actions/ws'

const CleanBacktestResultsModal = ({
onClose,
isOpen,
nextStrategy,
onLoadStrategy,
}) => {
const { t } = useTranslation()

const dispatch = useDispatch()

const clearBacktestOptions = () => {
dispatch(WSActions.resetBacktestData())
}
const onSubmitReset = () => {
clearBacktestOptions()
onLoadStrategy(nextStrategy, true)
onClose()
}

return (
<Modal
isOpen={isOpen}
onClose={onClose}
label={t('strategyEditor.clearBacktestResultsModalTitle')}
onSubmit={onClose}
>
<p>{t('strategyEditor.clearBacktestResultsModalText')}</p>
<Modal.Footer>
<Modal.Button primary onClick={onClose}>
{t('ui.cancel')}
</Modal.Button>
<Modal.Button secondary onClick={onSubmitReset}>
{t('ui.proceed')}
</Modal.Button>
</Modal.Footer>
</Modal>
)
}

CleanBacktestResultsModal.propTypes = {
onClose: PropTypes.func.isRequired,
isOpen: PropTypes.bool.isRequired,
nextStrategy: PropTypes.shape({
label: PropTypes.string,
}),
onLoadStrategy: PropTypes.func.isRequired,
}

CleanBacktestResultsModal.defaultProps = {
nextStrategy: {},
}

export default memo(CleanBacktestResultsModal)
3 changes: 3 additions & 0 deletions src/modals/Strategy/ClearBacktestResultsModal/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ClearBacktestResultsModal from './ClearBacktestResultsModal'

export default ClearBacktestResultsModal
3 changes: 2 additions & 1 deletion src/pages/Strategies/Strategies.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import UIActions from '../../redux/actions/ui'
import WSActions from '../../redux/actions/ws'

import StrategiesPage from './Strategies'
import { getAuthToken } from '../../redux/selectors/ws'
import { getAuthToken, getBacktestResults } from '../../redux/selectors/ws'

const mapStateToProps = (state) => ({
authToken: getAuthToken(state),
firstLogin: getFirstLogin(state),
isGuideActive: getGuideStatusForPage(state, STRATEGY_PAGE),
strategyContent: getStrategyContent(state),
backtestResults: getBacktestResults(state),
})

const mapDispatchToProps = (dispatch) => ({
Expand Down
21 changes: 20 additions & 1 deletion src/pages/Strategies/Strategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import SaveUnsavedChangesModal from '../../modals/Strategy/SaveUnsavedChangesMod
import RemoveExistingStrategyModal from '../../modals/Strategy/RemoveExistingStrategyModal'
import SaveStrategyAsModal from '../../modals/Strategy/SaveStrategyAsModal/SaveStrategyAsModal'
import { getDefaultStrategyOptions } from '../../components/StrategyEditor/StrategyEditor.helpers'
import ClearBacktestResultsModal from '../../modals/Strategy/ClearBacktestResultsModal'

import './style.css'

Expand All @@ -41,6 +42,7 @@ const StrategiesPage = ({
authToken,
onSave,
onRemove,
backtestResults: { finished },
}) => {
const [strategy, setStrategy] = useState(strategyContent)
const [indicators, setIndicators] = useState([])
Expand All @@ -51,6 +53,7 @@ const StrategiesPage = ({
const [isRemoveModalOpened, setIsRemoveModalOpened] = useState(false)
const [isSaveStrategyAsModalOpen, setIsSaveStrategyAsModalOpen] = useState(false)
const [isRenameStrategyModalOpen, setIsRenameStrategyModalOpen] = useState(false)
const [isClearBacktestResultsModalOpen, setIsClearBacktestResultsOpen] = useState(false)
const [actionStrategy, setActionStrategy] = useState({})
const [nextStrategyToOpen, setNextStrategyToOpen] = useState(null)

Expand Down Expand Up @@ -187,6 +190,11 @@ const StrategiesPage = ({
setIsUnsavedStrategyModalOpen(true)
return
}
if (finished && !forcedLoad) {
setNextStrategyToOpen(strategyToLoad)
setIsClearBacktestResultsOpen(true)
return
}
if (!_isEmpty(strategyToLoad) && _isEmpty(strategyToLoad.strategyOptions)) {
strategyToLoad.strategyOptions = getDefaultStrategyOptions()
}
Expand All @@ -209,6 +217,8 @@ const StrategiesPage = ({
setIsRemoveModalOpened(false)
setIsSaveStrategyAsModalOpen(false)
setIsRenameStrategyModalOpen(false)
setIsClearBacktestResultsOpen(false)
setIsUnsavedStrategyModalOpen(false)
}

const removeStrategy = () => {
Expand Down Expand Up @@ -288,7 +298,7 @@ const StrategiesPage = ({
/>
<SaveUnsavedChangesModal
isOpen={isUnsavedStrategyModalOpen}
onClose={() => setIsUnsavedStrategyModalOpen(false)}
onClose={onCloseModals}
strategy={strategy}
nextStrategy={nextStrategyToOpen}
onLoadStrategy={onLoadStrategy}
Expand All @@ -312,6 +322,12 @@ const StrategiesPage = ({
onRemoveStrategy={removeStrategy}
strategy={actionStrategy}
/>
<ClearBacktestResultsModal
isOpen={isClearBacktestResultsModalOpen}
onClose={onCloseModals}
nextStrategy={nextStrategyToOpen}
onLoadStrategy={onLoadStrategy}
/>
</Layout.Main>
<Layout.Footer />
</Layout>
Expand All @@ -328,6 +344,9 @@ StrategiesPage.propTypes = {
authToken: PropTypes.string.isRequired,
onSave: PropTypes.func.isRequired,
onRemove: PropTypes.func.isRequired,
backtestResults: PropTypes.shape({
finished: PropTypes.bool,
}).isRequired,
}

StrategiesPage.defaultProps = {
Expand Down
1 change: 1 addition & 0 deletions src/redux/reducers/ws/backtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function getInitialState() {
currentTest: null,
loading: false,
executing: false,
finished: false,
trades: [],
candles: [],
gid: null,
Expand Down

0 comments on commit 755f7dd

Please sign in to comment.