Complete API reference for the TypeScript SDK (@opinion-labs/opinion-clob-sdk v0.5.2). All methods are async and use camelCase naming.
Market Data Methods
getMarkets
Get a paginated list of markets available for trading.
import{TopicType,TopicStatusFilter,TopicSortType}from'@opinion-labs/opinion-clob-sdk';constresult=awaitclient.getMarkets({topicType:TopicType.ALL,// Optional: BINARY, CATEGORICAL, ALL (default: ALL)page:1,// Optional: page number (default: 1)limit:20,// Optional: items per page (default: 20, max: 20)status:TopicStatusFilter.ACTIVATED,// Optional: ALL, ACTIVATED, RESOLVEDsortBy:TopicSortType.BY_VOLUME_DESC,// Optional: sorting method (default: BY_TIME_DESC)});console.log(result.result.total);// Total number of matching marketsconsole.log(result.result.list);// Array of market objects
Parameters:
Parameter
Type
Required
Description
topicType
TopicType
No
Filter by market type (default: ALL)
page
number
No
Page number, must be >= 1 (default: 1)
limit
number
No
Items per page, 1-20 (default: 20)
status
TopicStatusFilter
No
Filter by market status
sortBy
TopicSortType
No
Sorting method (default: BY_TIME_DESC)
Response: ApiResponse<MarketListResult> containing { total, list }.
getMarket
Get detailed information about a binary market.
Parameters:
Parameter
Type
Required
Description
marketId
number
Yes
Market ID
useCache
boolean
No
Use cached data if available (default: true)
Response: ApiResponse<MarketDetailResult> containing { data } with market details.
getCategoricalMarket
Get detailed information about a categorical market, including all child markets.
Parameters:
Parameter
Type
Required
Description
marketId
number
Yes
Categorical market ID
Response: ApiResponse<MarketDetailResult> containing { data } with market details and childMarkets array.
getQuoteTokens
Retrieve the list of supported quote tokens (currencies) on the platform.
Parameters:
Parameter
Type
Required
Description
useCache
boolean
No
Use cached data if available (default: true)
Response: ApiResponse<QuoteTokenListResult> containing { total, list }.
getOrderbook
Get the orderbook (market depth) for a specific token.
Parameters:
Parameter
Type
Required
Description
tokenId
string
Yes
Token ID (the outcome token to query)
Response: ApiResponse<OrderbookResponse> with bids, asks, and lastPrice.
Response fields:
Field
Description
symbol
Token ID
ts
Timestamp in milliseconds
bids
Array of [price, shares] for buy orders
asks
Array of [price, shares] for sell orders
lastPrice
Latest price from the last trade
getLatestPrice
Get the latest price for a specific token.
Parameters:
Parameter
Type
Required
Description
tokenId
string
Yes
Token ID
Response: ApiResponse<LatestPriceResponse>.
getPriceHistory
Get price history for a specific token.
Parameters:
Parameter
Type
Required
Description
tokenId
string
Yes
Token ID
interval
string
No
Time interval: '1m', '1h', '1d', '1w', 'max' (default: '1h')
startAt
number
No
Start timestamp (Unix seconds)
endAt
number
No
End timestamp (Unix seconds)
Response: ApiResponse<PriceHistoryResponse>.
getFeeRates
Get fee rates from the on-chain FeeManager contract for a specific token.
Parameters:
Parameter
Type
Required
Description
tokenId
string
Yes
Token ID
Response: FeeRateSettings object (not wrapped in ApiResponse since this is an on-chain call).
Trading Methods
placeOrder
Place a market or limit order.
Limit Buy Order (by quote token amount):
Limit Buy Order (by shares):
Market Buy Order:
Limit Sell Order:
Parameters:
Parameter
Type
Required
Description
data
PlaceOrderDataInput
Yes
Order details (see Models)
checkApproval
boolean
No
Check and enable trading first (default: false)
Response: ApiResponse<CreateOrderResponse> with order data including trans_no (order ID).
Successful response example:
placeOrdersBatch
Place multiple orders in batch. Orders are submitted sequentially. If one fails, the rest continue.
const result = await client.cancelOrder('504d7580-cd59-11ef-887f-0a58a9feac02');
console.log(result);
const orderIds = ['order_id_1', 'order_id_2', 'order_id_3'];
const results = await client.cancelOrdersBatch(orderIds);
for (const r of results) {
if (r.success) {
console.log(`Order ${r.index} cancelled`);
} else {
console.log(`Order ${r.index} failed:`, r.error);
}
}
import { OrderSide } from '@opinion-labs/opinion-clob-sdk';
// Cancel all open orders
const result = await client.cancelAllOrders();
// Cancel all open orders for a specific market
const result2 = await client.cancelAllOrders({ marketId: 57 });
// Cancel all open BUY orders
const result3 = await client.cancelAllOrders({ side: OrderSide.BUY });
// Cancel all open SELL orders for a specific market
const result4 = await client.cancelAllOrders({ marketId: 57, side: OrderSide.SELL });
console.log(result.totalOrders); // Total orders found
console.log(result.cancelled); // Successfully cancelled
console.log(result.failed); // Failed to cancel
console.log(result.results); // Detailed results for each order
// Get all orders
const result = await client.getMyOrders();
// Filter by market_id and status
const result2 = await client.getMyOrders({
marketId: 57,
status: '1', // 1=pending, 2=filled, 3=canceled, 4=expired, 5=failed, 6=on chain failed
page: 1,
limit: 10,
});
console.log(result.result.total);
console.log(result.result.list);
const result = await client.getOrderById('504d7580-cd59-11ef-887f-0a58a9feac02');
console.log(result.result);
const result = await client.getMyBalances();
for (const balance of result.result) {
console.log(balance.totalBalance); // Total in-app balance
console.log(balance.balance); // Available balance
console.log(balance.netWorth); // Total net worth
console.log(balance.currencyAddress); // Token contract address
}
// Get all positions
const result = await client.getMyPositions();
// With pagination and market filter
const result2 = await client.getMyPositions({
marketId: 23,
page: 1,
limit: 10,
});
console.log(result.result.total);
console.log(result.result.list);
// Get all trades
const result = await client.getMyTrades();
// Filter by market with pagination
const result2 = await client.getMyTrades({
marketId: 57,
page: 1,
limit: 10,
});
console.log(result.result.total);
console.log(result.result.list);
const result = await client.getUserAuth();
console.log(result.result);
const result = await client.enableTrading();
console.log(result.success); // true if successful
console.log(result.txHash); // Transaction hash (undefined if already enabled)
const result = await client.split(
57, // marketId
BigInt(100 * 10**18), // amount in wei (100 tokens with 18 decimals)
true // checkApproval (default: true)
);
// For USDC with 6 decimals:
const result2 = await client.split(57, BigInt(100 * 10**6));
console.log(result.success);
console.log(result.txHash);