53 lines
1.4 KiB
Markdown
53 lines
1.4 KiB
Markdown
# trading: order processor
|
|
|
|
###### Sprint: ?
|
|
|
|
|
|
###DOC
|
|
for matching and executing orders openware creates a flow that manage by RabbitMQ and its consumers.
|
|
we have three consumers that works on trades:
|
|
1. order processor:<br >
|
|
does preliminary calculations and works on order like locking order<br >
|
|
2. matching:<br >
|
|
match orders and pass them to executor
|
|
3. trade executor:<br >
|
|
execute trades that matching creates
|
|
|
|
|
|
```mermaid
|
|
stateDiagram-v2
|
|
[*] --> API
|
|
API --> RabbitMQ
|
|
RabbitMQ --> OrderProcessor
|
|
OrderProcessor --> RabbitMQ
|
|
RabbitMQ --> Matching
|
|
Matching --> RabbitMQ
|
|
RabbitMQ --> Executor
|
|
Executor --> Notify
|
|
Notify --> [*]
|
|
```
|
|
|
|
#### Order Processor
|
|
##### what does order processor do step by step:
|
|
1. initializing: submit all orders with pending state(take them to ram)
|
|
2. submit:<br >
|
|
1. it finds order by id with lockversion
|
|
2. check state of order
|
|
3. update locked and balance of account
|
|
4. submit operation and accounting
|
|
5. update order state to WAIT
|
|
6. enqueue in rabbit (pass orders to matching)
|
|
|
|
```mermaid
|
|
graph TD
|
|
A[api] -->|enque| B(RabbitMQ)
|
|
B --> C(order processor)
|
|
C --> |submit order in ram|D{check state}
|
|
D -->|pending| E[order locking]
|
|
D -->|else| B
|
|
E -->G[submit operation and accounting]
|
|
G --> F[update state to wait]
|
|
F --> |enque to matching| B
|
|
|
|
```
|