Market Data Source
Financial precision with Decimal types | Python & Rust dual ecosystem support | Extensible architecture
Market Data Source is a Rust library for generating realistic synthetic market data with Python bindings. It provides a unified interface to generate real-time and historical market data, making it easier for developers to integrate market data into their applications for backtesting, research, and development.
Why Market Data Source?
- No API limits - Generate unlimited data without rate limiting
- No costs - Completely free and open source
- Reproducible - Deterministic generation with seed support
- Native bindings - Use from both Rust and Python
- Flexible - Export to CSV, JSON, PNG charts, or stream to CouchDB
Key features:
- Rust implementation with Python bindings via PyO3
- Realistic data generation using advanced algorithms to simulate market conditions
- Multiple export formats including CSV, JSON, CouchDB, and PNG charts
- Extensible architecture allowing users to easily add custom algorithms
Features
- Configurable synthetic market data generation
- Support for OHLC candles and tick data
- Random walk with drift algorithm
- Multiple export formats:
- CSV export for data analysis
- JSON and JSON Lines export
- CouchDB integration for NoSQL storage
- PNG chart generation for data visualization
- Deterministic generation with seed support
- Streaming generation for large datasets
- Extensible architecture for adding new algorithms
Installation
Quick Install
Python (pip)
Rust (Cargo)
[]
= "0.3.0"
Detailed Installation
Python Installation
Option 1: Install from PyPI (Recommended)
# Using pip
# Using uv (faster)
Option 2: Build from source
# Clone the repository
# Install with maturin
Rust Installation
Add to your Cargo.toml:
[]
= "0.3.0"
# Or with specific features
= {
version = "0.3.0",
= ["csv_export", "json_export", "png_export"]
}
Available features:
csv_export- CSV file export supportjson_export- JSON/JSONL export supportpng_export- PNG chart generationcouchdb- CouchDB database exportdotenvy- Environment variable configurationserde- Serialization support
Quick Start
Python Example
# Create generator with configuration
=
# Generate 100 OHLC candles
=
# Export to various formats
Rust Example
use ;
See examples/ directory for more comprehensive examples.
Environment Variables
Market Data Source supports configuration through environment variables. Copy .env.example to .env and configure your settings:
# Edit .env with your actual values
Key environment variables:
COUCHDB_URL: CouchDB server URL (default: http://localhost:5984)COUCHDB_USERNAME/COUCHDB_PASSWORD: Optional authenticationCOUCHDB_DATABASE: Database name (default: market_data)EXPORT_BATCH_SIZE: Batch size for bulk operations (default: 1000)- API keys for future data providers (Alpha Vantage, Polygon, Finnhub, etc.)
See .env.example for the complete list of available environment variables.
Usage
Python Usage
Market Data Source provides a Pythonic API for generating market data:
# Create generator with configuration
=
# Generate OHLC data
=
# Convert to pandas DataFrame
=
=
# Generate tick data
=
# Use preset configurations
=
=
=
=
# Export data
See examples/python/ for more complete examples including pandas integration.
Rust Usage
Here's a simple example of how to use Market Data Source in Rust:
use ;
Data Export
Market Data Source supports multiple export formats for different use cases:
CSV Export
Export generated data to CSV files for analysis in Excel, pandas, or other tools:
use ;
use ;
JSON Export
Export data in JSON or JSON Lines format:
use ;
// Standard JSON format using convenience function
to_json_ohlc?;
// JSON Lines format (one JSON object per line)
to_jsonl_ohlc?;
// Or use the exporter directly for custom options
use ;
use DataExporter;
// Pretty-printed JSON
let json_exporter = with_options;
json_exporter.export_ohlc?;
// JSON Lines format
let jsonl_exporter = with_options;
jsonl_exporter.export_ohlc?;
CouchDB Export
Export data directly to CouchDB for NoSQL storage and replication:
use ;
Running Examples
The library includes comprehensive examples for all export formats:
# CSV export example
# JSON export example
# CouchDB export example (requires CouchDB running)
# PNG chart export example
# All export formats example
Current Status
✅ v0.1.0 Foundation Complete
- Library structure implemented
- Core data types (OHLC, Tick, Volume)
- Market data generator with configurable parameters
- Random walk with drift algorithm
- Builder pattern for configuration
- Comprehensive export infrastructure:
- CSV export with streaming support and custom options
- JSON and JSON Lines export with pretty printing
- CouchDB integration with bulk operations
- PNG chart generation with candlestick charts, line charts, volume bars, and moving averages
- Proper error handling with structured error types
- Serde serialization support
- 54+ tests passing (unit tests + integration tests + comprehensive export tests)
- Complete example suite demonstrating all export formats
🚧 In Development
- Additional generation algorithms
- More sophisticated market patterns
- API emulation features
Automated Releases
Market Data Source uses GitHub Actions with trusted publishing (OIDC) for secure, automated releases to both crates.io and PyPI without storing API tokens.
Release Process
To create a new release:
- Update version in
Cargo.tomlandpyproject.toml - Update
CHANGELOG.mdwith release notes - Commit and push changes
- Create and push a version tag:
The automated workflow will:
- Validate version consistency
- Run full test suite across all platforms
- Build and publish to crates.io
- Build Python wheels for multiple platforms
- Publish to PyPI
- Create GitHub release with artifacts
Testing Publication Setup
Test the publishing configuration without releasing:
# Via GitHub Actions UI:
# Actions → Test Publishing Setup → Run workflow
For more details, see .github/PUBLISHING.md.
Release Process
Market Data Source uses GitHub Actions for automated releases to both crates.io and PyPI. For complete documentation, see docs/RELEASE.md.
Quick Release
# 1. Prepare a patch release (e.g., 0.3.0 -> 0.3.1)
# 2. Review and update CHANGELOG.md
# 3. Commit and push the tag
Version Management
Versions are synchronized between Cargo.toml and pyproject.toml:
# Check version consistency
# Set specific version
Release Types
- Patch: Bug fixes (
python scripts/prepare-release.py --bump patch) - Minor: New features (
python scripts/prepare-release.py --bump minor) - Major: Breaking changes (
python scripts/prepare-release.py --bump major)
Automated Workflow
The release workflow automatically:
- Validates version consistency and runs all tests
- Builds packages for all platforms
- Publishes to crates.io and PyPI
- Creates GitHub release with artifacts
- Prepares PR for next development version
For detailed procedures and troubleshooting, see docs/RELEASE.md.
Contributing
Contributions are welcome! If you'd like to contribute to Market Data Source, please fork the repository and submit a pull request.
License
This project is licensed under the MIT License - see the LICENSE file for details.