Skip to main content
The DFlow Trade API’s /order endpoint enables trading from any spot token to a prediction market outcome token, including market tokenization when needed.

Trading Flow Overview

When you want to trade a spot token for a prediction market outcome token, the /order endpoint orchestrates the entire transaction flow behind the scenes. The endpoint automatically:
  1. Detects whether the target market has been tokenized (initialized)
  2. Executes a two-step swap path: Input Token → Settlement Mint → Outcome Token
  3. Handles market tokenization if the market hasn’t been initialized yet
The /order endpoint accepts any spot token as inputMint and any outcome token mint as outputMint. The endpoint automatically constructs the appropriate transaction path based on the market’s initialization status.

Transaction Flow

All trades from spot tokens to outcome tokens follow a two-step swap path that route through the settlement mint as an intermediate step:
  1. Input Token → Settlement Mint
  2. Settlement Mint → Outcome Token
The /order endpoint returns a single transaction that executes both swaps.

Market Initialization States

The /order endpoint automatically detects whether the target market has been tokenized and handles the transaction accordingly:

Initialized Markets

When a market has already been tokenized, the transaction executes the two-step swap path directly: Input Token → Settlement Mint → Outcome Token

Uninitialized Markets

When a market hasn’t been tokenized yet, the /order endpoint automatically includes market tokenization in the transaction before executing the swap: Market Tokenization + (Input Token → Settlement Mint → Outcome Token) The transaction will:
  1. First perform on-demand market tokenization (creating the YES and NO outcome tokens on-chain)
  2. Then execute the two-step swap: Input Token → Settlement Mint → Outcome Token
On-demand market creation (tokenization) incurs a small fee. This fee is automatically included in the transaction when trading into an uninitialized market.

Checking Market Status

You can check a market’s initialization status using the Prediction Market Metadata API. The isInitialized field in the market response indicates whether the market has been tokenized:
  • isInitialized: true - Market is already tokenized; direct swap path
  • isInitialized: false - Market needs tokenization; transaction will include initialization
While you can check this status for informational purposes, the /order endpoint handles the detection automatically, so you don’t need to check beforehand.

Key Takeaways

  • The /order endpoint accepts any spot token as input and any outcome token as output
  • All trades execute through the settlement mint as an intermediate step: Input Token → Settlement Mint → Outcome Token
  • For initialized markets, the transaction executes the swap path directly
  • For uninitialized markets, the transaction includes market tokenization before executing the swap path
  • On-demand market creation (tokenization) incurs a small fee
  • The endpoint automatically detects market initialization status and constructs the appropriate transaction
  • You can check isInitialized via the metadata API