Skip to main content

petrosa-contracts

Canonical, shared pydantic contracts for the Petrosa trading path.

This package resolves petrosa_k8s#1116: contracts/signal.py and contracts/trading_config.py were copy-pasted into petrosa-cio/ and petrosa-tradeengine/ and had diverged in both directions (CIO had leverage, tradeengine had decision_id; the TradingConfigAudit.config_type enum differed). One of those divergences (leverage reaching tradeengine) was the direct cause of petrosa-tradeengine#599 — a P0 where every position traded at a hardcoded 10x leverage because the field was silently dropped by extra="ignore".

What's here

  • petrosa_contracts.signal.Signal and its enums (SignalType, SignalStrength, TimeFrame, OrderType, TimeInForce, StrategyMode) — the reconciled superset of both repos' Signal models, with both leverage and decision_id.
  • petrosa_contracts.trading_config.TradingConfig, TradingConfigAudit, LeverageStatus — the reconciled superset, with TradingConfigAudit supporting all four config_type values (global, symbol, symbol_side, strategy).
  • Every model sets model_config = ConfigDict(extra="forbid"). A producer field with no matching consumer attribute now raises ValidationError at parse time instead of being silently discarded.

Installation

Install the published package from PyPI:

pip install petrosa-contracts

For local development only, contributors with access to the private repository may install directly from the source tree:

pip install "petrosa-contracts @ git+https://github.com/PetroSa2/petrosa_k8s.git@main#subdirectory=petrosa-contracts"

This private-repository URL requires repository access and must not appear in a public consumer's requirements.txt. Tags named petrosa-contracts-vX.Y.Z trigger the publication workflow.

Usage

from petrosa_contracts import Signal, TradingConfig

signal = Signal(
    strategy_id="orderbook_skew",
    symbol="BTCUSDT",
    action="buy",
    confidence=0.82,
    price=65000.0,
    quantity=0.01,
    current_price=65000.0,
    source="petrosa-cio",
    strategy="orderbook_skew",
    leverage=5,
    decision_id="a1b2c3d4e5f6",
)

# Any field neither producer nor consumer declared now raises immediately:
Signal(**{**signal.model_dump(), "unexpected_field": 1})
# -> pydantic.ValidationError: Extra inputs are not permitted

Scope of petrosa_k8s#1116 covered by this package

This PR creates the canonical package and its contract tests (petrosa_k8s#1116 AC: "exist in exactly one place", "superset reconciling both divergences", "extra=forbid", "contract test in CI"). It does not yet remove the vendored copies from petrosa-cio/contracts/ and petrosa-tradeengine/contracts/ or switch those services to import from this package — that requires coordinated, staged changes in each of those repos' own CI/deploy pipelines and is tracked as follow-up work:

  • petrosa-cio: migrate to petrosa_contracts, delete the vendored copy.
  • petrosa-tradeengine: migrate to petrosa_contracts, delete the vendored copy.

Both follow-ups should keep the same staged-rollout discipline the parent ticket calls for (log-then-enforce) for any field this package's extra="forbid" newly rejects that either service's real traffic still sends.

Development

cd petrosa-contracts
pip install -e ".[dev]"
pytest --cov=petrosa_contracts --cov-report=term-missing
ruff check src/ tests/
ruff format --check src/ tests/

Metadata

Release files for petrosa-contracts 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for petrosa-contracts 0.1.0
File Size Uploaded
petrosa_contracts-0.1.0.tar.gz 12.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for petrosa-contracts 0.1.0
File Interpreter ABI Platform
petrosa_contracts-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.1 kB

Release files / petrosa_contracts-0.1.0.tar.gz

Download URL petrosa_contracts-0.1.0.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0bf925313dddcbe2f7335158d8a603b6b847382a9dbe3c7ca69cebf411bd23ee
BLAKE2b-256 checksum
How to use checksums
fb57a98ef82d152e04afb463686f417a106bc1e969e932167c3ccd15405d9c7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release files / petrosa_contracts-0.1.0-py3-none-any.whl

Download URL petrosa_contracts-0.1.0-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f2e6de220333686b80f094230aad4f5123df23168411a4b9901d9b73ba39bb36
BLAKE2b-256 checksum
How to use checksums
0c37c28180fecbf03efe88cbf1b9e568376adf740ead39a1681fa271c7a45815
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page