Phase C · Information Systems Architecture

AIB Trading Service API

Version: 1.0
Status: Draft
Last Updated: 2026-06-08


Overview

aib-trading owns order lifecycle, pre-trade compliance gates, trade execution, settlement management, and best execution tracking.

Primary Tables: order_, trade, settlement, emir_trade_report, approved_instrument, position, best_execution_policy
Calls: aib-compliance (mandate validation), aib-reporting (EMIR)
Called By: aib-operations (position updates)


SLA Targets

MetricTargetNotes
Pre-Trade GateP95: 50msReal-time suitability + mandate check
Order CreationP95: 100msMiFID II Art. 25 compliance gate
Trade Execution ConfirmationP95: 200msBroker callback → DB record
Settlement InstructionP95: 500msT+0 EOD to CSD
Throughput (orders)5,000 req/secPeak trading hours
Availability99.99%Execution failure = liability

OpenAPI 3.0 Specification

openapi: 3.0.3 info: title: AIB Trading Service API version: 1.0.0 description: Order management, pre-trade compliance, trade execution, settlement, best execution contact: name: AIB Architecture servers: - url: https://api.aib.internal/trading/v1 description: Production paths: /orders: post: summary: Place order with pre-trade compliance checks operationId: createOrder requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/OrderCreateRequest' responses: '201': description: Order created and pre-trade checks passed content: application/json: schema: $ref: '#/components/schemas/OrderResponse' '400': description: Pre-trade check failed (suitability, mandate, best execution) content: application/json: schema: $ref: '#/components/schemas/PreTradeErrorResponse' tags: - Orders x-sla: p95_latency_ms: 100 timeout_ms: 500 get: summary: List orders for a client operationId: listOrders parameters: - name: account_id in: query required: true schema: type: string format: uuid - name: status in: query schema: type: string enum: [pending, submitted, executed, rejected, canceled] - name: limit in: query schema: type: integer default: 100 responses: '200': description: List of orders content: application/json: schema: type: array items: $ref: '#/components/schemas/OrderResponse' tags: - Orders x-sla: p95_latency_ms: 150 /orders/{order_id}: get: summary: Retrieve order details with pre-trade check results operationId: getOrder parameters: - name: order_id in: path required: true schema: type: string format: uuid responses: '200': description: Order details content: application/json: schema: $ref: '#/components/schemas/OrderResponse' tags: - Orders x-sla: p95_latency_ms: 50 patch: summary: Update order status (cancel, suspend) operationId: updateOrder parameters: - name: order_id in: path required: true schema: type: string format: uuid requestBody: content: application/json: schema: type: object properties: status: type: string enum: [canceled] responses: '200': description: Order updated content: application/json: schema: $ref: '#/components/schemas/OrderResponse' tags: - Orders x-sla: p95_latency_ms: 100 /orders/{order_id}/execute: post: summary: Execute order (internal routing to broker) operationId: executeOrder parameters: - name: order_id in: path required: true schema: type: string format: uuid requestBody: content: application/json: schema: type: object properties: broker_id: type: string description: Selected broker (best execution) responses: '202': description: Order submitted to broker '400': description: Order cannot be executed (status != pending) tags: - Execution x-sla: p95_latency_ms: 200 /trades: post: summary: Record executed trade (callback from broker) operationId: createTrade requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/TradeCreateRequest' responses: '201': description: Trade recorded content: application/json: schema: $ref: '#/components/schemas/TradeResponse' '400': description: Invalid order_id or trade data tags: - Trades x-sla: p95_latency_ms: 150 get: summary: List trades operationId: listTrades parameters: - name: account_id in: query schema: type: string format: uuid - name: from_date in: query schema: type: string format: date - name: to_date in: query schema: type: string format: date responses: '200': description: List of trades content: application/json: schema: type: array items: $ref: '#/components/schemas/TradeResponse' tags: - Trades x-sla: p95_latency_ms: 200 /trades/{trade_id}: get: summary: Retrieve trade details operationId: getTrade parameters: - name: trade_id in: path required: true schema: type: string format: uuid responses: '200': description: Trade details content: application/json: schema: $ref: '#/components/schemas/TradeResponse' tags: - Trades x-sla: p95_latency_ms: 50 /settlements: post: summary: Create settlement instruction (T+2 from trade_date) operationId: createSettlement requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/SettlementCreateRequest' responses: '201': description: Settlement scheduled content: application/json: schema: $ref: '#/components/schemas/SettlementResponse' tags: - Settlement x-sla: p95_latency_ms: 100 get: summary: List settlements with status operationId: listSettlements parameters: - name: status in: query schema: type: string enum: [scheduled, matched, failed, buy_in_pending] - name: intended_sd_from in: query schema: type: string format: date responses: '200': description: List of settlements content: application/json: schema: type: array items: $ref: '#/components/schemas/SettlementResponse' tags: - Settlement x-sla: p95_latency_ms: 150 /settlements/{settlement_id}: get: summary: Retrieve settlement details with T+n escalation status operationId: getSettlement parameters: - name: settlement_id in: path required: true schema: type: string format: uuid responses: '200': description: Settlement details content: application/json: schema: $ref: '#/components/schemas/SettlementResponse' tags: - Settlement x-sla: p95_latency_ms: 50 patch: summary: Update settlement status (mark matched, initiate buy-in) operationId: updateSettlement parameters: - name: settlement_id in: path required: true schema: type: string format: uuid requestBody: content: application/json: schema: type: object properties: status: type: string enum: [matched, buy_in_pending, escalated_to_fma] responses: '200': description: Settlement updated '400': description: Invalid status transition tags: - Settlement x-sla: p95_latency_ms: 150 /positions: get: summary: Retrieve current positions for account operationId: listPositions parameters: - name: account_id in: query required: true schema: type: string format: uuid responses: '200': description: Current positions content: application/json: schema: type: array items: $ref: '#/components/schemas/PositionResponse' tags: - Positions x-sla: p95_latency_ms: 100 /best-execution-policy: get: summary: Retrieve current best execution policy operationId: getBestExecutionPolicy parameters: - name: version_date in: query schema: type: string format: date responses: '200': description: Best execution policy content: application/json: schema: $ref: '#/components/schemas/BestExecutionPolicyResponse' tags: - Best Execution x-sla: p95_latency_ms: 50 post: summary: Publish new best execution policy (compliance) operationId: createBestExecutionPolicy requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/BestExecutionPolicyCreateRequest' responses: '201': description: Policy published content: application/json: schema: $ref: '#/components/schemas/BestExecutionPolicyResponse' tags: - Best Execution x-sla: p95_latency_ms: 200 components: schemas: OrderCreateRequest: type: object required: - account_id - isin - quantity - direction properties: account_id: type: string format: uuid isin: type: string pattern: '^[A-Z]{2}[A-Z0-9]{9}[0-9]$' quantity: type: integer minimum: 1 direction: type: string enum: [buy, sell] limit_price: type: number nullable: true OrderResponse: type: object properties: order_id: type: string format: uuid account_id: type: string format: uuid mandate_id: type: string format: uuid isin: type: string quantity: type: integer direction: type: string status: type: string enum: [pending, submitted, executed, rejected, canceled] pre_trade_check: type: object properties: suitability_check: type: string enum: [passed, failed] suitability_reason: type: string nullable: true mandate_compliance_check: type: string enum: [passed, failed] mandate_reason: type: string nullable: true approved_instrument_check: type: string enum: [passed, failed] best_execution_check: type: string enum: [passed, failed] created_at: type: string format: date-time PreTradeErrorResponse: type: object properties: error_code: type: string enum: [SUITABILITY_FAILED, MANDATE_EXCEEDED, INSTRUMENT_NOT_APPROVED, BEST_EXECUTION_FAILED] error_message: type: string details: type: object TradeCreateRequest: type: object required: - order_id - executed_price - executed_quantity properties: order_id: type: string format: uuid executed_price: type: number executed_quantity: type: integer trade_date: type: string format: date broker_reference: type: string TradeResponse: type: object properties: trade_id: type: string format: uuid order_id: type: string format: uuid executed_price: type: number executed_quantity: type: integer trade_date: type: string format: date intended_sd: type: string format: date description: T+2 settlement date settlement_id: type: string format: uuid emir_trade_report_id: type: string format: uuid nullable: true created_at: type: string format: date-time SettlementCreateRequest: type: object required: - trade_id properties: trade_id: type: string format: uuid SettlementResponse: type: object properties: settlement_id: type: string format: uuid trade_id: type: string format: uuid status: type: string enum: [scheduled, matched, failed, buy_in_pending, escalated_to_fma] intended_sd: type: string format: date fail_days: type: integer description: Days settlement has failed (0 = on-time, 3+ = escalate) t3_escalation_required: type: boolean description: CSDR Art. 7 escalation trigger buy_in_assessed: type: boolean csdr_penalty_applicable: type: boolean scheduled_at: type: string format: date-time matched_at: type: string format: date-time nullable: true PositionResponse: type: object properties: position_id: type: string format: uuid account_id: type: string format: uuid isin: type: string quantity: type: integer cost_basis_chf: type: number current_market_price: type: number unrealized_pl_chf: type: number settlement_date: type: string format: date updated_at: type: string format: date-time BestExecutionPolicyResponse: type: object properties: policy_id: type: string format: uuid effective_date: type: string format: date version: type: integer approved_brokers: type: array items: type: object properties: broker_id: type: string broker_name: type: string execution_quality_score: type: number execution_venues: type: array items: type: object properties: venue_mic: type: string priority: type: integer BestExecutionPolicyCreateRequest: type: object required: - approved_brokers - execution_venues properties: approved_brokers: type: array items: type: string execution_venues: type: array items: type: string

