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

[WIP] added different exit startegy selection in case of winning and losing for combined SL #59

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
82 changes: 54 additions & 28 deletions components/lib/SlManagerComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import {
RadioGroup,
Radio,
Grid,
TextField
TextField,
Box
} from '@material-ui/core'
import { COMBINED_SL_EXIT_STRATEGY, SL_ORDER_TYPE } from '../../types/plans'
import {
COMBINED_SL_EXIT_STRATEGY_LABEL,
EXIT_STRATEGIES,
EXIT_STRATEGIES_DETAILS
EXIT_STRATEGIES_DETAILS,
POSITION_STATE,
POSITION_STATE_LABEL
} from '../../lib/constants'

const SlManagerComponent = ({ state, onChange, exitStrategies }) => {
Expand Down Expand Up @@ -52,33 +55,56 @@ const SlManagerComponent = ({ state, onChange, exitStrategies }) => {
<FormLabel component='legend'>
When Combined trailing SL triggers
</FormLabel>
<RadioGroup
aria-label='combinedExitStrategy'
name='combinedExitStrategy'
value={state.combinedExitStrategy}
onChange={e =>
onChange({
combinedExitStrategy: e.target
.value as COMBINED_SL_EXIT_STRATEGY
})
}
>
{[
COMBINED_SL_EXIT_STRATEGY.EXIT_ALL,
COMBINED_SL_EXIT_STRATEGY.EXIT_LOSING
].map(combinedExitStrategy => (
<FormControlLabel
key={combinedExitStrategy}
value={combinedExitStrategy}
control={<Radio size='small' />}
label={
<Typography variant='body2'>
{COMBINED_SL_EXIT_STRATEGY_LABEL[combinedExitStrategy]}
</Typography>
{[POSITION_STATE.WINNING, POSITION_STATE.LOSING].map(item => (
<Box pl={2} pt={1} key={item}>
<FormLabel component='legend'>
{POSITION_STATE_LABEL[item]}
</FormLabel>
<RadioGroup
aria-label='combinedExitStrategy'
name='combinedExitStrategy'
value={
item === POSITION_STATE.WINNING
? state.combinedExitStrategyWinning
: state.combinedExitStrategyLosing
}
/>
))}
</RadioGroup>
style={{ paddingLeft: '4px' }}
onChange={e =>
onChange(
item === POSITION_STATE.WINNING
? {
combinedExitStrategyWinning: e.target
.value as COMBINED_SL_EXIT_STRATEGY
}
: {
combinedExitStrategyLosing: e.target
.value as COMBINED_SL_EXIT_STRATEGY
}
)
}
>
{[
COMBINED_SL_EXIT_STRATEGY.EXIT_ALL,
COMBINED_SL_EXIT_STRATEGY.EXIT_LOSING
].map(combinedExitStrategy => (
<FormControlLabel
key={combinedExitStrategy}
value={combinedExitStrategy}
control={<Radio size='small' />}
label={
<Typography variant='body2'>
{
COMBINED_SL_EXIT_STRATEGY_LABEL[
combinedExitStrategy
]
}
</Typography>
}
/>
))}
</RadioGroup>
</Box>
))}
</Grid>

<Grid item xs={12}>
Expand Down
24 changes: 10 additions & 14 deletions lib/browserUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ export const formatFormDataForApi = ({
strategy: string
data: AvailablePlansConfig
}): SUPPORTED_TRADE_CONFIG | null => {
const getOnSquareOffSetAborted = ({ exitStrategy, combinedExitStrategy }) =>
exitStrategy === EXIT_STRATEGIES.MULTI_LEG_PREMIUM_THRESHOLD &&
combinedExitStrategy === COMBINED_SL_EXIT_STRATEGY.EXIT_ALL

switch (strategy) {
case STRATEGIES.DIRECTIONAL_OPTION_SELLING: {
const {
Expand Down Expand Up @@ -169,7 +165,9 @@ export const formatFormDataForApi = ({
trailEveryPercentageChangeValue,
trailingSlPercent,
exitStrategy,
combinedExitStrategy
combinedExitStrategy,
combinedExitStrategyLosing,
combinedExitStrategyWinning
} = data as ATM_STRADDLE_CONFIG

const apiProps: ATM_STRADDLE_TRADE = {
Expand All @@ -180,12 +178,10 @@ export const formatFormDataForApi = ({
trailEveryPercentageChangeValue
),
trailingSlPercent: Number(trailingSlPercent),
onSquareOffSetAborted: getOnSquareOffSetAborted({
exitStrategy,
combinedExitStrategy
}),
maxSkewPercent: Number(maxSkewPercent),
thresholdSkewPercent: Number(thresholdSkewPercent),
combinedExitStrategyLosing,
combinedExitStrategyWinning,
...getSchedulingApiProps({
isAutoSquareOffEnabled,
squareOffTime,
Expand All @@ -212,7 +208,9 @@ export const formatFormDataForApi = ({
trailingSlPercent,
exitStrategy,
expireIfUnsuccessfulInMins,
combinedExitStrategy
combinedExitStrategy,
combinedExitStrategyLosing,
combinedExitStrategyWinning
} = data as ATM_STRANGLE_CONFIG

const apiProps: ATM_STRANGLE_TRADE = {
Expand All @@ -223,11 +221,9 @@ export const formatFormDataForApi = ({
trailEveryPercentageChangeValue
),
trailingSlPercent: Number(trailingSlPercent),
onSquareOffSetAborted: getOnSquareOffSetAborted({
exitStrategy,
combinedExitStrategy
}),
inverted: Boolean(inverted),
combinedExitStrategyLosing,
combinedExitStrategyWinning,
...getSchedulingApiProps({
isAutoSquareOffEnabled,
squareOffTime,
Expand Down
14 changes: 14 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ export enum ANCILLARY_TASKS {
CLEANUP_COMPLETED_JOBS = 'CLEANUP_COMPLETED_JOBS'
}

export enum POSITION_STATE {
WINNING = 'WINNING',
LOSING = 'LOSING'
}

export const POSITION_STATE_LABEL = {
[POSITION_STATE.WINNING]: 'If winning',
[POSITION_STATE.LOSING]: 'If losing'
}

export const COMBINED_SL_EXIT_STRATEGY_LABEL = {
[COMBINED_SL_EXIT_STRATEGY.EXIT_ALL]: 'Exit all legs',
[COMBINED_SL_EXIT_STRATEGY.EXIT_LOSING]:
Expand Down Expand Up @@ -133,6 +143,8 @@ export const STRATEGIES_DETAILS = {
slOrderType: SL_ORDER_TYPE.SLM,
slLimitPricePercent: 1,
combinedExitStrategy: COMBINED_SL_EXIT_STRATEGY.EXIT_ALL,
combinedExitStrategyWinning: COMBINED_SL_EXIT_STRATEGY.EXIT_ALL,
combinedExitStrategyLosing: COMBINED_SL_EXIT_STRATEGY.EXIT_ALL,
rollback: {
onBrokenHedgeOrders: false,
onBrokenPrimaryOrders: false,
Expand Down Expand Up @@ -169,6 +181,8 @@ export const STRATEGIES_DETAILS = {
slOrderType: SL_ORDER_TYPE.SLM,
slLimitPricePercent: 1,
combinedExitStrategy: COMBINED_SL_EXIT_STRATEGY.EXIT_ALL,
combinedExitStrategyWinning: COMBINED_SL_EXIT_STRATEGY.EXIT_ALL,
combinedExitStrategyLosing: COMBINED_SL_EXIT_STRATEGY.EXIT_ALL,
rollback: {
onBrokenHedgeOrders: false,
onBrokenPrimaryOrders: false,
Expand Down
Loading