๐ User Updates
Connect to the socket server as an authenticated user to receive real-time updates on your positions, activities, and TC balance.
To receive real-time updates about your positions, activities, and TC balance, you must connect to the socket server as an authenticated user.
import { io } from "socket.io-client";
const url = "{{BASE_URL}}";
const opts = {
transports: ["websocket"],
reconnection: true,
auth: { token: "YOUR_TOKEN_HERE" }, // Set your JWT or session token here
};
const socket = io(url, opts);
socket.on("connect", () => {
console.log("connected", socket.id);
// Optionally join a room if needed
// socket.emit("joinRoom", "user_123"); // Example: join a user-specific room
});
socket.on("disconnect", (reason) => {
console.log("disconnected", reason);
});
socket.on("connect_error", (err) => {
console.error("Connection error:", err.message);
});
// Listen for user-specific events
socket.on("update_position", (data) => {
console.log("Received update_position:", data);
});
socket.on("update_activity", (data) => {
console.log("Received update_activity:", data);
});
socket.on("update_cgpc_balance", (data) => {
console.log("Received update_cgpc_balance:", data);
});
๐ฐ Get TC Balance Updates
Sent when your TC/USDC token balance or related wallet information changes.
Event: update_cgpc_balance
| Field | Type | Description |
|---|---|---|
| id | string | Balance record ID |
| createdAt | string | Record creation ISO timestamp |
| updatedAt | string | Last update ISO timestamp |
| deletedAt | string | null | Deletion timestamp (if deleted) |
| userId | number | User identifier |
| balanceUSDC | string | USDC balance |
| lockBalanceUSDC | string | Locked USDC balance |
| balanceUSDT | string | USDT balance |
| lockBalanceUSDT | string | Locked USDT balance |
| balanceCGPC | number | TC token balance |
| lockBalanceCGPC | string | Locked CGPC balance |
| walletProxyAddress | string | Proxy wallet address |
| walletAddress | string | Userโs wallet address |
| tradeGap | string | Trade gap value |
| lastRewardClaimedAt | string | Last reward claim ISO timestamp |
๐ Get New Positions
Sent when your position in a market is updated.
Event: update_position
| Field | Type | Description |
|---|---|---|
| id | string | Position ID |
| marketId | string | Market identifier |
| amount | number | Number of shares held |
| outcomeId | string | Outcome identifier |
| outcomeTitle | string | Outcome name (e.g., "yes", "no") |
| eventId | number | Event identifier |
| marketQuestion | string | The marketโs question |
| marketStatus | enum | Market status (ACTIVE, CLOSED, etc.) |
| marketImage | string | Image URL for the market |
| avgPrice | number | Average price paid |
| latestPrice | number | Most recent price |
| currentValue | number | Current value of your position |
| betValue | number | Total amount youโve bet |
| pnl | number | Profit and loss (decimal) |
| winValue | number | Value if your outcome wins |
๐ Get Activity of the user
Sent when a new activity (trade) is recorded for your account.
Event: update_activity
| Field | Type | Description |
|---|---|---|
| id | string | Activity ID |
| amount | number | Amount traded |
| price | number | Price per unit |
| total | number | Total value of the trade |
| type | enum | Activity type (buy, sell, etc.) |
| createdAt | string | ISO timestamp of the activity |
| txHash | string | Blockchain transaction hash |
| marketId | string | Market identifier |
| marketTitle | string | Market title |
| marketQuestion | string | Marketโs question |
| marketImage | string | Image URL for the market |
| eventId | number | Event identifier |
| outcomeId | string | Outcome identifier |
| outcomeTitle | string | Outcome name |
| outcomeType | number | Outcome type (numeric) |
| abbreviation | string|null | Abbreviation (if any) |
| slug | string | Slug for the event/market |
| rewardToken | string | null | Reward token (if any) |
๐ผ Get Outcome Balance
Sent when your balance or locked balance for a specific outcome token is updated. This event notifies you of changes to your holdings for a particular outcome in a market.
Event: update_outcome_balance
| Field | Type | Description |
|---|---|---|
| id | string | Outcome balance record ID |
| createdAt | string | Record creation ISO timestamp |
| updatedAt | string | Last update ISO timestamp |
| deletedAt | string|null | Deletion timestamp (if deleted) |
| userId | number | User identifier |
| outcomeId | number | Outcome identifier |
| tokenId | string | Token identifier for the outcome |
| balance | number | Current balance for this outcome |
| lockedBalance | string | Locked balance for this outcome |
๐งพ Get Open Orders
Emitted to provide the list of open orders for a user in a specific market.
| Field | Type | Description |
|---|---|---|
| id | string | Order ID |
| market_id | number | Market ID |
| orders_address | string | Address associated with the order |
| orders_amount | string | Total order amount |
| orders_filled_amount | string | Amount already filled |
| orders_outcome_type | number | Outcome type (e.g., 0 = No, 1 = Yes) |
| orders_price | string | Order price |
| orders_remaining_amount | string | Remaining amount to be filled |
| orders_side | number | Order side (0 = buy, 1 = sell) |
| orders_status | number | Status code of the order |
| orders_expired | null/number | Expiry timestamp or null |
| orders_type | number | Type of order |
| outcome_id | number | Outcome ID |
| outcome_title | string | Outcome title |
| orders_total | string | Total value of the order |
| market_image | string | URL to market image |