Skip to main content

ArcticDB-backed time series cache with incremental updates — fetch once, upsert the gap.

Project description

arctic-incr-cache

ArcticDB-backed time series cache with incremental updates.

First call fetches the full window from your data source and stores it in ArcticDB. Subsequent calls only fetch the gap between the cached tail and the requested end — then merge and upsert. Incomplete (still-updating) bars are automatically excluded from storage so they never overwrite finalised data.

Install

pip install arctic-incr-cache
# or
uv add arctic-incr-cache

Quick start

import datetime
import arcticdb as adb
from arctic_incr_cache import IncrCache

arctic = adb.Arctic("lmdb://data/arcticdb")
lib = arctic.get_library("ohlcv-1d", create_if_missing=True)

cache = IncrCache(
    lib,
    fetch=lambda symbol, end, count: your_api.get_daily_bars(symbol, end=end, count=count),
)

df = cache.get("AAPL", end=datetime.date(2024, 6, 1), count=60)
  • First call — fetches 60 bars from your API, stores in ArcticDB, returns.
  • Second call (same or later end) — serves from ArcticDB; fetches only the gap if the cache is stale.

Intraday data

Set bar_minutes to the bar width and provide get_tz to return the market timezone:

from zoneinfo import ZoneInfo

intraday = IncrCache(
    lib,
    fetch=lambda symbol, end, count: your_api.get_minute_bars(symbol, end=end, count=count),
    bar_minutes=1,
    default_count=390 * 5,
    get_tz=lambda symbol: ZoneInfo("America/New_York"),
)

Concurrency

By default writes run in a daemon thread. Pass spawn and lock_class for gevent or other async runtimes:

import gevent
import gevent.lock

cache = IncrCache(
    lib,
    fetch=my_fetch,
    spawn=gevent.spawn,
    lock_class=gevent.lock.BoundedSemaphore,
)

Constructor parameters

Parameter Required Description
library yes ArcticDB library instance
fetch(symbol, end, count) yes Fetch raw data from upstream; return tz-naive local-time DataFrame
bar_minutes no Bar width in minutes (default 1440 = daily)
default_count no Bars returned when count is omitted (default 252)
get_tz(symbol) no Market timezone (tzinfo) or None for daily (default: None)
spawn no Fire-and-forget callable for async writes (default: daemon thread)
lock_class no Lock constructor (default: threading.Lock)

License

MIT

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

arctic_incr_cache-0.1.0.tar.gz (45.0 kB view details)

Uploaded Source

Built Distribution

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

arctic_incr_cache-0.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file arctic_incr_cache-0.1.0.tar.gz.

File metadata

  • Download URL: arctic_incr_cache-0.1.0.tar.gz
  • Upload date:
  • Size: 45.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for arctic_incr_cache-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fac2edb64c3b55e701bc96744308b3740a1c003b839aabbb5fe8456581bfa9d8
MD5 7333f93e414754907ae93dea2f8df41f
BLAKE2b-256 822d75733d5076c5b58fc86e6b142783c99bd0d834acff34a786355e29d67f6e

See more details on using hashes here.

File details

Details for the file arctic_incr_cache-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for arctic_incr_cache-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8cf21ba01232b867a7be74b276eff7658cd1b015d9543c0e1cf3c5690dde4a10
MD5 79d9ffb6b2839825143233053c7de471
BLAKE2b-256 09ad51ed6eb0d8f64b5577ca954d790956e3e5c1a208e3b91bc32ea36a464ef4

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