Skip to content

Instantly share code, notes, and snippets.

@WJWang
Created April 25, 2021 20:03
Show Gist options
  • Save WJWang/5a924284f37196fd15a590b87a36d70e to your computer and use it in GitHub Desktop.
Save WJWang/5a924284f37196fd15a590b87a36d70e to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const spotFuture = Machine({
type: 'parallel',
states: {
'建立部位': {
initial: '現貨數 < 設定目標數',
states: {
'現貨數 < 設定目標數': {
on: {
'買現貨': '期貨空單數 < 現貨數',
},
},
'期貨空單數 < 現貨數': {
on: {
'空期貨': '期貨空單數 = 現貨數',
},
},
'期貨空單數 = 現貨數': {
on: {
'未達設定目標數': '現貨數 < 設定目標數',
'已達設定目標數': '結束建立部位',
},
},
'結束建立部位': { type: 'final' },
},
},
'減少部位': {
initial: '現貨數 > 預期降低目標數量',
states: {
'現貨數 > 預期降低目標數量': {
on: {
'賣現貨': '期貨空單數 < 現貨數',
},
},
'期貨空單數 < 現貨數': {
on: {
'買回期貨': '期貨空單數 = 現貨數',
},
},
'期貨空單數 = 現貨數': {
on: {
'未達預期降低目標數量': '現貨數 > 預期降低目標數量',
'已達預期降低目標數量': '結束減少部位',
},
},
'結束減少部位': { type: 'final' },
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment