Skip to main content

Querying Orders

Get a Single Order

import { Orderbook } from '@imtbl/orderbook';

const { result: order } = await orderbook.getListing(orderId);

console.log({
  id: order.id,
  status: order.status,
  price: order.buy.amount,
  seller: order.accountAddress,
  tokenId: order.sell.tokenId,
});

List Orders for a Collection

import { Orderbook, OrderStatusName } from '@imtbl/orderbook';

const { result } = await orderbook.listListings({
  sellItemContractAddress: NFT_CONTRACT,
  status: OrderStatusName.ACTIVE,
  pageSize: 50,
});

for (const listing of result) {
  console.log(`Token #${listing.sell.tokenId}: ${listing.buy.amount} IMX`);
}

Pagination

let cursor: string | undefined;

do {
  const { result, page } = await orderbook.listListings({
    sellItemContractAddress: NFT_CONTRACT,
    status: OrderStatusName.ACTIVE,
    pageSize: 100,
    pageCursor: cursor,
  });
  
  for (const listing of result) {
    console.log(listing.id);
  }
  
  cursor = page.nextCursor;
} while (cursor);

Order Status

Orders progress through these statuses:
StatusDescription
ACTIVEOrder is open and can be filled
FILLEDOrder has been completely filled
CANCELLEDOrder was cancelled by the maker
EXPIREDOrder passed its expiration time
INACTIVEOrder is temporarily unfillable
PENDINGOrder is being processed

Fill Status

Track how much of an order has been filled (relevant for ERC-1155 partial fills):
Fill StatusDescription
UNFILLEDNo fills yet
PARTIALSome quantity filled
FILLEDCompletely filled
const { result: order } = await orderbook.getListing(orderId);

console.log({
  fillStatus: order.fillStatus.name,
  numerator: order.fillStatus.numerator,   // Amount filled
  denominator: order.fillStatus.denominator, // Total amount
});

// For ERC-1155: Check remaining quantity
const remaining = 
  BigInt(order.fillStatus.denominator) - BigInt(order.fillStatus.numerator);
console.log(`${remaining} items still available`);

Cancelling Orders

Soft Cancel (Gasless)

Soft cancels are free and instant—the order is marked as cancelled off-chain:
import { Orderbook } from '@imtbl/orderbook';

const { result } = await orderbook.cancelOrders([orderId], address);
console.log('Order cancelled:', result);
Soft cancels are immediate but rely on marketplaces respecting the cancellation. The signature remains technically valid on-chain until expiration.

Hard Cancel (On-Chain)

Hard cancels invalidate the order on-chain. This costs gas but guarantees the order cannot be filled:
import { Orderbook } from '@imtbl/orderbook';

// Prepare the cancellation
const { signableAction } = await orderbook.prepareOrderCancellations([orderId]);

// Execute on-chain
const hash = await walletClient.sendTransaction({
  to: signableAction.to,
  data: signableAction.data,
});

await publicClient.waitForTransactionReceipt({ hash });
console.log('Order cancelled on-chain');

When to Use Each

ScenarioRecommended
User wants to cancel quicklySoft cancel
High-value orderHard cancel
Suspicious activityHard cancel
Order about to expireSoft cancel

Webhooks

Get real-time notifications for order events. Configure in Hub.
EventTrigger
imtbl_order_updatedOrder status changed
imtbl_activity_saleTrade completed

Webhook Payload Example

{
  "event_name": "imtbl_order_updated",
  "data": {
    "id": "order-123",
    "status": "FILLED",
    "sell": {
      "type": "ERC721",
      "contract_address": "0x...",
      "token_id": "456"
    },
    "buy": {
      "type": "NATIVE",
      "amount": "1000000000000000000"
    }
  }
}

Next Steps