Skip to content
🌐Network: Mainnet▼

Error Codes ​

All API endpoints return structured error responses with numeric error codes for programmatic handling.

Error Response Format ​

json
{
  "code": 2000,
  "message": "Market 0x123... not found"
}

Both REST API and WebSocket responses use the same error format, making it easy to handle errors consistently across your application.

Error Code Ranges ​

RangeCategoryDescription
1xxxGeneralInternal errors, invalid requests, rate limiting
2xxxMarketMarket not found, paused, or already exists
3xxxOrderOrder not found, not active, invalid params
4xxxAccount/SessionAuthentication, session, whitelist errors
5xxxTradeTrade not found, invalid trade count
6xxxSubscriptionWebSocket subscription errors
7xxxValidationAmount, time range, pagination errors
8xxxBlock/EventsBlock or events not found

Complete Error Code Reference ​

General Errors (1xxx) ​

CodeNameDescription
1000InternalErrorUnexpected server error
1001InvalidRequestMalformed or invalid request
1002ParseErrorFailed to parse request body
1003RateLimitExceededToo many requests
1004GeoRestrictedRegion not allowed

Market Errors (2xxx) ​

CodeNameDescription
2000MarketNotFoundSpecified market does not exist
2001MarketPausedMarket is currently paused
2002MarketAlreadyExistsMarket already exists

Order Errors (3xxx) ​

CodeNameDescription
3000OrderNotFoundSpecified order does not exist
3001OrderNotActiveOrder is not in active state
3002InvalidOrderParamsInvalid order parameters

Account/Session Errors (4xxx) ​

CodeNameDescription
4000InvalidSignatureSignature verification failed
4001InvalidSessionSession is invalid
4002AccountNotFoundTrading account not found
4003WhitelistNotConfiguredWhitelist not configured

Trade Errors (5xxx) ​

CodeNameDescription
5000TradeNotFoundSpecified trade does not exist
5001InvalidTradeCountInvalid trade count requested

Subscription/WebSocket Errors (6xxx) ​

CodeNameDescription
6000AlreadySubscribedAlready subscribed to topic
6001TooManySubscriptionsSubscription limit exceeded
6002SubscriptionErrorWebSocket subscription error

Validation Errors (7xxx) ​

CodeNameDescription
7000InvalidAmountInvalid amount specified
7001InvalidTimeRangeInvalid time range
7002InvalidPaginationInvalid pagination parameters
7003NoActionsProvidedNo actions in request
7004TooManyActionsToo many actions in request

Block/Events Errors (8xxx) ​

CodeNameDescription
8000BlockNotFoundBlock not found
8001EventsNotFoundEvents not found for block

Handling Errors ​

Example: JavaScript/TypeScript ​

typescript
const response = await fetch('https://api.o2.xyz/v1/markets/invalid-id');
const data = await response.json();

if (data.code) {
  switch (data.code) {
    case 2000:
      console.error('Market not found:', data.message);
      break;
    case 1003:
      console.error('Rate limited, retry later');
      break;
    default:
      console.error(`Error ${data.code}: ${data.message}`);
  }
}

Example: Rust ​

rust
#[derive(Deserialize)]
struct ApiError {
    code: u32,
    message: String,
}

match error.code {
    2000 => println!("Market not found: {}", error.message),
    1003 => println!("Rate limited, retry later"),
    _ => println!("Error {}: {}", error.code, error.message),
}

WebSocket Error Handling ​

WebSocket connections receive errors in the same format:

json
{
  "code": 6001,
  "message": "Subscription limit exceeded"
}

Common WebSocket error scenarios:

  • 6000 (AlreadySubscribed) - Attempting to subscribe to a topic you're already subscribed to
  • 6001 (TooManySubscriptions) - Exceeded the maximum number of subscriptions per connection
  • 6002 (SubscriptionError) - General subscription error (e.g., invalid market ID)