AD
Documentation Dec 09, 2025 20 min read
Technical Specification: Abstraction Layer

Detailed architecture, API definitions, and data models for the Trading Gateway.

#Architecture#API#Python#Design

Abstraction Layer: Technical Specification

1. Architecture Overview

The Abstraction Layer is designed using the Adapter Pattern to decouple ZenOTC's internal trading systems (OMS, EMS, PMS) from external Smart Order Routing (SOR) providers.

High-Level Diagram

graph LR
    OMS[Order Management System] --> Gateway[Trading Gateway Interface]
    EMS[Execution Management System] --> Gateway
    
    subgraph "Abstraction Layer"
        Gateway --> Factory[Adapter Factory]
        Factory --> Talos[Talos Adapter]
        Factory --> Portware[Portware Adapter]
        Factory --> Mock[Mock Adapter]
    end
    
    Talos --> TalosAPI[Talos API]
    Portware --> PortwareAPI[Portware API]

2. Core Components

2.1 TradingGateway Interface

The standardized contract that all adapters must implement.

class TradingGateway(ABC):
    @abstractmethod
    async def submit_order(self, order: Order) -> OrderResult:
        pass

    @abstractmethod
    async def cancel_order(self, order_id: str) -> bool:
        pass

    @abstractmethod
    async def get_market_data(self, symbol: str) -> MarketData:
        pass
        
    @abstractmethod
    async def subscribe_stream(self, symbols: List[str], callback: Callable):
        pass

2.2 Data Models

Standardized internal representations of trading entities.

  • Order: id, symbol, side, quantity, price, type, time_in_force
  • Trade: id, order_id, price, quantity, fee, timestamp
  • MarketData: symbol, bid, ask, last, volume, timestamp

2.3 Adapter Factory

Responsible for instantiating the correct adapter based on configuration.

class AdapterFactory:
    @staticmethod
    def get_adapter(config: Config) -> TradingGateway:
        if config.provider == "TALOS":
            return TalosAdapter(config.api_key, config.secret)
        elif config.provider == "PORTWARE":
            return PortwareAdapter(config.connection_string)
        else:
            raise ValueError("Unknown provider")

3. Functional Requirements

  1. Order Management: Support Limit, Market, Stop, and TWAP/VWAP algo orders.
  2. Real-time Data: Stream L1/L2 market data with <5ms internal latency.
  3. Normalization: Automatically convert provider-specific error codes to internal standard codes.
  4. Resilience: Automatic reconnection logic for WebSocket streams.
  5. Logging: Structured logging (JSON) for all outgoing and incoming messages.

4. Non-Functional Requirements

  1. Latency: <5ms overhead added by the abstraction layer.
  2. Throughput: Support 10,000 messages/second.
  3. Concurrency: Support 1,000+ concurrent WebSocket connections.
  4. Availability: 99.99% uptime design (stateless services).
  5. Security: API keys stored in HashiCorp Vault; TLS 1.3 for all connections.

5. Technology Stack

  • Language: Python 3.11 (AsyncIO)
  • Framework: FastAPI (for REST interface), websockets (for streaming)
  • Data Validation: Pydantic v2
  • Testing: Pytest, pytest-asyncio
  • Infrastructure: Docker, Kubernetes (EKS)

6. Implementation Plan

  • Week 1: Core Interface & Data Models
  • Week 2: Talos Adapter Implementation
  • Week 3: Alternative Adapter (Portware) & Testing
  • Week 4: Integration & Production Deployment