Skip to content

limitOrderProcess

---
config:
  theme: dark
---
sequenceDiagram
    title Limit Order (GTC & GTD only)
    participant User as User/SDK
    participant API as Orderbook API
    participant Sequencer
    participant Relayer as Relayer (Off-chain)

    Note over User,API: Limit Order Creation Flow

    User->>User: Create array of order(s)<br/>Includes timestamp
    User->>User: User signs EACH order in order array
    Note over User: Timestamp is a salt to prevent order duplication
    Note over User: User EOA signs on behalf of itself or a SAFE account

    User->>API: Submit order payload (GTC or GTD order type)

    loop Process Limit Orders - "promise all"
        Note over API: Validation Checks:<br/>• batch size <= 1000 - pessimistic<br/>• validate signatures - pessimistic<br/>• validate symbol/market - optimistic<br/>• check for self-crossing - optimistic<br/><br/>Batch orders process optimistically -<br/>orders failing validation are filtered out

        alt Post-Only = False
            API->>API: Fetch matching orders<br/>check for wash trading
            API->>Sequencer: Execute as IOC order<br/>up to limit price
            Note over API,Sequencer: Partial fill stat is updated if matching order(s) are not completely filled
            Sequencer->>Sequencer: Update SQL & BQ
            Sequencer-->>API: Reconcile orderbook state
            API->>API: Send fill confirmations
            Sequencer->>Relayer: Submit applicable settlement instructions
        else Post-Only = True
            API->>API: Reject if order crossed
            API->>API: Post GTC/GTD limit order
        end
    end
    API-->>User: Send status of all orders [posted, matched, rejected]