Skip to main content
During development, you can use the developer endpoints without an API key. For production use, you’ll need an API key to avoid rate limits.
Decrease a position by trading YES or NO outcome tokens back into a settlement stablecoin. Submit a trade, and the system opens a reduce order, routes to offchain liquidity, and settles onchain.
1

Choose an Outcome Token

Start with the outcome mint you want to reduce. If you need to find outcome mints first, use Discover Prediction Markets.
2

Request a Reduce Trade

Request a trade from the outcome token into a settlement mint using /order. This opens a reduce order and writes your limit price and side (YES or NO) into the Reduce Order Escrow account while escrowes your outcome tokens.Reduce Position
const API_BASE_URL = "https://dev-quote-api.dflow.net";
const API_KEY = process.env.DFLOW_API_KEY; // Optional

const outcomeMint = "OUTCOME_TOKEN_MINT_ADDRESS";
const settlementMint = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"; // USDC
const amount = 5_000_000; // 5 outcome tokens (6 decimals)

const queryParams = new URLSearchParams();
queryParams.append("inputMint", outcomeMint);
queryParams.append("outputMint", settlementMint);
queryParams.append("amount", amount.toString());
queryParams.append("userPublicKey", keypair.publicKey.toBase58());

const headers: HeadersInit = {};
if (API_KEY) {
  headers["x-api-key"] = API_KEY;
}

const orderResponse = await fetch(
  `${API_BASE_URL}/order?${queryParams.toString()}`,
  { headers }
).then((x) => x.json());
3

Sign and Submit the Transaction

Sign the transaction returned by /order and submit it to Solana.
const transactionBuffer = Buffer.from(orderResponse.transaction, "base64");
const transaction = VersionedTransaction.deserialize(transactionBuffer);

transaction.sign([keypair]);
const signature = await connection.sendTransaction(transaction);
4

Monitor Order Status

Poll /order-status for async orders. This returns fills and the final status.
const statusResponse = await fetch(
  `${API_BASE_URL}/order-status?signature=${signature}`,
  { headers }
).then((x) => x.json());

console.log(statusResponse.status, statusResponse.fills);
5

Fill the Reduce Order

You do not call a separate endpoint to fill the order. The settlement authority reads your limit price and side from Reduce Order Escrow, submits a limit IOC to offchain liquidity, and settles onchain. Depending on reserve balance, the system follows one of two paths:
When reserves are balanced, the order settles immediately. Unused outcome tokens are refunded, platform fees are transferred, and stablecoins move from the Settlement Vault to your wallet.Fund Reduce Position
When reserves are not balanced, the order fills without immediate settlement. Unused outcome tokens are refunded. Later, when reserves rebalance, the settlement authority completes settlement, transfers stablecoins to your wallet, and pays platform fees.Settle Reduce PositionFund Reduce Position
A limit IOC (Immediate‑Or‑Cancel) order executes immediately at the limit price (or better) for whatever size is available right now. Any unfilled portion is canceled instead of resting on the book.

API Routes

Cookbook Repository

This recipe, along with many more, is available in the DFlow Cookbook Repo. You can clone it and start coding immediately.