4 ms·
> Are there well-known patterns to handle such situations? I'm not familiar with algorithmic trading so may be way off, but if I understand your problem correc
by friendzis 4y ago
> Are there well-known patterns to handle such situations?
I'm not familiar with algorithmic trading so may be way off, but if I understand your problem correctly, it sounds like you need what is called parallel states: state machine where a "state" is in itself a state machine. The trick here is that transition of one "leg" can be transition trigger for another leg. In your example you would have 4 states: "Executing trade leg A/B" and "Executing balancing trade". Suppose trade A fills first (a complex machine in itself), it triggers leg B to terminate and transition to balancing trade state while leg A would transition to completion state.
- bheadmaster 4y agoI think the problem with parallel states is the combinatorial explosion of the number of transitions - instead of having O(n) transitions, now you have O(n_1*n_2*...*n_k) transitions between all possible k-tuples of parallel states.
- friendzis 4y agoUm... No? Parallel (though hierarchical/recursive would be more fitting term) states are literally designed to fight combinatorial explosion of transitions. Qt docs provide nice, concise summary: https://doc.qt.io/qt-5/statemachine-api.html#using-parallel-states-to-avoid-a-combinatorial-explosion-of-states https://doc.qt.io/qt-5/statemachine-api.html#using-parallel-... Instead of transitioning on multiple parameters you decompose states into respective nested state machines to avoid this explosion