Skip to content

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 result

Resume Logic

When trades are partially complete, findTradeStepsResumePoint determines where to continue:

StateAction
All steps have tradesSkip (return [])
No trades existStart from beginning with initial amount
Partial tradesResume from next step using previous trade.toAmount

Concepts

TermMeaning
RateCoin + amount + provider (CEX) to trade from
Trade PathMulti-hop conversion, e.g., BTC → USDT → EUR
Vault BalanceCaps trade amount to available CEX vault balance