Integration Points

Calls to Other Services

  • aib-compliance (GET /clients/{client_id}?check_kyc_status=true): Pre-trade suitability validation
  • aib-reporting (POST /emir-trades): EMIR reporting for derivatives

Called By

  • None (source service)

Event Publishing

  • order.created → pre-trade checks
  • trade.executed → settlement creation + EMIR reporting
  • settlement.matched → position update
  • settlement.failed → T+3 escalation + ops alert

Pre-Trade Compliance Gate (4-Check Logic)

ORDER SUBMISSION ↓ [CHECK 1] Suitability Assessment valid? ├─ Pass → next check └─ Fail (expired) → REJECT (status=400) ↓ [CHECK 2] Mandate limit compliance? ├─ ISIN in approved_instrument list? ├─ Position weight within mandate.max_weight_pct? ├─ Pass → next check └─ Fail → REJECT (status=400) ↓ [CHECK 3] Best Execution venue selected? ├─ Broker in best_execution_policy? ├─ Pass → next check └─ Fail → REJECT (status=400) ↓ [CHECK 4] No pending MAR sanctions flags? ├─ MAR surveillance flag.status = 'clear'? ├─ Pass → CREATE order └─ Fail → REJECT (status=400) ↓ ORDER CREATED (status=pending)

Settlement Discipline (CSDR Art. 5, 7)

DayStatusAction
T+0Order executedTrade record created
T+0 EODTrade → Settlement instructionT+2 settlement date calculated via settlement_calendar
T+2Settlement dateAwait CSD matching
T+2 EOD (success)Settlement matchedsettlement.status = 'matched'
T+2 EOD (failure)Settlement failedsettlement.fail_days=1, ops alert
T+3 EOD1 day overduesettlement.fail_days=2, CCO notification
T+4 EOD2 days overduesettlement.fail_days=3, settlement.t3_escalation_required=true, buy-in assessment
T+30Unresolvedsettlement.status='escalated_to_fma', FMA report filed

Regulatory Compliance

RegulationRequirementImplementation
MiFID II Art. 25Pre-trade suitability gate4-check logic in order creation
MiFID II Art. 27Best execution policy/best-execution-policy endpoint + RTS 28 reporting
CSDR Art. 5T+2 settlement disciplineSettlement instruction T+2 scheduling
CSDR Art. 7Settlement failure escalation3-day fail trigger + buy-in + penalty accrual
EMIR Art. 9Trade reporting (derivatives)UTI assignment + ARM reporting within T+1

References

Referenced by