Ultra-low-latency trading infrastructure with FIX protocol, venue connectors, feed handling, order book, and risk engine.
- Architecture
- FIX Protocol Flow
- Risk Engine Pipeline
- Order Book Matching
- Deployment Architecture
- Benchmark Comparisons
- Tests
- License
flowchart TD
subgraph External["External Venues"]
BBG[Bloomberg B-PIPE]
EMSX[Bloomberg EMSX]
MKTX[MarketAxess]
REUTERS[Reuters]
end
subgraph FeedLayer["Feed Handler Layer"]
MV[Multi-Venue Feed Handler\n100K+ events/sec]
NORM[Feed Normalizer]
FILTER[Feed Filter]
STATS[Feed Statistics\nVWAP/TWAP/Volatility]
LAT[Latency Monitor\nµs precision]
end
subgraph FIXLayer["FIX Protocol Layer"]
F42[FIX 4.2 Session]
F44[FIX 4.4 Session]
F50[FIX 5.0 Session]
ROUTER[FIX Message Router]
BUILDER[FIX Message Builder]
STORE[FIX Session Store\nRedis-backed]
HB[FIX Heartbeat Monitor]
RESEND[FIX Resend Handler]
REJECT[FIX Reject Handler]
end
subgraph VenueLayer["Venue Connector Layer"]
SDK[Venue Connector SDK]
SM[Session Manager]
OR[Order Router\nSmart Routing]
MDA[Market Data Aggregator]
PM[Position Manager]
EA[Execution Analyzer]
end
subgraph OrderBookLayer["Order Book Layer"]
OBM[Order Book Manager\n10K+ orders/sec]
PL[Price Level\nO(1) insertion]
ME[Matching Engine\nPrice-Time Priority]
end
subgraph RiskLayer["Risk Engine Layer"]
PTR[Pre-Trade Risk\n<2ms checks]
POS[Position Limit]
KS[Kill Switch\nMiFID II Art 16]
AUDIT[Risk Audit Trail]
VAR[VaR/CVaR\nMonte Carlo]
STRESS[Stress Testing]
end
subgraph CoreLayer["Core Infrastructure"]
ORCH[Core Orchestrator]
CFG[Config Manager\nYAML/TOML/JSON]
LOG[Logging Framework\nStructured JSON]
MET[Metrics Collector\nPrometheus]
HC[Health Check\nReadiness/Liveness]
TR[Distributed Tracing]
SLA[SLA Monitoring\nBurn Rate]
FF[Feature Flags\nA/B Testing]
end
subgraph SecurityLayer["Security Layer"]
ZT[Zero-Trust\nmTLS/SPIFFE]
AUTHZ[RBAC/ABAC\nPolicy Engine]
SEC[Secrets Management\nVault]
REG[Regulatory Reporting\nMiFID II RTS 22]
end
subgraph InfraLayer["Infrastructure"]
DOCKER[Docker\nMulti-stage]
K8S[Kubernetes\nHPA/Ingress/PDB]
end
BBG --> MV
EMSX --> MV
MKTX --> MV
REUTERS --> MV
MV --> NORM --> FILTER --> STATS
MV --> LAT
F42 --> ROUTER
F44 --> ROUTER
F50 --> ROUTER
ROUTER --> BUILDER
ROUTER --> STORE
ROUTER --> HB
ROUTER --> RESEND
ROUTER --> REJECT
SDK --> SM --> OR
OR --> MDA
OR --> PM
OR --> EA
OBM --> PL --> ME
PTR --> POS
PTR --> KS
KS -->|No| EXEC[Execute Order]
KS -->|Yes| CANCEL[Cancel All Orders]
PTR -->|Fail| REJECT[Reject Order]
POS -->|Fail| REJECT
EXEC --> AUDIT
CANCEL --> AUDIT
REJECT --> AUDIT
ORCH --> CFG
ORCH --> LOG
ORCH --> MET
ORCH --> HC
ORCH --> TR
ORCH --> SLA
ORCH --> FF
ZT --> AUTHZ
ZT --> SEC
ZT --> REG
DOCKER --> K8S
flowchart LR
subgraph Client["Client Applications"]
WEB[Web Dashboard]
API[REST API]
WS[WebSocket Feed]
end
subgraph Gateway["API Gateway"]
LB[Load Balancer]
AUTH[Authentication]
RATE[Rate Limiter]
end
subgraph Services["Microservices"]
FEED[Feed Service]
ORDER[Order Service]
RISK[Risk Service]
POS[Position Service]
REPORT[Reporting Service]
end
subgraph Data["Data Layer"]
REDIS[(Redis\nCache)]
KAFKA[[Kafka\nEvent Bus]]
PG[(PostgreSQL\nPersistence)]
S3[[S3\nCold Storage]]
end
subgraph External["External"]
VENUE[Venue APIs]
MARKET[Market Data]
end
WEB --> LB
API --> LB
WS --> LB
LB --> AUTH --> RATE
RATE --> FEED
RATE --> ORDER
RATE --> RISK
RATE --> POS
RATE --> REPORT
FEED --> REDIS
FEED --> KAFKA
ORDER --> REDIS
ORDER --> KAFKA
RISK --> REDIS
POS --> PG
REPORT --> PG
REPORT --> S3
FEED --> MARKET
ORDER --> VENUE
sequenceDiagram
participant V as Venue
participant FS as FIX Session
participant MR as Message Router
participant MB as Message Builder
participant SB as Session Store
participant HB as Heartbeat
V->>FS: Logon (MsgType=A)
FS->>MB: Build Logon Response
MB->>V: Logon Ack
FS->>SB: Store Session State
loop Every 30s
HB->>V: Heartbeat (MsgType=0)
V->>HB: Heartbeat Ack
end
V->>MR: New Order Single (MsgType=D)
MR->>FS: Validate & Route
FS->>MB: Build Execution Report
MB->>V: Execution Report (MsgType=8)
V->>MR: Cancel Request (MsgType=F)
MR->>FS: Validate & Route
FS->>MB: Build Cancel Ack
MB->>V: Cancel Reject (MsgType=9) if invalid
stateDiagram-v2
[*] --> New: New Order Single (D)
New --> PendingNew: Risk Check Pass
New --> Rejected: Risk Check Fail
PendingNew --> Filled: Execution Report (8)
PendingNew --> PartiallyFilled: Partial Execution
PartiallyFilled --> Filled: Complete Execution
PendingNew --> Cancelled: Cancel Request (F)
Filled --> [*]
Rejected --> [*]
Cancelled --> [*]
note right of New
Pre-trade risk check
<2ms latency
end note
note right of Filled
Position update
P&L calculation
end note
flowchart TD
subgraph Inbound["Inbound Messages"]
LOGON[Logon\nMsgType=A]
ORDER[New Order Single\nMsgType=D]
CANCEL[Cancel Request\nMsgType=F]
REPLACE[Order Cancel/Replace\nMsgType=G]
MARKET[Market Data Request\nMsgType=V]
HEART[Heartbeat\nMsgType=0]
end
subgraph Processing["Message Processing"]
PARSE[FIX Parser]
VALIDATE[Message Validator]
ROUTE[Message Router]
TRANSFORM[Message Transformer]
end
subgraph Outbound["Outbound Messages"]
EXEC[Execution Report\nMsgType=8]
REJECT[Order Reject\nMsgType=9]
CACK[Cancel Ack\nMsgType=9]
MD[Market Data\nMsgType=W]
HBACK[Heartbeat Ack\nMsgType=0]
end
LOGON --> PARSE
ORDER --> PARSE
CANCEL --> PARSE
REPLACE --> PARSE
MARKET --> PARSE
HEART --> PARSE
PARSE --> VALIDATE --> ROUTE --> TRANSFORM
TRANSFORM --> EXEC
TRANSFORM --> REJECT
TRANSFORM --> CACK
TRANSFORM --> MD
TRANSFORM --> HBACK
flowchart LR
ORDER[Order Request] --> PTR[Pre-Trade Risk Check\n<2ms]
PTR -->|Pass| POS[Position Limit Check]
POS -->|Pass| KS{Kill Switch\nEngaged?}
KS -->|No| EXEC[Execute Order]
KS -->|Yes| CANCEL[Cancel All Orders]
PTR -->|Fail| REJECT[Reject Order]
POS -->|Fail| REJECT
EXEC --> AUDIT[Audit Trail\nRegulatory Log]
CANCEL --> AUDIT
REJECT --> AUDIT
subgraph RiskMetrics["Risk Metrics"]
VAR[Value at Risk\nHistorical/Parametric]
CVaR[Conditional VaR\nExpected Shortfall]
STRESS[Stress Testing\nHistorical Scenarios]
MC[Monte Carlo\nSimulation]
end
AUDIT --> VAR
AUDIT --> CVaR
AUDIT --> STRESS
AUDIT --> MC
flowchart TD
START[Order Received] --> CHECK1{Order Size\nLimit?}
CHECK1 -->|Pass| CHECK2{Price\nCollar?}
CHECK1 -->|Fail| REJECT1[Reject: Size Exceeded]
CHECK2 -->|Pass| CHECK3{Position\nLimit?}
CHECK2 -->|Fail| REJECT2[Reject: Price Out of Range]
CHECK3 -->|Pass| CHECK4{Notional\nLimit?}
CHECK3 -->|Fail| REJECT3[Reject: Position Exceeded]
CHECK4 -->|Pass| CHECK5{Velocity\nCheck?}
CHECK4 -->|Fail| REJECT4[Reject: Notional Exceeded]
CHECK5 -->|Pass| CHECK6{Kill Switch\nActive?}
CHECK5 -->|Fail| REJECT5[Reject: Velocity Exceeded]
CHECK6 -->|No| PASS[Risk Check Passed]
CHECK6 -->|Yes| KILL[Kill Switch Triggered]
REJECT1 --> LOG[Log Rejection]
REJECT2 --> LOG
REJECT3 --> LOG
REJECT4 --> LOG
REJECT5 --> LOG
KILL --> LOG
PASS --> LOG
flowchart LR
subgraph Inputs["Data Inputs"]
POS[Positions]
MARKET[Market Data]
HIST[Historical Data]
end
subgraph Calculations["Risk Calculations"]
VAR[Value at Risk\n95% / 99%]
CVaR[Conditional VaR\nExpected Shortfall]
STRESS[Stress Testing\n2008 / 2020 Scenarios]
MC[Monte Carlo\n10K Simulations]
GREEKS[Greeks\nDelta / Gamma / Vega]
end
subgraph Outputs["Risk Outputs"]
LIMITS[Dynamic Limits]
ALERTS[Risk Alerts]
REPORTS[Regulatory Reports]
DASH[Risk Dashboard]
end
POS --> VAR
POS --> CVaR
POS --> STRESS
POS --> MC
POS --> GREEKS
MARKET --> VAR
MARKET --> CVaR
MARKET --> STRESS
MARKET --> MC
HIST --> VAR
HIST --> STRESS
VAR --> LIMITS
CVaR --> LIMITS
STRESS --> LIMITS
MC --> LIMITS
GREEKS --> LIMITS
LIMITS --> ALERTS
LIMITS --> REPORTS
LIMITS --> DASH
flowchart TD
BUY[Buy Order] --> OBM[Order Book Manager]
SELL[Sell Order] --> OBM
OBM --> PL[Price Level]
PL --> ME{Matching Engine\nPrice-Time Priority}
ME -->|Match| TRADE[Generate Trade]
ME -->|No Match| ADD[Add to Book]
TRADE --> P&L[Update Position P&L]
ADD --> DEPTH[Update Market Depth]
flowchart TD
subgraph OrderBook["Order Book"]
subgraph Bids["Bids (Buy Orders)"]
B1[Price: 100.00\nQty: 500\nTime: 09:30:01]
B2[Price: 99.99\nQty: 300\nTime: 09:30:02]
B3[Price: 99.98\nQty: 200\nTime: 09:30:03]
end
subgraph Asks["Asks (Sell Orders)"]
A1[Price: 100.01\nQty: 400\nTime: 09:30:01]
A2[Price: 100.02\nQty: 600\nTime: 09:30:02]
A3[Price: 100.03\nQty: 100\nTime: 09:30:03]
end
end
subgraph Matching["Matching Process"]
NEW[New Sell Order\nPrice: 100.00\nQty: 450] --> CHECK{Check Best Bid}
CHECK -->|B1: 100.00 >= 100.00| MATCH[Match with B1]
MATCH --> FILL1[Fill 400 @ 100.00]
FILL1 --> REMAIN[Remaining: 50]
REMAIN --> CHECK2{Check Next Bid}
CHECK2 -->|B2: 99.99 < 100.00| NO[No Match]
NO --> ADD[Add to Book\nPrice: 100.00\nQty: 50]
end
flowchart LR
subgraph Priority["Price-Time Priority"]
P1[Price 100.00\nTime 09:30:01\nQty 100]
P2[Price 100.00\nTime 09:30:02\nQty 200]
P3[Price 100.00\nTime 09:30:03\nQty 300]
P4[Price 99.99\nTime 09:30:01\nQty 400]
P5[Price 99.99\nTime 09:30:02\nQty 500]
end
subgraph Execution["Execution Order"]
E1[1st: P1\nBest Price + Earliest]
E2[2nd: P2\nBest Price + 2nd Earliest]
E3[3rd: P3\nBest Price + 3rd Earliest]
E4[4th: P4\n2nd Best Price + Earliest]
E5[5th: P5\n2nd Best Price + 2nd Earliest]
end
P1 --> E1
P2 --> E2
P3 --> E3
P4 --> E4
P5 --> E5
flowchart TD
subgraph Cloud["Cloud / On-Premises"]
subgraph K8s["Kubernetes Cluster"]
subgraph Pods["Pods"]
APP[Apex Omega App\nMulti-replica]
REDIS[Redis\nSession Store]
KAFKA[Kafka\nEvent Bus]
end
INGRESS[Ingress Controller\nTLS Termination]
HPA[Horizontal Pod Autoscaler]
PDB[Pod Disruption Budget]
end
subgraph Monitoring["Observability"]
PROM[Prometheus\nMetrics]
GRAF[Grafana\nDashboards]
JAEGER[Jaeger\nDistributed Tracing]
ALERT[Alertmanager\nAlerting Rules]
end
end
INGRESS --> APP
APP --> REDIS
APP --> KAFKA
HPA --> APP
PDB --> APP
APP --> PROM
PROM --> GRAF
PROM --> ALERT
APP --> JAEGER
flowchart LR
subgraph Source["Source Control"]
GIT[Git Repository]
PR[Pull Request]
end
subgraph CI["Continuous Integration"]
BUILD[Build]
TEST[Run Tests\n2,065 tests]
LINT[Lint & Static Analysis]
SCAN[Security Scan]
end
subgraph CD["Continuous Deployment"]
STAGE[Staging]
CANARY[Canary Deploy]
PROD[Production]
end
subgraph Monitoring["Monitoring"]
METRICS[Metrics]
LOGS[Logs]
TRACES[Traces]
end
GIT --> PR --> BUILD --> TEST --> LINT --> SCAN
SCAN --> STAGE --> CANARY --> PROD
PROD --> METRICS
PROD --> LOGS
PROD --> TRACES
flowchart TD
subgraph Global["Global Load Balancer"]
GSLB[Global Server Load Balancer]
end
subgraph Region1["US-East"]
LB1[Load Balancer]
APP1[App Replicas]
RDS1[Redis Primary]
KAFKA1[Kafka Cluster]
end
subgraph Region2["EU-West"]
LB2[Load Balancer]
APP2[App Replicas]
RDS2[Redis Replica]
KAFKA2[Kafka Cluster]
end
subgraph Region3["APAC"]
LB3[Load Balancer]
APP3[App Replicas]
RDS3[Redis Replica]
KAFKA3[Kafka Cluster]
end
GSLB --> LB1
GSLB --> LB2
GSLB --> LB3
LB1 --> APP1
LB2 --> APP2
LB3 --> APP3
APP1 --> RDS1
APP2 --> RDS2
APP3 --> RDS3
RDS1 -.->|Replication| RDS2
RDS1 -.->|Replication| RDS3
APP1 --> KAFKA1
APP2 --> KAFKA2
APP3 --> KAFKA3
| Feature | Apex Omega | Murex | Calypso | Bloomberg | ION |
|---|---|---|---|---|---|
| FIX Protocol | 4.2/4.4/5.0 | 4.2/4.4 | 4.2/4.4 | Proprietary | 4.2/4.4 |
| Latency | <1ms | <1ms | <5ms | <10ms | <2ms |
| Order Book | 10K+ orders/sec | 5K/sec | 3K/sec | N/A | 8K/sec |
| Risk Engine | Pre-trade <2ms | Pre-trade <5ms | Pre-trade <10ms | N/A | Pre-trade <5ms |
| Venue Connectors | Bloomberg, MarketAxess | Multi-venue | Multi-venue | Bloomberg only | Multi-venue |
| Docker + K8s | ✅ | ❌ | ❌ | ❌ | ❌ |
| Open Source | AGPL-3.0 | ❌ | ❌ | ❌ | ❌ |
| LLM-Agnostic | ✅ | ❌ | ❌ | ❌ | ❌ |
| Regulatory Reporting | MiFID II RTS 22 | MiFID II | MiFID II | N/A | MiFID II |
| Metric | Apex Omega | Murex | Calypso | ION |
|---|---|---|---|---|
| Order Entry Latency | <1ms | <1ms | <5ms | <2ms |
| Market Data Latency | <1ms | <1ms | <5ms | <2ms |
| Risk Check Latency | <2ms | <5ms | <10ms | <5ms |
| Throughput | 10K+ orders/sec | 5K/sec | 3K/sec | 8K/sec |
| Feed Handling | 100K+ events/sec | 50K/sec | 20K/sec | 80K/sec |
| Concurrent Sessions | 1,000+ | 500+ | 200+ | 800+ |
| Memory Footprint | <2GB | <4GB | <8GB | <3GB |
| Startup Time | <30s | <60s | <120s | <45s |
| Dimension | Apex Omega | Murex | Calypso | ION |
|---|---|---|---|---|
| Horizontal Scaling | ✅ K8s HPA | ❌ Manual | ❌ Manual | ❌ Manual |
| Vertical Scaling | ✅ | ✅ | ✅ | ✅ |
| Multi-Region | ✅ | ❌ | ❌ | ❌ |
| Auto-Failover | ✅ | ❌ | ❌ | ❌ |
| Load Balancing | ✅ | ✅ | ✅ | ✅ |
| Session Affinity | ✅ | ✅ | ✅ | ✅ |
| Cost Factor | Apex Omega | Murex | Calypso | ION |
|---|---|---|---|---|
| License Fee | $0 (AGPL-3.0) | $500K+ | $300K+ | $200K+ |
| Infrastructure | $50K | $100K | $150K | $80K |
| Maintenance | $30K | $100K | $80K | $60K |
| Support | Community | Vendor | Vendor | Vendor |
| Total | $80K | $700K | $530K | $340K |
2,065 tests across 40 files, TDD-enforced.
Counts are pytest --collect-only verified — this is the number the suite actually
collects and runs. (A further 5 files / 185 tests written against modules that do not
exist in this repo are quarantined under tests/_unimplemented/; see the README there.)
| Module | Tests | Files |
|---|---|---|
| Order Book | 543 | 4 |
| FIX Protocol | 411 | 8 |
| Core Infrastructure | 254 | 4 |
| Venue Connectors | 189 | 3 |
| Risk Engine | 183 | 5 |
| Feed Handler | 159 | 5 |
| Performance | 92 | 3 |
| Security | 85 | 3 |
| Deployment | 70 | 3 |
| API Gateway | 57 | 1 |
| Integration | 22 | 1 |
| Total | 2,065 | 40 |
# Run all tests
make test
# Run with coverage
make test-coverage
# Run specific module
make test FIX
make test orderbook
make test risk
# Run performance tests
make test-perf
# Run integration tests
make test-integrationAGPL-3.0
Copyright (c) 2024 Ahmed Hassan
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.