@opinion-labs/opinion-api
v0.2.2
Published
Auto-generated OpenAPI client for Opinion Prediction Market API
Readme
@opinion-labs/opinion-api
Auto-generated TypeScript client for the Opinion Labs Prediction Market OpenAPI.
Installation
npm install @opinion-labs/opinion-apiQuick Start
import { createClient, createConfig } from '@opinion-labs/opinion-api/client';
import { getMarket, getTokenOrderbook, getTokenLatestPrice } from '@opinion-labs/opinion-api';
// Create a configured client
const client = createClient(
createConfig({
baseUrl: 'https://openapi.opinion.trade/openapi',
headers: {
apikey: 'your_api_key',
},
})
);
// Fetch markets
const { data } = await getMarket({
client,
headers: { apikey: 'your_api_key' },
query: { chainId: '56', marketType: 2, page: 1, limit: 10, sortBy: 1 },
});
console.log(data?.result?.list);Available Endpoints
Market Data
| Function | Description |
|----------|-------------|
| getMarket() | List markets with pagination and filters |
| getMarketByMarketId() | Get binary market details by ID |
| getMarketCategoricalByMarketId() | Get categorical market details by ID |
| getQuoteToken() | List supported quote tokens |
| getTokenOrderbook() | Get orderbook for a token |
| getTokenLatestPrice() | Get latest price for a token |
| getTokenPriceHistory() | Get price history with interval/time range |
| getTokenFeeRates() | Get fee rates for a token |
User & Positions
| Function | Description |
|----------|-------------|
| getUserAuth() | Get authenticated user info |
| getUserBalance() | Get user's token balances |
| getPositions() | Get user's positions |
| getPositionsUserByWalletAddress() | Get another user's positions |
| getTrade() | Get user's trade history |
| getTradeUserByWalletAddress() | Get another user's trade history |
| getOrder() | Get user's orders |
| getOrderByOrderId() | Get order details by ID |
Orders
| Function | Description |
|----------|-------------|
| postOrder() | Place an order |
| postOrderCancel() | Cancel an order |
Response Format
All endpoints return responses in the following structure:
{
data?: {
errno: number; // 0 = success
errmsg: string; // Error message (empty on success)
result: T; // Response payload
};
error?: unknown;
}Higher-Level SDK
For a more ergonomic developer experience with built-in order signing, wallet management, and WebSocket support, use @opinion-labs/opinion-clob-sdk which wraps this client.
Requirements
- Node.js >= 18
- TypeScript >= 5.3 (for type-safe usage)
License
MIT
