Skip to main content

Cache-first market bar archive: fetch from Polygon (or others), store 1m bars, return any timeframe. No pandas required for callers.

Project description

Barvault

Cache-first market bar archive: fetch from Polygon (or other providers), store 1-minute bars in S3 or local, return any timeframe. Callers can use plain Python (datetime, list[dict]) — no pandas required.

  • deterministic archive reads (stable ordering + explicit boundary semantics)
  • a single golden source stored in the archive: 1-minute bars
  • stateless configuration (no module globals, no env lookups at import-time)

Install (Poetry)

poetry install

Quick usage

from __future__ import annotations

from datetime import datetime, timezone

from market_data import ArchiveConfig, MarketDataClient, PolygonConfig

cfg = ArchiveConfig.s3(bucket="public-market-data-truth-trader", prefix="md-archive")
client = MarketDataClient(cfg, polygon=PolygonConfig(api_key="YOUR_POLYGON_KEY"))

records = client.get_bars_records(
    ["AAPL"],
    start=datetime(2025, 1, 2, 14, 30, tzinfo=timezone.utc),
    end=datetime(2025, 1, 2, 15, 30, tzinfo=timezone.utc),
    timeframe="5min",
)
print(records[:2])

Fetch + cache (Polygon) + return any timeframe

The archive’s golden source is always 1-minute bars. MarketDataClient will:

  • read what’s already in the archive for [start, end)
  • detect missing expected minutes (using the provided calendar)
  • fetch missing data from Polygon
  • write 1m bars back to the archive (merge + de-dupe)
  • return 1m or any derived timeframe (resampled from 1m)
from __future__ import annotations

from market_data import ArchiveConfig, MarketDataClient, PolygonConfig

# Local archive:
# cfg = ArchiveConfig.local(root="/tmp/md-archive")
#
# S3 archive:
cfg = ArchiveConfig.s3(bucket="public-market-data-truth-trader", prefix="md-archive")

client = MarketDataClient(
    cfg,
    polygon=PolygonConfig(api_key="YOUR_POLYGON_KEY"),
)

# Always returns data for [start,end) (start inclusive, end exclusive).
bars_1m = client.get_bars(
    ["AAPL", "MSFT"],
    start="2025-01-02T14:30:00Z",
    end="2025-01-02T15:30:00Z",
    timeframe="1min",
)

# Derived timeframe (resampled from 1m):
bars_5m = client.get_bars(
    ["AAPL"],
    start="2025-01-02T14:30:00Z",
    end="2025-01-02T15:30:00Z",
    timeframe="5min",
)

# If you don't want to work with pandas DataFrames, use plain Python records:
records_5m = client.get_bars_records(
    ["AAPL"],
    start="2025-01-02T14:30:00Z",
    end="2025-01-02T15:30:00Z",
    timeframe="5min",
)

Timeframe notes:

  • Use pandas-compatible offset strings like "5min", "1h", "1D".
  • Do not use "1m" to mean 1 minute — in pandas "m" means months.

Design constraints

  • import market_data must not start servers, read env vars, or require credentials
  • all configuration is passed via constructors/args (ArchiveConfig, provider constructors, etc.)
  • only 1m is accepted by the writer; higher timeframes are derived from 1m (never written)

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

truthtrader_barvault-0.1.1.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

truthtrader_barvault-0.1.1-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file truthtrader_barvault-0.1.1.tar.gz.

File metadata

  • Download URL: truthtrader_barvault-0.1.1.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for truthtrader_barvault-0.1.1.tar.gz
Algorithm Hash digest
SHA256 81feabe89d679dca7da6193bbc25ed666ed5cc94f850cfc03498766ed6890a6d
MD5 1124c95095ee62af52acb3db98da86c0
BLAKE2b-256 1933fc795ada98cf8a7517ee82b9fd3ce16f2c7ef9e306d63332f058e6699c67

See more details on using hashes here.

Provenance

The following attestation bundles were made for truthtrader_barvault-0.1.1.tar.gz:

Publisher: publish-pypi.yml on meetorman/truthtrader-barvault

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file truthtrader_barvault-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for truthtrader_barvault-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6f49276b5185e8e3c7eb9ef00093b35d3118e532495657154c7ff9c6bceed5d0
MD5 729d253916aa851978bb0737c3f285a7
BLAKE2b-256 b2190643f39acf016f77a902f439cbda6478e0d7e4b947438ea24fbd98aa260c

See more details on using hashes here.

Provenance

The following attestation bundles were made for truthtrader_barvault-0.1.1-py3-none-any.whl:

Publisher: publish-pypi.yml on meetorman/truthtrader-barvault

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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