Initial commit
This commit is contained in:
82
docs/zagros/order-trade-steps/executor.md
Normal file
82
docs/zagros/order-trade-steps/executor.md
Normal file
@@ -0,0 +1,82 @@
|
||||
# trading: trade executor
|
||||
|
||||
###### Sprint: ?
|
||||
|
||||
|
||||
###DOC
|
||||
* in case of reading first part processor or matching please skip this part.
|
||||
|
||||
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 --> [*]
|
||||
```
|
||||
|
||||
#### Trade executor
|
||||
##### what does trade executor do step by step:
|
||||
1. it gets price and market and other informations
|
||||
2. create_trade_and_strike_orders
|
||||
1. get both orders
|
||||
2. get both needed accounts
|
||||
3. validate above informations
|
||||
4. initialize new trade with above data
|
||||
5. strike maker side
|
||||
1. change order attr like volume,locked,...
|
||||
2. unlocking funds and plus funds
|
||||
2. check order fill
|
||||
6. strike taker side
|
||||
1. change order attr like volume,locked,...
|
||||
2. check order fill
|
||||
7. create operations and accountings recorde
|
||||
1. record_liability_debit!
|
||||
2. record_liability_credit!
|
||||
3. record_liability_transfer!
|
||||
4. record_revenues!
|
||||
8. publish trade dependent on its state
|
||||
|
||||
|
||||
|
||||
```mermaid
|
||||
graph TD
|
||||
A[RabbitMQ] -->|submit payload| B(executor)
|
||||
B --> |execute|C(get information about trade)
|
||||
C --> D(get both orders)
|
||||
D --> E(get both needed accounts)
|
||||
E --> F(validation on datas)
|
||||
F --> G(initialize new trade)
|
||||
G --> H( maker side)
|
||||
G --> I(taker side)
|
||||
H --> J(striker)
|
||||
I --> J
|
||||
J -->K(calculate incomes and fees)
|
||||
K --> L(update orders data like locked and volume,..)
|
||||
L --> M(unlock funds and plus incomes)
|
||||
M --> N{is order filled}
|
||||
N --> |yes|O(change state to done)
|
||||
O --> P(unlocked extra locked funds)
|
||||
N -->|no and market order|Q(cancell order)
|
||||
Q --> R(create operations record for cancellation)
|
||||
R --> S(create operation records)
|
||||
P --> S
|
||||
S --> T(record_liability_debit, record_liability_credit, record_liability_transfer, record_revenues)
|
||||
T --> U(save trade)
|
||||
U --> V(publish trade)
|
||||
|
||||
```
|
||||
Reference in New Issue
Block a user