PairCandleCache#
API documentation for tradingstrategy.transport.pair_candle_cache.PairCandleCache Python class in Trading Strategy framework.
- class PairCandleCache[source]#
Bases:
objectContext manager for pair candle cache operations.
Handles loading, updating, and saving of cached candle data and metadata. Designed to be used as a context manager to ensure proper file locking.
- Example usage:
- with PairCandleCache(cache_path) as cache:
partition = cache.metadata.partition_for_fetch(pair_ids, start_time, end_time) # … perform fetches … cache.update([df1, df2]) # Update cache with new data return cache.data[] # filter as needed
- __init__(base_path)[source]#
Initialize cache with base file path.
- Parameters:
base_path (str) – Absolute path without extension (e.g., “/path/to/candles-1h”). Extensions .parquet, .json, .lock will be appended as needed.
Methods
__init__(base_path)Initialize cache with base file path.
update(new_dataframes, pair_ids, start_time, ...)Update cache with new candle data.
Attributes
- __init__(base_path)[source]#
Initialize cache with base file path.
- Parameters:
base_path (str) – Absolute path without extension (e.g., “/path/to/candles-1h”). Extensions .parquet, .json, .lock will be appended as needed.
- property data: DataFrame#
Access to the cached candle DataFrame.
- property metadata: PairCandleMetadata#
Access to the cache metadata.
- update(new_dataframes, pair_ids, start_time, end_time)[source]#
Update cache with new candle data.
Concatenates new data with existing, removes duplicates, sorts, and saves both the parquet file and metadata.
- Parameters:
new_dataframes (list[pandas.core.frame.DataFrame]) – List of DataFrames containing new candle data to add to cache.
pair_ids (Collection[int]) – Trading pairs that were included in the fetch operation.
start_time (datetime) – Start time used for the fetch operation.
end_time (datetime) – End time used for the fetch operation.
- Return type:
None