PaymentRunTradesCreator
Creates CEX trades to convert coins into the payout currency for a PaymentRun.
Flow
run()
│
├─► isPayoutComplete? ──yes──► return (allCreated=true)
│
▼
findExistingTrades(byMotive) → findRatesWithMissingTrades → findPartnerApp
│ │
│ not found ◄───────┘
│ │
│ ▼
│ return (allCreated=false)
▼
FOR EACH rate with missing trades:
│
└─► createTradesForRate
│
├─► no provider ──► skip
├─► no vault ──────► skip
├─► no balance ────► skip
├─► no rate ───────► skip
│
└─► success ──► executeTradeSteps ──► collect trades
│
▼
updatePaymentRunWithTrades → return resultResume Logic
When trades are partially complete, findTradeStepsResumePoint determines where to continue:
| State | Action |
|---|---|
| All steps have trades | Skip (return []) |
| No trades exist | Start from beginning with initial amount |
| Partial trades | Resume from next step using previous trade.toAmount |
Concepts
| Term | Meaning |
|---|---|
| Rate | Coin + amount + provider (CEX) to trade from |
| Trade Path | Multi-hop conversion, e.g., BTC → USDT → EUR |
| Vault Balance | Caps trade amount to available CEX vault balance |
