Skip to content

marketOrders

---
config:
  theme: dark
---
sequenceDiagram
    title Market Order (FOK & IOC only)
    actor A1 as User/SDK
    participant OB as Orderbook API
    participant Sequencer as Sequencer
    participant P1 as Relayer (Off-chain)

    Note over A1, OB: Market Order (Single Order) & Combo Flow
    A1 ->> A1: Create array of order(s)<br/>Includes timestamp
    A1 ->> A1: User provides single signature for order array
    Note over A1: Timestamp is a salt to prevent order duplication
    Note over A1: User EOA signs on behalf of itself or a SAFE account
    A1 ->> OB: Submit signed order payload (FOK or IOC order type)
    Note over A1, OB: Order Processing Flow

    alt FOK Order Type - "all or nothing"
        Note over OB: Validation checks:<br/>• validate signature<br/>• check order(s) are unique markets<br/>• validate symbol/market<br/>• max 6 option legs + 1 perp leg<br/>• NOTE: all or nothing for combos
        OB ->> OB: Fetch matching orders & check for wash trading
        OB ->> Sequencer: Send all matching orders that satisfy order requirements
        Note over OB, Sequencer: Partial fill state is updated if matching order is not completely filled
        alt FOK Failed Fill
            Note over OB: Order submission for combos is pessimistic<br/>ALL are fully fillable or All fail
            Sequencer ->> OB: Reconcile orderbook state
            OB ->> A1: Failed fill scenario: (FOK) end process
            A1 ->> OB: Re-attempt if intent still valid
        else FOK Successful Fill
            Sequencer ->> Sequencer: Update SQL & BQ
            Sequencer ->> OB: Reconcile orderbook state
            OB ->> A1: Send fill confirmation [optimistic trade confirmation]
            Sequencer ->> P1: Submit applicable settlement instructions
        end

    else IOC Order Type - partial fill allowed
        Note over OB: Validation checks:<br/>• validate signature<br/>• validate symbol/market<br/>• only single market orders allowed
        OB ->> OB: Fetch matching orders & check for wash trading
        OB ->> Sequencer: Send all matching orders that satisfy order requirements
        Note over OB, Sequencer: Partial fill state is updated if matching order is not completely filled
        alt IOC Failed Fill
            Sequencer ->> OB: Reconcile orderbook state
            OB ->> A1: Failed fill scenario: (IOC) end process
        else IOC Successful Fill
            Note over OB, Sequencer: Both partial and full fills<br/>follow the same success path
            Sequencer ->> Sequencer: Update SQL & BQ
            Sequencer ->> OB: Reconcile orderbook state
            OB ->> A1: Send fill confirmation [optimistic trade confirmation]
            Sequencer ->> P1: Submit applicable settlement instructions
        end
    end