openapi: 3.1.0 info: title: Api version: 0.1.0 description: StockEZ Trading Platform API servers: - url: /api description: Base API path tags: - name: health description: Health operations - name: auth description: Authentication operations - name: stocks description: Stock market operations - name: portfolio description: Portfolio management - name: transactions description: Trading transactions - name: admin description: Admin operations - name: watchlist description: Watchlist management paths: /healthz: get: operationId: healthCheck tags: [health] summary: Health check responses: "200": description: Healthy content: application/json: schema: $ref: "#/components/schemas/HealthStatus" /auth/register: post: operationId: register tags: [auth] summary: Register a new user requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/RegisterRequest" responses: "201": description: User registered content: application/json: schema: $ref: "#/components/schemas/AuthResponse" "400": description: Bad request content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" /auth/login: post: operationId: login tags: [auth] summary: Login user requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/LoginRequest" responses: "200": description: Login successful content: application/json: schema: $ref: "#/components/schemas/AuthResponse" "401": description: Unauthorized content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" /auth/me: get: operationId: getMe tags: [auth] summary: Get current user security: - bearerAuth: [] responses: "200": description: Current user info content: application/json: schema: $ref: "#/components/schemas/User" "401": description: Unauthorized content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" /stocks: get: operationId: getStocks tags: [stocks] summary: Get all stocks parameters: - name: search in: query schema: type: string - name: sector in: query schema: type: string responses: "200": description: List of stocks content: application/json: schema: type: array items: $ref: "#/components/schemas/Stock" /stocks/{symbol}: get: operationId: getStock tags: [stocks] summary: Get a specific stock parameters: - name: symbol in: path required: true schema: type: string responses: "200": description: Stock details content: application/json: schema: $ref: "#/components/schemas/StockDetail" "404": description: Not found content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" /stocks/{symbol}/history: get: operationId: getStockHistory tags: [stocks] summary: Get stock price history parameters: - name: symbol in: path required: true schema: type: string - name: period in: query schema: type: string enum: [1d, 1w, 1m, 3m, 1y] default: 1m responses: "200": description: Price history content: application/json: schema: type: array items: $ref: "#/components/schemas/PricePoint" /portfolio: get: operationId: getPortfolio tags: [portfolio] summary: Get user portfolio security: - bearerAuth: [] responses: "200": description: Portfolio data content: application/json: schema: $ref: "#/components/schemas/Portfolio" /portfolio/summary: get: operationId: getPortfolioSummary tags: [portfolio] summary: Get portfolio summary stats security: - bearerAuth: [] responses: "200": description: Portfolio summary content: application/json: schema: $ref: "#/components/schemas/PortfolioSummary" /transactions: get: operationId: getTransactions tags: [transactions] summary: Get user transactions security: - bearerAuth: [] parameters: - name: page in: query schema: type: integer default: 1 - name: limit in: query schema: type: integer default: 20 responses: "200": description: Transactions list content: application/json: schema: $ref: "#/components/schemas/TransactionList" post: operationId: createTransaction tags: [transactions] summary: Buy or sell stock security: - bearerAuth: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/TransactionRequest" responses: "201": description: Transaction created content: application/json: schema: $ref: "#/components/schemas/Transaction" "400": description: Bad request (insufficient funds or shares) content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" /watchlist: get: operationId: getWatchlist tags: [watchlist] summary: Get user watchlist security: - bearerAuth: [] responses: "200": description: Watchlist stocks content: application/json: schema: type: array items: $ref: "#/components/schemas/Stock" post: operationId: addToWatchlist tags: [watchlist] summary: Add stock to watchlist security: - bearerAuth: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/WatchlistRequest" responses: "201": description: Added to watchlist content: application/json: schema: $ref: "#/components/schemas/MessageResponse" /watchlist/{symbol}: delete: operationId: removeFromWatchlist tags: [watchlist] summary: Remove from watchlist security: - bearerAuth: [] parameters: - name: symbol in: path required: true schema: type: string responses: "200": description: Removed from watchlist content: application/json: schema: $ref: "#/components/schemas/MessageResponse" /admin/users: get: operationId: adminGetUsers tags: [admin] summary: Admin - get all users security: - bearerAuth: [] responses: "200": description: All users content: application/json: schema: type: array items: $ref: "#/components/schemas/AdminUser" /admin/users/{userId}: patch: operationId: adminUpdateUser tags: [admin] summary: Admin - update user security: - bearerAuth: [] parameters: - name: userId in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/AdminUpdateUserRequest" responses: "200": description: User updated content: application/json: schema: $ref: "#/components/schemas/AdminUser" delete: operationId: adminDeleteUser tags: [admin] summary: Admin - delete user security: - bearerAuth: [] parameters: - name: userId in: path required: true schema: type: integer responses: "200": description: User deleted content: application/json: schema: $ref: "#/components/schemas/MessageResponse" /admin/stocks: post: operationId: adminCreateStock tags: [admin] summary: Admin - create stock security: - bearerAuth: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/AdminCreateStockRequest" responses: "201": description: Stock created content: application/json: schema: $ref: "#/components/schemas/Stock" /admin/stocks/{symbol}: patch: operationId: adminUpdateStock tags: [admin] summary: Admin - update stock security: - bearerAuth: [] parameters: - name: symbol in: path required: true schema: type: string requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/AdminUpdateStockRequest" responses: "200": description: Stock updated content: application/json: schema: $ref: "#/components/schemas/Stock" delete: operationId: adminDeleteStock tags: [admin] summary: Admin - delete stock security: - bearerAuth: [] parameters: - name: symbol in: path required: true schema: type: string responses: "200": description: Stock deleted content: application/json: schema: $ref: "#/components/schemas/MessageResponse" /admin/stats: get: operationId: adminGetStats tags: [admin] summary: Admin - platform statistics security: - bearerAuth: [] responses: "200": description: Platform stats content: application/json: schema: $ref: "#/components/schemas/AdminStats" components: securitySchemes: bearerAuth: type: http scheme: bearer bearerFormat: JWT schemas: HealthStatus: type: object properties: status: type: string required: - status ErrorResponse: type: object properties: error: type: string message: type: string required: - error MessageResponse: type: object properties: message: type: string required: - message RegisterRequest: type: object properties: name: type: string email: type: string password: type: string required: - name - email - password LoginRequest: type: object properties: email: type: string password: type: string required: - email - password AuthResponse: type: object properties: token: type: string user: $ref: "#/components/schemas/User" required: - token - user User: type: object properties: id: type: integer name: type: string email: type: string role: type: string enum: [user, admin] balance: type: number createdAt: type: string format: date-time required: - id - name - email - role - balance - createdAt AdminUser: type: object properties: id: type: integer name: type: string email: type: string role: type: string enum: [user, admin] balance: type: number isActive: type: boolean createdAt: type: string format: date-time required: - id - name - email - role - balance - isActive - createdAt Stock: type: object properties: id: type: integer symbol: type: string name: type: string currentPrice: type: number previousClose: type: number change: type: number changePercent: type: number volume: type: integer marketCap: type: number sector: type: string required: - id - symbol - name - currentPrice - previousClose - change - changePercent - volume - marketCap - sector StockDetail: allOf: - $ref: "#/components/schemas/Stock" - type: object properties: high52w: type: number low52w: type: number avgVolume: type: integer description: type: string inWatchlist: type: boolean required: - high52w - low52w - avgVolume - description - inWatchlist PricePoint: type: object properties: timestamp: type: string format: date-time price: type: number volume: type: integer required: - timestamp - price - volume Portfolio: type: object properties: holdings: type: array items: $ref: "#/components/schemas/Holding" balance: type: number totalValue: type: number totalInvested: type: number totalGainLoss: type: number totalGainLossPercent: type: number required: - holdings - balance - totalValue - totalInvested - totalGainLoss - totalGainLossPercent Holding: type: object properties: stockId: type: integer symbol: type: string name: type: string quantity: type: number avgBuyPrice: type: number currentPrice: type: number currentValue: type: number gainLoss: type: number gainLossPercent: type: number required: - stockId - symbol - name - quantity - avgBuyPrice - currentPrice - currentValue - gainLoss - gainLossPercent PortfolioSummary: type: object properties: totalValue: type: number dayChange: type: number dayChangePercent: type: number totalGainLoss: type: number totalGainLossPercent: type: number balance: type: number holdingsCount: type: integer required: - totalValue - dayChange - dayChangePercent - totalGainLoss - totalGainLossPercent - balance - holdingsCount Transaction: type: object properties: id: type: integer userId: type: integer stockId: type: integer symbol: type: string name: type: string type: type: string enum: [buy, sell] quantity: type: number price: type: number totalAmount: type: number createdAt: type: string format: date-time required: - id - userId - stockId - symbol - name - type - quantity - price - totalAmount - createdAt TransactionList: type: object properties: transactions: type: array items: $ref: "#/components/schemas/Transaction" total: type: integer page: type: integer limit: type: integer required: - transactions - total - page - limit TransactionRequest: type: object properties: symbol: type: string type: type: string enum: [buy, sell] quantity: type: number required: - symbol - type - quantity WatchlistRequest: type: object properties: symbol: type: string required: - symbol AdminUpdateUserRequest: type: object properties: role: type: string enum: [user, admin] isActive: type: boolean balance: type: number AdminCreateStockRequest: type: object properties: symbol: type: string name: type: string currentPrice: type: number sector: type: string description: type: string marketCap: type: number required: - symbol - name - currentPrice - sector AdminUpdateStockRequest: type: object properties: name: type: string currentPrice: type: number sector: type: string description: type: string marketCap: type: number AdminStats: type: object properties: totalUsers: type: integer activeUsers: type: integer totalStocks: type: integer totalTransactions: type: integer totalVolume: type: number totalMarketCap: type: number required: - totalUsers - activeUsers - totalStocks - totalTransactions - totalVolume - totalMarketCap