> ## Documentation Index
> Fetch the complete documentation index at: https://pond.dflow.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Add Platform Fees

> How to add platform fees to prediction market outcome token trades

<Info>
  During development, you can use the [developer endpoints](/get-started/endpoints) without an API key. For production use, [request an API key](/get-started/api-key) for higher rate limits.
</Info>

Prediction market outcome token trades use [`platformFeeScale`](/resources/trading-api/order/order#parameter-platform-fee-scale), not `platformFeeBps`. The fee is calculated dynamically using the formula `k * p * (1 - p) * c`, where `k` is `platformFeeScale / 1000`, `p` is the outcome token price (0–1), and `c` is the trade volume. `platformFeeMode` is ignored for outcome token trades; the fee is always collected in the [settlement mint](/prediction-markets/prediction-market-data-model).

<Steps>
  <Step title="Set up">
    Imports, env config, and the wallet used across every step.

    <AccordionGroup>
      <Accordion title="Imports, env, and wallet">
        ```typescript theme={null}
        import "dotenv/config";

        import { Keypair } from "@solana/web3.js";
        import bs58 from "bs58";

        const DFLOW_TRADE_API_URL = process.env.DFLOW_TRADE_API_URL ?? "https://dev-quote-api.dflow.net";
        const DFLOW_API_KEY = process.env.DFLOW_API_KEY; // optional; not needed for dev endpoints
        const DFLOW_SETTLEMENT_MINT = process.env.DFLOW_SETTLEMENT_MINT ?? "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"; // USDC

        const keypair = Keypair.fromSecretKey(
          bs58.decode(process.env.SOLANA_PRIVATE_KEY ?? "")
        );

        const headers: HeadersInit = {};
        if (DFLOW_API_KEY) headers["x-api-key"] = DFLOW_API_KEY;
        ```
      </Accordion>
    </AccordionGroup>
  </Step>

  <Step title="Request an order with platformFeeScale">
    <AccordionGroup>
      <Accordion title="Request an order with a dynamic fee">
        ```typescript theme={null}
        const outcomeMint = "OUTCOME_TOKEN_MINT_ADDRESS";

        const queryParams = new URLSearchParams();
        queryParams.append("inputMint", DFLOW_SETTLEMENT_MINT);
        queryParams.append("outputMint", outcomeMint);
        queryParams.append("amount", "1000000"); // 1 USDC (6 decimals)
        queryParams.append("platformFeeScale", "50"); // k = 0.050 in formula k * p * (1 - p) * c
        queryParams.append("feeAccount", "YourSettlementMintTokenAccountAddress");
        queryParams.append("userPublicKey", keypair.publicKey.toBase58());

        const orderResponse = await fetch(
          `${DFLOW_TRADE_API_URL}/order?${queryParams.toString()}`,
          { headers }
        ).then((r) => r.json());
        ```
      </Accordion>
    </AccordionGroup>
  </Step>

  <Step title="Fee account setup">
    The [`feeAccount`](/resources/trading-api/order/order#parameter-fee-account) parameter is required and must be a token account that holds the settlement mint (USDC or CASH). Outcome token accounts cannot receive the fee.

    <Warning>
      The fee account must match the settlement mint. Outcome tokens themselves cannot be used as fee accounts.
    </Warning>
  </Step>

  <Step title="Check fee in response">
    The `/order` response includes a `platformFee` object showing the calculated fee.

    <AccordionGroup>
      <Accordion title="Reading platform fee from response">
        ```typescript theme={null}
        if (orderResponse.platformFee) {
          console.log("Platform fee details:", {
            amount: orderResponse.platformFee.amount,
            feeBps: orderResponse.platformFee.feeBps,
            feeAccount: orderResponse.platformFee.feeAccount,
          });
        }
        ```
      </Accordion>
    </AccordionGroup>
  </Step>
</Steps>

## Related Resources

<CardGroup cols={2}>
  <Card title="Buy Outcome Tokens" href="/prediction-markets/recipes/buy-outcome-tokens" icon="wallet">
    Open a prediction market position from any input token.
  </Card>

  <Card title="Prediction Market Fees" href="/prediction-markets/prediction-market-fees" icon="percent">
    How fees work for prediction markets, including the dynamic fee formula.
  </Card>

  <Card title="Add Platform Fees (Spot)" href="/spot/recipes/platform-fees" icon="arrow-right-arrow-left">
    Add fees to standard spot swaps with `platformFeeBps`.
  </Card>

  <Card title="Authenticate Requests" href="/resources/recipes/api-keys" icon="key">
    Authenticate requests for production rate limits.
  </Card>
</CardGroup>

## API Routes

* [GET /order](/resources/trading-api/order/order)
