JSON Schemas for trading platform events
Project description
Trading Contracts
JSON Schema validation library for trading platform events. This package provides schemas and validation tools for Kafka events used across the trading platform services.
Features
- JSON Schema Validation: Pre-defined schemas for all trading platform events
- Python Package: Easy integration with Python services
- Version Management: Schema versioning with semantic versioning support
- Type Safety: Full type hints and validation
Installation
pip install trading-contracts
Quick Start
from trading_contracts import validate_event, load_schema
# Validate an event
event_data = {
"event_id": "evt_123",
"version": 1,
"instance_id": "inst_001",
"symbol": "BTCUSDT",
"side": "BUY",
"price": "45000.50",
"ts": "2024-01-15T10:30:00Z"
}
try:
validate_event("strategy.signal@v1", event_data)
print("Event is valid!")
except ValidationError as e:
print(f"Validation failed: {e}")
# Load schema for inspection
schema = load_schema("strategy.signal@v1")
print(f"Schema title: {schema['title']}")
Available Schemas
| Event | Schema File | Description |
|---|---|---|
md.candle.closed@v1 |
md.candle.closed.v1.schema.json |
Market data candle close events |
strategy.signal@v1 |
strategy.signal.v1.schema.json |
Trading signals from strategy service |
risk.signal.allowed@v1 |
risk.signal.allowed.v1.schema.json |
Risk validation approvals |
risk.signal.denied@v1 |
risk.signal.denied.v1.schema.json |
Risk validation denials |
risk.limit.breached@v1 |
risk.limit.breached.v1.schema.json |
Risk limit breaches |
exec.order.placed@v1 |
exec.order.placed.v1.schema.json |
Order placement events |
exec.order.rejected@v1 |
exec.order.rejected.v1.schema.json |
Order rejection notifications |
exec.order.filled@v1 |
exec.order.filled.v1.schema.json |
Order execution confirmations |
pf.position.updated@v1 |
pf.position.updated.v1.schema.json |
Portfolio position updates |
pf.balance.updated@v1 |
pf.balance.updated.v1.schema.json |
Account balance updates |
pf.pnl.updated@v1 |
pf.pnl.updated.v1.schema.json |
Portfolio P&L updates |
runs.started@v1 |
runs.started.v1.schema.json |
Strategy run lifecycle events |
runs.status.changed@v1 |
runs.status.changed.v1.schema.json |
Run status transitions |
runs.finished@v1 |
runs.finished.v1.schema.json |
Run completion events |
HTTP API
OpenAPI specification for HTTP endpoints is available in http/openapi.yaml.
Schema Naming Convention
Schemas follow the pattern: {service}.{event_type}@v{version}
- service: Service identifier (strategy, exec, risk, pf, runs)
- event_type: Specific event type (signal, order.filled, etc.)
- version: Schema version number
Development
Setup
git clone <repository>
cd contracts
pip install -e ".[dev]"
Running Tests
pytest
Code Quality
black src/
isort src/
mypy src/
Adding New Schemas
- Create schema file in
kafka/directory - Follow naming convention:
{event}.v{version}.schema.json - Add example in
examples/directory - Update this README with new event details
Schema Requirements
All schemas must include:
event_id: Unique event identifierversion: Schema version (const value)ts: Timestamp in ISO 8601 formatadditionalProperties: falsefor strict validation
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file trading_contracts-0.2.0.tar.gz.
File metadata
- Download URL: trading_contracts-0.2.0.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a229c5a52cdee82934febe837690975263acfa28398780466902966dbd768f1a
|
|
| MD5 |
d65e0be9942d1a3ea72f2e8cdd1c87e8
|
|
| BLAKE2b-256 |
a0061a6c0cfdbd83d94981c8b7c9537539eb850bb3ea262c1a93d68aaa3d985b
|
File details
Details for the file trading_contracts-0.2.0-py3-none-any.whl.
File metadata
- Download URL: trading_contracts-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ecaf7fe7ce45f074860388c4cdf0077deb7908916d4e4c37d4a8d7ee962602e
|
|
| MD5 |
fe056edeacc5530fc9014934d92b80fc
|
|
| BLAKE2b-256 |
3986bd9600812f7d6f3725d3eea5a1f2cc03e1dc9b7c0188294f18bff66e5107
|