Our system (QD) incorporates a mechanism designed for transferring indexed states for events such as: Candle, Order.
The fundamental operation of this mechanism involves transferring a snapshot initially and subsequently applying incremental updates to this snapshot.
Candle event is an indexed event in our system that contains specific fields such as:
- flags - flags for processing updates
- index - event index, which represents order of the event
Note: Events arrive in a special order in which order these events need to be handled so as not to break the sequence of state.
Here is a description of the algorithm how to work with our indexed events:
-
Set up a pending queue for indexed market events.
-
Create variables to control state:
Transaction
: Indicates transaction processing.SnapshotFull
: Indicates full snapshot acquisition in the queue.SnapshotPart
: Indicates the process of getting a snapshot in the queue.
-
Set up a listener for incoming events.
-
Subscribe to events for the required instrument.
-
For each indexed event received, in order:
5.1. If the
eventFlags
field value hasSNAPSHOT_BEGIN
, then: - Clear the pending queue. - SetSnapshotPart = true
andSnapshotFull = false
.5.2. If the
eventFlags
field value hasSNAPSHOT_END
andSnapshotPart
is true, then: - SetSnapshotPart = false
andSnapshotFull = true
.5.3. If the
eventFlags
field value hasTX_PENDING
, then: - SetTransaction = true
. Otherwise, setTransaction = false
.5.4. Add the event to the pending queue.
-
If
SnapshotPart
is true orTransaction
is true, proceed to step 10. -
If
SnapshotFull
is true, then:- Remove state (previous events).
- Set
SnapshotFull = false
.
-
For each event in the pending queue:
8.1. If the event has the
REMOVE_EVENT
flag, then: - Remove the event with this index from the state.8.2. Otherwise, add or update the event with this index to the state.
-
Clear the pending queue.
-
Wait for the next events, then go back to step 5.