Skip to main content

Method Signature

async createLimitOrder(params: CreateLimitOrderParams): Promise<CreateOrderResult>
Creates a limit order on a market. A limit order sits on the orderbook at your specified price until matched or cancelled. Slippage is 0 — the order executes only at your exact price.

Parameters

marketAppId
number
required
The market application ID on Algorand
position
0 | 1
required
The position to trade: 1 for Yes, 0 for No
price
number
required
Price in microunits (e.g., 500_000 = $0.50). Must be between 0 and 1,000,000.
quantity
number
required
Quantity in microunits (e.g., 1_000_000 = 1 share)
isBuying
boolean
required
Whether this is a buy order (true) or sell order (false)
feeBase
number
Fee base in microunits (e.g., 70_000 = 7%). If omitted, reads from market’s on-chain global state.

Return Type

type CreateOrderResult = {
  escrowAppId: number;
  txIds: string[];
  confirmedRound: number;
  matchedQuantity?: number;
  matchedPrice?: number;
}
escrowAppId
number
The escrow app ID of the newly created order
txIds
string[]
Array of transaction IDs from the atomic group
confirmedRound
number
The confirmed round number on the blockchain
matchedQuantity
number
Total quantity that was immediately matched (in microunits). For limit orders, this is non-zero if there were matching counterparty orders at your exact price.
matchedPrice
number
Volume-weighted average fill price in microunits. Accounts for complementary matching (e.g., 1,000,000 - noPrice for YES buys).

Example

import { AlphaClient } from '@alpha-arcade/sdk';
import algosdk from 'algosdk';

const account = algosdk.mnemonicToSecretKey(process.env.MNEMONIC!);
const algodClient = new algosdk.Algodv2('', 'https://mainnet-api.algonode.cloud', 443);
const indexerClient = new algosdk.Indexer('', 'https://mainnet-idx.algonode.cloud', 443);

const client = new AlphaClient({
  algodClient,
  indexerClient,
  signer: algosdk.makeBasicAccountTransactionSigner(account),
  activeAddress: account.addr.toString(),
  matcherAppId: 741347297,
  usdcAssetId: 31566704,
  apiKey: process.env.ALPHA_API_KEY!,
});

// Fetch a market
const markets = await client.getLiveMarkets();
const market = markets[0];

// Place a limit buy order: 1 Yes share at $0.10
const result = await client.createLimitOrder({
  marketAppId: market.marketAppId,
  position: 1,          // Yes
  price: 100_000,       // $0.10
  quantity: 1_000_000,  // 1 share
  isBuying: true,
});

console.log(`Order created! Escrow: ${result.escrowAppId}`);
console.log(`Matched quantity: ${(result.matchedQuantity ?? 0) / 1e6} shares`);

Behavior Notes

  • Zero Slippage: Limit orders execute only at your exact price. They will not match against less favorable prices.
  • Immediate Matching: If there are existing counterparty orders at your price or better, your limit order will immediately match against them. The remaining quantity (if any) sits on the orderbook.
  • Collateral Requirements:
    • Buy orders: Require USDC equal to (quantity * price / 1,000,000) + fee
    • Sell orders: Require outcome tokens equal to quantity
  • Asset Opt-in: The SDK automatically opts-in to required assets (USDC or outcome tokens) if needed.
  • Escrow Creation: Each order creates a new escrow application (957,000 microAlgos MBR) which is returned when the order is cancelled or fully filled.

Build docs developers (and LLMs) love