Complete Trading API Documentation for Vision Max Integration
Version 1.0 | ALL POST | Real-Time WebSocket | PSX Compliant | T+2 Settlement
โก DEMO MODE: This is a static demonstration for API documentation. All trading buttons and data
updates are simulated. No real trades will be executed.
WEBSOCKET CONNECTED
Session: OPTIMUS_TRADING_001 | Market: PSX | T+2 Settlement Active
// Used in: Order entry systems, algorithmic trading
๐ฐ
Portfolio APIs
POST /portfolio/summaryPOST /portfolio/holdingsPOST /account/buying-power
Account management - view holdings, portfolio performance, and buying power.
// Used in: Portfolio dashboards, risk management systems
๐
Webhook Notifications
POST /webhook/visionmax
Real-time event notifications for order executions, rejections, and account alerts.
// Used in: Alert systems, trade confirmations
๐๏ธ
PSX Compliance
Circuit BreakersLot Size RulesT+2 Settlement
Pakistan Stock Exchange specific rules and validations applied to all orders.
// Used in: Pre-trade validation, compliance checks
1. WEBSOCKET MARKET DATA STREAMS
Real-Time ยท JWT Required
๐ก What are WebSocket streams?
WebSocket connections provide real-time, bidirectional communication. Unlike
REST APIs where you request data, WebSockets push data to your application as soon as it's
available. Perfect for live trading screens, charts, and order books.
// Used in: Live price feeds, real-time charts, instant order updates
Real-time market status updates with PSX-specific sessions - pre-open,
continuous trading, post-close sessions. Critical for order validation.
// Used in: Trading hours validation, market countdowns
2. TRADING REST APIS
Base: https://api.optimuscapital.com/v1 ยท ALL POST
๐ What are REST APIs?
REST APIs follow a request-response pattern. Your application sends a request,
and the server responds with data. Unlike WebSockets, these are not real-time - you ask for data
when you need it. Perfect for account management, placing orders, and fetching historical data.
// Used in: Order placement, portfolio views, account management
Lists all securities currently held in portfolio with detailed P&L, valuation,
and available quantities.
// Used in: Portfolio management, tax calculations
3. PRE-TRADE VALIDATION & RISK APIS
Local Validation Before Vision Max
โ ๏ธ CRITICAL: These APIs run locally before sending to Vision Max
Vision Max does NOT validate buying power, exposure limits, or circuit breakers.
These checks must be performed locally to prevent order rejections and ensure compliance.
Validates order against all PSX rules before submission. If any check fails,
order is rejected locally and never sent to Vision Max, saving time and preventing rejections.
// Called automatically by /orders endpoint before Vision Max submission
4. BUYING POWER & T+2 SETTLEMENT APIS
PSX Settlement Rules
POST/account/buying-powerReal-time available funds
Webhooks are HTTP callbacks - Optimus sends real-time notifications to your
Vision Max endpoint when events occur. Unlike polling, you don't need to constantly check for
updates.
// Used in: Real-time trade confirmations, instant alerts
order.confirmed - Order accepted by exchange
order.rejected - Order rejected by pre-trade checks
order.cancelled - Order cancelled by user
order.execution - Partial or full fill
margin.call - Margin call threshold hit
account.alert - Deposit/withdrawal status
๐ What this is for:
Real-time event notifications from Optimus to Vision Max. Ensures your
application stays synchronized with order status changes.
// Used in: Push notifications, real-time UI updates
Pre-open Session: 9:15 AM โ 9:30 AM Continuous Trading: 9:30 AM โ 3:30 PM Post-close Session: 3:30 PM โ 3:35 PM
All orders validated against market hours
๐ Settlement Cycle
T+2 Settlement: All cash and security balances reflect T+2 cycle Unsettled Funds: Not available for trading until T+2
Affects buying power calculations
โก Circuit Breakers
Upper Circuit: +10% from last close Lower Circuit: -10% from last close Orders rejected: Outside these limits
Automatically enforced by Optimus
๐ Lot Size Requirements
Board Lots: Standard trading units Odd Lots: Not permitted for orders Multiple: Must be in multiples of lot size
Example: MEBL lot size = 500 shares
๐ซ Trading Restrictions
Short Selling: Not permitted for retail investors Day Trading: Allowed with margin accounts Position Limits: Per exchange regulations
Compliance checks on all orders
๐ Order Types
MIT: Market If Touched MTL: Market To Limit IOC: Immediate or Cancel FOK: Fill or Kill
PSX-specific order types supported
๐ PSX Integration Note:
All orders placed through Optimus are automatically
validated against PSX rules. If any rule is violated (market closed, invalid lot size, outside
circuit breaker), the order will be rejected with a specific error code before reaching the
exchange.
11. SECURITY & COMPLIANCE
TLS 1.2+ Required
๐ Why security matters:
Trading APIs handle sensitive financial data and real money. These security
measures protect user data, prevent abuse, and ensure regulatory compliance.
โข Encryption: TLS 1.2+ (HTTPS for REST, WSS for WebSockets)
โข Rate Limiting:
- Authentication APIs: 5 requests per minute per IP
- Trading APIs: 100 requests per second per user
- Public Data APIs: 200 requests per minute per IP
โข IP Whitelisting: Vision Max whitelists Optimus production IPs
โข Audit Logs: All orders/auth logged with request_id, user_id, timestamp
โข Idempotency Keys: Prevent duplicate order submissions
โข JWT Expiry: 1 hour access tokens, 7 day refresh tokens
12. JSON STANDARDS
snake_case ยท ISO 8601
๐ Why standards matter:
Consistent JSON formatting ensures your code works reliably across all endpoints
and makes integration easier for developers.
โข Naming Convention: snake_case for all JSON property names
โข Timestamps: ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ)
โข Numbers: Use JSON number type (not strings)
โข Standard Response Envelope:
Success: { "status": "success", "code": 200, "data": { ... }, "request_id": "..." }
Error: { "status": "error", "code": 400, "message": "Summary", "error_details": { ... }, "request_id": "..." }
13. ERROR CODES
Complete Reference
โ ๏ธ Why error codes matter:
Error codes help your application understand what went wrong and take
appropriate action - whether it's retrying, showing user-friendly messages, or escalating issues.
1001 Authentication - Invalid token
1002 Authentication - Token expired
1003 Authorization - Insufficient permissions
2001 Trading - Invalid symbol
2002 Trading - Invalid quantity (lot size)
2003 Trading - Invalid price (outside circuit breaker)
2004 Trading - Insufficient buying power
2005 Trading - Position not held (for sell orders)
2006 Trading - Market closed
2007 Trading - Order type not supported
2008 Trading - Position limit exceeded
2009 Trading - Sector exposure limit exceeded
2010 Trading - Circuit breaker triggered
3001 System - Rate limit exceeded
3002 System - Idempotency key reused
4001 Settlement - Unsettled funds not available
4002 Settlement - T+2 settlement in progress
9001 Vision Max - Backend connectivity issue
9002 Vision Max - Order rejected by exchange
YOUR HOLDINGS
Portfolio Summary ยท T+2 Settlement
Portfolio HoldingsLast Updated: 11:30 AM PKT
Total ValuePKR 1,875,000+2.3%
Today's P&L+PKR 42,500+2.3%
Total P&L+PKR 125,000+7.14%
Positions126 Sectors
MEBL187.501,000PKR 187.5K+3.88%
SYS432.10500PKR 216.1K+1.67%
ENGRO321.75800PKR 257.4K+2.10%
OGDC109.302,000PKR 218.6K+0.92%
PSO75.123,000PKR 225.4K+1.61%
KEL102.501,500PKR 153.8K-1.06%
๐ Progress bars show portfolio weight (% of total)๐ข Positive P&L๐ด Negative P&Lโฑ๏ธ T+2 Settlement applies