> ## 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.

# Change Position Size

> How to increase or decrease a prediction market position

<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>

To increase, trade an input token (USDC, CASH, or any SPL) into the outcome token. To decrease, flip the mints. Both directions use the same `/order` endpoint.

## Increase

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

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

        import { Connection, Keypair, VersionedTransaction } 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 SOLANA_RPC_URL = process.env.SOLANA_RPC_URL ?? "https://api.mainnet-beta.solana.com";

        const connection = new Connection(SOLANA_RPC_URL, "confirmed");
        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">
    <AccordionGroup>
      <Accordion title="Request an order">
        ```typescript theme={null}
        const outcomeMint = "OUTCOME_TOKEN_MINT_ADDRESS";
        const amount = 25_000_000; // 25 USDC (6 decimals)

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

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

  <Step title="Sign and submit">
    <AccordionGroup>
      <Accordion title="Sign and submit">
        ```typescript theme={null}
        const txBuffer = Buffer.from(orderResponse.transaction, "base64");
        const transaction = VersionedTransaction.deserialize(txBuffer);

        transaction.sign([keypair]);

        const signature = await connection.sendRawTransaction(transaction.serialize(), {
          skipPreflight: true,
          maxRetries: 2,
        });
        console.log(`  Tx: https://orbmarkets.io/tx/${signature}`);

        await connection.confirmTransaction({
          signature,
          blockhash: transaction.message.recentBlockhash,
          lastValidBlockHeight: orderResponse.lastValidBlockHeight,
        });
        ```
      </Accordion>
    </AccordionGroup>
  </Step>

  <Step title="Check order status">
    <AccordionGroup>
      <Accordion title="Check order status">
        ```typescript theme={null}
        const status = await fetch(
          `${DFLOW_TRADE_API_URL}/order-status?signature=${signature}`,
          { headers }
        ).then((r) => r.json());

        console.log(status.status, status.fills);
        ```
      </Accordion>
    </AccordionGroup>
  </Step>
</Steps>

## Decrease

<Steps>
  <Step title="Request an order">
    <AccordionGroup>
      <Accordion title="Request an order">
        ```typescript theme={null}
        // Reuses DFLOW_TRADE_API_URL, DFLOW_SETTLEMENT_MINT, headers, and keypair from the setup above.
        const decOutcomeMint = "OUTCOME_TOKEN_MINT_ADDRESS";
        const decAmount = 5_000_000; // 5 outcome tokens (6 decimals)

        const decParams = new URLSearchParams();
        decParams.append("inputMint", decOutcomeMint);
        decParams.append("outputMint", DFLOW_SETTLEMENT_MINT);
        decParams.append("amount", decAmount.toString());
        decParams.append("userPublicKey", keypair.publicKey.toBase58());

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

  <Step title="Sign and submit">
    <AccordionGroup>
      <Accordion title="Sign and submit">
        ```typescript theme={null}
        const decTxBuffer = Buffer.from(decOrderResponse.transaction, "base64");
        const decTransaction = VersionedTransaction.deserialize(decTxBuffer);

        decTransaction.sign([keypair]);

        const decSignature = await connection.sendRawTransaction(decTransaction.serialize(), {
          skipPreflight: true,
          maxRetries: 2,
        });
        console.log(`  Tx: https://orbmarkets.io/tx/${decSignature}`);

        await connection.confirmTransaction({
          signature: decSignature,
          blockhash: decTransaction.message.recentBlockhash,
          lastValidBlockHeight: decOrderResponse.lastValidBlockHeight,
        });
        ```
      </Accordion>
    </AccordionGroup>
  </Step>

  <Step title="Check order status">
    <AccordionGroup>
      <Accordion title="Check order status">
        ```typescript theme={null}
        const decStatus = await fetch(
          `${DFLOW_TRADE_API_URL}/order-status?signature=${decSignature}`,
          { headers }
        ).then((r) => r.json());

        console.log(decStatus.status, decStatus.fills);
        ```
      </Accordion>
    </AccordionGroup>
  </Step>

  <Step title="Settlement">
    Reduce orders settle via one of two paths depending on reserve balance.

    <AccordionGroup>
      <Accordion title="Synchronous">
        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.
      </Accordion>

      <Accordion title="Asynchronous">
        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 and transfers stablecoins to your wallet.
      </Accordion>
    </AccordionGroup>
  </Step>
</Steps>

## Related Resources

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

  <Card title="Redeem Outcome Tokens" href="/prediction-markets/recipes/redeem-outcome-tokens" icon="check-circle">
    Complete redemption flow including scalar outcome payouts.
  </Card>

  <Card title="Track User Positions" href="/prediction-markets/recipes/track-positions" icon="chart-line">
    Map wallet balances back to markets and outcomes.
  </Card>

  <Card title="Market Lifecycle" href="/prediction-markets/market-lifecycle" icon="clock">
    States a market moves through and what each one allows.
  </Card>
</CardGroup>

## API Routes

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