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

example.ts
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}`,
});
circle-exclamation

Method Categories

Category
Description
Gas Required

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:

Cache
Default TTL
Recommendation

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:

Best Practices

1

Single Instance

Create one Client for your application; connection pooling is automatic.

2

Error Checking

Always check errno before accessing result.

3

Cache Tuning

Adjust cache TTLs based on your use case.

4

Connectivity Verification

Test with getQuoteTokens() before trading.

5

Async/Await

All Client methods are async; always use await when calling them.