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
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.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")
- Order Management: Support Limit, Market, Stop, and TWAP/VWAP algo orders.
- Real-time Data: Stream L1/L2 market data with <5ms internal latency.
- Normalization: Automatically convert provider-specific error codes to internal standard codes.
- Resilience: Automatic reconnection logic for WebSocket streams.
- Logging: Structured logging (JSON) for all outgoing and incoming messages.
- Latency: <5ms overhead added by the abstraction layer.
- Throughput: Support 10,000 messages/second.
- Concurrency: Support 1,000+ concurrent WebSocket connections.
- Availability: 99.99% uptime design (stateless services).
- Security: API keys stored in HashiCorp Vault; TLS 1.3 for all connections.
- 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)
- Week 1: Core Interface & Data Models
- Week 2: Talos Adapter Implementation
- Week 3: Alternative Adapter (Portware) & Testing
- Week 4: Integration & Production Deployment