Client
The Client class is the main interface to the Opinion prediction market infrastructure. It provides methods for market data queries, trading, position management, and blockchain interactions.
Initialization
import 'dotenv/config';
import { Client, CHAIN_ID_BNB_MAINNET, DEFAULT_API_HOST } from '@opinion-labs/opinion-clob-sdk';
const client = new Client({
host: DEFAULT_API_HOST,
apiKey: process.env.API_KEY!,
chainId: CHAIN_ID_BNB_MAINNET,
rpcUrl: process.env.RPC_URL!,
privateKey: process.env.PRIVATE_KEY! as `0x${string}`,
multiSigAddress: process.env.MULTI_SIG_ADDRESS! as `0x${string}`,
});Security: Never hardcode API keys or private keys. Always load from environment variables.
Method Categories
Market Data
Query markets, orderbooks, prices
No
Trading
Place and cancel orders
No (gas-free CLOB)
User Data
Query positions, balances, trades
No
Token Operations
split, merge, redeem, enableTrading
Yes (BNB)
Response Format
All API methods return a consistent response wrapper:
The ApiResponse<T> type is defined as:
Caching
The Client implements built-in caching for frequently accessed data:
Quote Tokens
3600s (1 hour)
Rarely changes, keep high
Market Data
300s (5 minutes)
Balance freshness vs performance
Enable Trading
3600s (1 hour)
Approvals rarely change
Cache TTLs can be configured during initialization:
Bypass cache for individual calls: