2.4 KiB
2.4 KiB
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:
- order processor:
does preliminary calculations and works on order like locking order - matching:
match orders and pass them to executor - trade executor:
execute trades that matching creates
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:
- it gets price and market and other informations
- create_trade_and_strike_orders
- get both orders
- get both needed accounts
- validate above informations
- initialize new trade with above data
- strike maker side
- change order attr like volume,locked,...
- unlocking funds and plus funds
- check order fill
- strike taker side
- change order attr like volume,locked,...
- check order fill
- create operations and accountings recorde
- record_liability_debit!
- record_liability_credit!
- record_liability_transfer!
- record_revenues!
- publish trade dependent on its state
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)