
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
A Python package containing ORM models for a PostgreSQL database that powers a personal quantitative trading and investment analysis platform.
This package provides SQLAlchemy ORM models and database utilities for managing financial data, trading strategies, portfolio analytics, and market research. The database serves as the backbone for a personal "quant hedge fund" project, storing everything from market data and content data.
AssetType
and Asset
tables for categorizing and managing financial instruments and various fiat and digital currenciesProviderType
and Provider
tables for handling data sources and exchangesProviderAssetMarket
table for storing OHLCV and bid/ask price dataProviderAssetOrder
table for tracking trading orders between assetsContentType
, ProviderContent
, and AssetContent
tables for managing news articles and social contentProviderAsset
table for mapping relationships between providers and assetspip install mc-postgres-db
# Clone the repository
git clone <repository-url>
cd mc-postgres-db
# Install using uv (recommended)
uv sync
export SQLALCHEMY_DATABASE_URL="postgresql://username:password@localhost:5432/mc_trading_db"
from sqlalchemy import create_engine, select
from sqlalchemy.orm import Session
from mcpdb.tables import Asset, Provider, ProviderAssetMarket
# Create database connection
url = "postgresql://username:password@localhost:5432/mc_trading_db"
engine = create_engine(url)
# Query assets
with Session(engine) as session:
stmt = select(Asset).where(Asset.is_active)
assets = session.scalars(stmt).all()
asset_pairs = {asset.id: asset.name for asset in assets}
print("Available assets:")
for asset_id, asset_name in asset_pairs.items():
print(f"{asset_id}: {asset_name}")
# Query market data
with Session(engine) as session:
stmt = (
select(ProviderAssetMarket)
.where(
ProviderAssetMarket.asset_id == 1, # Bitcoin for example
ProviderAssetMarket.provider_id == 2, # Binance for example
)
.order_by(ProviderAssetMarket.timestamp.desc())
.limit(10)
)
market_data = session.scalars(stmt).all()
for data in market_data:
print(f"Timestamp: {data.timestamp}, Close: {data.close}, Volume: {data.volume}")
# Get assets from a provider
with Session(engine) as session:
stmt = select(Provider).where(Provider.id == 1)
provider = session.scalars(stmt).one()
provider_assets = provider.get_all_assets(engine)
print(f"Assets available from {provider.name}:")
for provider_asset in provider_assets:
print(f"Asset code: {provider_asset.asset_code}")
# Install development dependencies using uv
uv sync --dev
# Run tests
uv run pytest
# Run linting
uv run ruff check
uv run ruff format
# Generate new migration
uv run alembic revision --autogenerate -m "Description of changes"
# Apply migrations
uv run alembic upgrade head
# Rollback migration
uv run alembic downgrade -1
mc-postgres-db/
├── src/ # Source code directory
│ └── mc_postgres_db/ # Main package directory
│ ├── __init__.py
│ ├── models.py
│ ├── operations.py
│ ├── prefect/
│ │ ├── __init__.py
│ │ ├── tasks.py
│ │ └── asyncio/
│ │ ├── __init__.py
│ │ └── tasks.py
│ └── testing/
│ ├── __init__.py
│ └── utilities.py
├── tests/ # Unit and integration tests
├── alembic/ # Database migrations
├── pyproject.toml # Project configuration and dependencies
├── uv.lock # Locked dependency versions
└── README.md # Project documentation
This database integrates with various financial data providers:
This package provides a robust testing harness for database-related tests, allowing you to run your tests against a temporary SQLite database that mirrors your PostgreSQL schema. This is especially useful for testing Prefect flows and tasks that interact with the database, without requiring a live PostgreSQL instance or extensive mocking.
postgres_test_harness
The postgres_test_harness
context manager (found in mc_postgres_db.testing.utilities
) creates a temporary SQLite database file, initializes all ORM models, and patches the Prefect tasks used to obtain the SQLAlchemy engine (both sync and async) so that all database operations in your flows and tasks are transparently redirected to this SQLite database.
Key benefits:
get_engine
(sync or async) will automatically use the temporary SQLite database.You can use the harness as a fixture in your tests. For example:
import pytest
from mc_postgres_db.testing.utilities import postgres_test_harness
@pytest.fixture(scope="function", autouse=True)
def postgres_harness():
with postgres_test_harness():
yield
def test_my_flow():
# Any Prefect task that calls get_engine() will use the SQLite test DB
...
If you are also testing Prefect flows, the postgres harness will already use Prefect's harness to ensure isolation:
import pytest
from mc_postgres_db.testing.utilities import postgres_test_harness
@pytest.fixture(scope="session", autouse=True)
def postgres_harness():
with postgres_test_harness(prefect_server_startup_timeout=45):
yield
Now, all your tests (including those that run Prefect flows) will use the temporary SQLite database, and you don't need to modify your flows or tasks to support testing.
This is a personal project, but suggestions and improvements are welcome:
This project is for personal use and learning purposes.
This software is for educational and personal use only. It is not intended for production trading or investment advice. Use at your own risk.
FAQs
Add your description here
We found that mc-postgres-db demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.