Skip to main content

Canonical schemas for AmpyFin (generated Python protobufs)

Project description

ampy-proto

Go Version Python Version Protocol Buffers License: MIT

Canonical Protocol Buffer schemas for financial data processing

ampy-proto provides type-safe, cross-language schemas for financial market data including bars, ticks, orders, fills, and more. Built for high-precision trading systems with support for Go, Python, and C++.

🚀 Quick Start

Go

# Install the convenience package (imports all schemas)
go get github.com/AmpyFin/ampy-proto/v2@v2.0.9

# Or install specific packages only
go get github.com/AmpyFin/ampy-proto/v2/gen/go/ampy/bars/v1@v2.0.9
package main

import (
    "fmt"
    "time"
    
    "github.com/AmpyFin/ampy-proto/v2/pkg/ampy"
    bars "github.com/AmpyFin/ampy-proto/v2/gen/go/ampy/bars/v1"
    common "github.com/AmpyFin/ampy-proto/v2/gen/go/ampy/common/v1"
    "google.golang.org/protobuf/proto"
    "google.golang.org/protobuf/types/known/timestamppb"
)

func main() {
    bar := &bars.Bar{
        Security: &common.SecurityId{
            Symbol: "AAPL",
            Mic:    "XNAS",
        },
        Start: timestamppb.New(time.Now().Add(-time.Minute)),
        End:   timestamppb.New(time.Now()),
        Open: &common.Decimal{
            Scaled: 15000,  // 150.00 with scale 2
            Scale:  2,
        },
        Close: &common.Decimal{
            Scaled: 15050,  // 150.50 with scale 2
            Scale:  2,
        },
        Volume: 1000,
    }

    data, _ := proto.Marshal(bar)
    fmt.Printf("Serialized %d bytes using ampy-proto v%s\n", len(data), ampy.Version)
}

Python

pip install ampy-proto==2.0.9
from ampy.bars.v1 import bars_pb2
from ampy.common.v1 import common_pb2

bar = bars_pb2.Bar()
bar.security.symbol = "AAPL"
bar.security.mic = "XNAS"
bar.open.scaled = 15000
bar.open.scale = 2
bar.close.scaled = 15050
bar.close.scale = 2
bar.volume = 1000

print(f"Price: ${bar.close.scaled / (10 ** bar.close.scale):.2f}")

📊 Available Schemas

Domain Purpose Key Messages
bars OHLCV price bars Bar, BarBatch
ticks Trade and quote data Tick, TickBatch
orders Order management Order, OrderRequest
fills Trade executions Fill
signals Trading signals Signal
fundamentals Financial statements Fundamental
news Market news NewsItem
fx Foreign exchange FxRate
positions Portfolio positions Position
universe Tradable securities Universe
common Shared types Decimal, SecurityId, Money

🎯 Key Features

High-Precision Decimals

Avoid floating-point errors with scaled decimal types:

price := &common.Decimal{
    Scaled: 15050,  // 150.50
    Scale:  2,      // 2 decimal places
}

Time Discipline

Clear separation of event time vs. ingest time:

bar := &bars.Bar{
    EventTime:  timestamppb.New(marketTime),  // When it happened
    IngestTime: timestamppb.New(now),         // When we received it
}

Security Identification

Proper market identification beyond just tickers:

security := &common.SecurityId{
    Symbol: "AAPL",
    Mic:    "XNAS",  // Market identifier code
    Figi:   "BBG000B9XRY4",  // Optional
}

🛠️ Development

Prerequisites

  • Buf for protobuf management
  • Go 1.23+ for Go code generation
  • Python 3.9+ for Python code generation
  • CMake and C++17 compiler for C++ code generation

Building

# Generate code for all languages
make gen

# Lint protobuf files
make lint

# Run tests
make test

# Build Python package
make py-build

Testing

# Test Go imports
go run examples/go/smoke/main.go

# Test Python imports
python examples/python/smoke.py

# Run roundtrip tests
make test

📈 Versioning

This project follows semantic versioning:

  • Major versions (v2, v3): Breaking changes requiring migration
  • Minor versions (v2.1, v2.2): Additive changes, backward compatible
  • Patch versions (v2.0.8, v2.0.9): Bug fixes, backward compatible

Current version: v2.0.9

🔧 Requirements

Go

require (
    github.com/AmpyFin/ampy-proto/v2 v2.0.9+
    google.golang.org/protobuf v1.36.8
)

Python

# pyproject.toml
dependencies = ["protobuf>=6.32.0,<7"]

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/your-feature
  3. Make your changes and add tests
  4. Run make lint and make test
  5. Submit a pull request

Schema Evolution Rules

  • Add new optional fields with default values
  • Add new enum values (append only)
  • Add new messages or services
  • Never change field numbers of existing fields
  • Never change field types of existing fields
  • Never remove fields (mark as deprecated instead)

📄 License

MIT License - see LICENSE file for details.

🆘 Support


Part of the AmpyFin ecosystem - building the future of algorithmic trading.

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

ampy_proto-2.0.9.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

ampy_proto-2.0.9-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file ampy_proto-2.0.9.tar.gz.

File metadata

  • Download URL: ampy_proto-2.0.9.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ampy_proto-2.0.9.tar.gz
Algorithm Hash digest
SHA256 1a3da4684792d19046ece28c8db82738590d130c44dc239f718ff1626a022cac
MD5 7f90578a5344717200f98c099b173b3e
BLAKE2b-256 83aca75e027a42a473392ac928cfd06c0d8d0407f014870720e875d34e916715

See more details on using hashes here.

File details

Details for the file ampy_proto-2.0.9-py3-none-any.whl.

File metadata

  • Download URL: ampy_proto-2.0.9-py3-none-any.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ampy_proto-2.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 985a99c471decb8da2c7bee42e463536693aa92a63eba5ce9234bbe708b9eb64
MD5 65dffa091bfd18020536526a15afe3e0
BLAKE2b-256 c0da07484c8f45063f99bf6ed308a5f18803cfed211189551e9a4ed250427247

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