Skip to main content

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
strategy.signal@v1 strategy.signal.v1.schema.json Trading signals from strategy service
exec.order.filled@v1 exec.order.filled.v1.schema.json Order execution confirmations
risk.signal.allowed@v1 risk.signal.allowed.v1.schema.json Risk validation results
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

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

  1. Create schema file in kafka/ directory
  2. Follow naming convention: {event}.v{version}.schema.json
  3. Add example in examples/ directory
  4. Update this README with new event details

Schema Requirements

All schemas must include:

  • event_id: Unique event identifier
  • version: Schema version (const value)
  • ts: Timestamp in ISO 8601 format
  • additionalProperties: false for strict validation

License

MIT License - see LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trading_contracts-0.1.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trading_contracts-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file trading_contracts-0.1.0.tar.gz.

File metadata

  • Download URL: trading_contracts-0.1.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for trading_contracts-0.1.0.tar.gz
Algorithm Hash digest
SHA256 233c51b4962e864bdc37f319193c0a33568cb07cb01bd4ccba471949a85a1b6b
MD5 0f70e7385859b298e6e5253303135c2f
BLAKE2b-256 4ca825ead90517faae50e52e124b77e4900e69d3206a3a97a6743fcd88a0c7ac

See more details on using hashes here.

File details

Details for the file trading_contracts-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for trading_contracts-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 50eb7cc3f2d600bbd9a7e3243d6fc2b74f4972cb2388ff433a95ad4c739daa02
MD5 1aea6dc41774f8ebdd4c49f39b21abe7
BLAKE2b-256 8184c2eabf4c0e25424fb78e91f5bc59dbb8486d03310c229b307588be4f1db2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page