Last active
July 5, 2020 15:32
-
-
Save disler/a765c21e6c20fe28fcb6850f576d415c to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const makeTradeInvalid = assign((c, e) => ({valid_trade: false})) | |
const fetchMachine = Machine({ | |
id: 'trade', | |
initial: 'begin_trade', | |
context: { | |
valid_trade: true, | |
}, | |
states: { | |
begin_trade: { | |
on: { | |
find_trade: 'trade_identified' | |
} | |
}, | |
trade_identified: { | |
on: { | |
'is_valid_trade?': 'validate_trade', | |
} | |
}, | |
validate_trade: { | |
type: 'parallel', | |
states: { | |
momentum_direction: { | |
initial: 'in_direction_of_momentum?', | |
states: { | |
'in_direction_of_momentum?': { | |
on: { | |
Yes1: 'trade_is_BAD', | |
No1: 'trade_is_validated', | |
} | |
}, | |
trade_is_validated: { type: 'final'}, | |
trade_is_BAD: { type: 'final', entry: [ makeTradeInvalid] } | |
} | |
}, | |
have_day_trade: { | |
initial: 'have_day_trade?', | |
states: { | |
'have_day_trade?': { | |
on: { | |
Yes2: 'trade_is_validated', | |
No2: 'trade_is_BAD', | |
} | |
}, | |
trade_is_validated: {type: 'final'}, | |
trade_is_BAD: { type: 'final', entry: [ makeTradeInvalid] } | |
} | |
}, | |
stop_loss_and_profit_target_set: { | |
initial: 'have_stop_loss_and_profit_target_set?', | |
states: { | |
'have_stop_loss_and_profit_target_set?': { | |
on: { | |
Yes3: 'trade_is_validated', | |
No3: 'trade_is_BAD', | |
} | |
}, | |
trade_is_validated: {type: 'final' }, | |
trade_is_BAD: { type: 'final', entry: [ makeTradeInvalid] } | |
} | |
}, | |
}, | |
onDone: 'trade_is_validated?', | |
onError: 'trade_is_BAD', | |
}, | |
trade_is_BAD: { | |
on: { | |
awknolwedged: 'begin_trade' | |
} | |
}, | |
'trade_is_validated?': { | |
on: {'': | |
[ | |
{target: 'trade_is_validated', cond: (c) => {console.log(c.valid_trade === true); return c.valid_trade === true} }, | |
{target: 'trade_is_BAD', cond: ({valid_trade}) => valid_trade === false} | |
] | |
} | |
}, | |
trade_is_validated: { | |
on: { | |
take_position: 'position_created', | |
} | |
}, | |
position_created: { | |
on: { | |
stop_loss: 'sell_position', | |
profit_target: 'profit_target_hit' | |
} | |
}, | |
profit_target_hit: { | |
on: { | |
take_profits: 'sell_position', | |
increase_stop_loss: 'position_created' | |
} | |
}, | |
sell_position: { | |
on: { | |
position_sold: 'track_statistics' | |
} | |
}, | |
track_statistics: { | |
on: { | |
diciplined_trade: 'successful_trade?', | |
emotional_trade: 'stop_trading_for_today', | |
}, | |
}, | |
'successful_trade?': { | |
on: { | |
winning_trade: 'W', | |
losing_trade: 'analyze_trade' | |
} | |
}, | |
W: { | |
on: { | |
trade_again: 'begin_trade', | |
done: 'stop_trading_for_today', | |
} | |
}, | |
analyze_trade: { | |
on: { | |
trade_again: 'begin_trade', | |
done: 'stop_trading_for_today', | |
} | |
}, | |
stop_trading_for_today: { | |
type: 'final' | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment