Skip to main content

Overview

Fetches all open orders for a wallet address across every live market on Alpha Arcade. This method uses the Alpha REST API to efficiently retrieve orders without scanning the entire blockchain. Requires an API key. Retrieve your API key from the Alpha Arcade Account page.

Method Signature

async getWalletOrdersFromApi(walletAddress: string): Promise<OpenOrder[]>

Parameters

walletAddress
string
required
The Algorand wallet address to fetch orders for

Returns

Returns an array of OpenOrder objects from all markets:
escrowAppId
number
The escrow application ID for this order
marketAppId
number
The market application ID
position
0 | 1
The position: 0 for NO, 1 for YES
side
number
The order side: 0 for SELL, 1 for BUY
price
number
Order price in microunits (e.g., 500000 = $0.50)
quantity
number
Total order quantity in microunits (e.g., 1000000 = 1 share)
quantityFilled
number
Amount already filled in microunits
slippage
number
Slippage tolerance in microunits. 0 indicates a limit order
owner
string
Algorand address of the order owner

Example Usage

Basic Usage

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

const account = algosdk.mnemonicToSecretKey(process.env.TEST_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!, // Required
});

const walletAddress = account.addr.toString();
const orders = await client.getWalletOrdersFromApi(walletAddress);

if (orders.length === 0) {
  console.log('No open orders found.');
} else {
  console.log(`Found ${orders.length} open order(s)`);
}

Display Order Details

const orders = await client.getWalletOrdersFromApi(walletAddress);

for (const order of orders) {
  const side = order.side === 1 ? 'BUY' : 'SELL';
  const position = order.position === 1 ? 'YES' : 'NO';
  const price = order.price / 1e6;
  const qty = order.quantity / 1e6;
  const filled = order.quantityFilled / 1e6;
  const remaining = qty - filled;

  console.log(`Escrow ${order.escrowAppId} | Market ${order.marketAppId}`);
  console.log(`  ${side} ${position} @ $${price}`);
  console.log(`  Qty: ${qty} | Filled: ${filled} | Remaining: ${remaining}`);
  console.log();
}

Group Orders by Market

const orders = await client.getWalletOrdersFromApi(walletAddress);

// Group by market
const ordersByMarket = orders.reduce((acc, order) => {
  const marketId = order.marketAppId;
  if (!acc[marketId]) {
    acc[marketId] = [];
  }
  acc[marketId].push(order);
  return acc;
}, {} as Record<number, typeof orders>);

// Display summary
for (const [marketId, marketOrders] of Object.entries(ordersByMarket)) {
  console.log(`Market ${marketId}: ${marketOrders.length} order(s)`);
}

Calculate Total Exposure

const orders = await client.getWalletOrdersFromApi(walletAddress);

let totalExposure = 0;

for (const order of orders) {
  const remaining = order.quantity - order.quantityFilled;
  const orderValue = (remaining * order.price) / 1e12; // Convert to dollars
  totalExposure += orderValue;
}

console.log(`Total exposure in open orders: $${totalExposure.toFixed(2)}`);

Differences from getOpenOrders

FeaturegetOpenOrdersgetWalletOrdersFromApi
ScopeSingle marketAll markets
Data sourceOn-chain (indexer)Alpha REST API
Requires API keyNoYes
PerformanceSlower for one marketFaster for multiple markets
Use caseMarket-specific queriesPortfolio overview

Error Handling

try {
  const orders = await client.getWalletOrdersFromApi(walletAddress);
  console.log(`Found ${orders.length} orders`);
} catch (error) {
  if (error.message.includes('apiKey is required')) {
    console.error('Please set ALPHA_API_KEY in your environment');
  } else {
    console.error('API error:', error);
  }
}

Notes

  • Requires API key: You must configure apiKey in the AlphaClient constructor
  • Automatic pagination: The method handles pagination internally and returns all results
  • Cross-market queries: Efficiently fetches orders from all markets in a single call
  • Live data: Returns real-time order data from the Alpha API

Build docs developers (and LLMs) love