Add Kraken cache-rates backfill, with VWAP support#3
Merged
Conversation
Move cache_key, cache_path and load_disk_cache from KrakenProvider methods to free public functions. Add save_disk_cache as a standalone helper. Make CACHE_DIR and CACHE_FILE constants public. This prepares for reuse by the upcoming cache-rates command.
Factor out parse_kraken_ohlc_response from fetch_candle_for_timestamp so the HTTP-status and JSON-decoding logic can be shared. Add fetch_candles_since, which returns all candles from a given timestamp instead of searching for a single one.
The export command hard-coded a 1440-minute fallback and ignored the DEFAULT_CANDLE_MINUTES environment variable. Change candle_minutes to candle_override_minutes (Option) and resolve the effective interval through resolve_candle_minutes, which checks the override, then the env default, then falls back to 1440. Add unit tests for argument parsing and candle-minutes resolution.
Extract the OPBD (opening) balance amount, sign, and date from an existing CAMT.053 file during the append-mode parse. Add opening_balance_cents and opening_date fields to Camt053ParseResult and extend the round-trip test to cover them. This information is needed for the upcoming prepend mode, which must preserve the original opening balance when inserting entries before the existing statement.
When the output file already exists and --start-date is earlier than the file's opening balance date, switch to prepend mode: build entries only for the gap period, then splice them before the existing entries and recalculate statement totals. Reject attempts to move the start date forward past the existing opening date. When prepending, omit the wallet balance check (the known-good closing balance is in the existing file). Add ExistingExportPlan, ExistingMergeMode, merge_with_existing_statement, refresh_statement_totals and supporting helpers with unit tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add yearly Kraken backfill that fills recent candles from the API and older daily gaps from the OHLCVT archive, storing midpoint values when VWAP is unavailable.
Add a --vwap path that computes exact candle VWAP from Kraken trade archives (back to late 2013), supports candle overrides, reuses cached ZIP downloads, and falls back to larger trade candles when sparse intervals are missing (e.g. due to exchange outages).
Improve progress and summary logging, protect complete-archive refreshes from shrinking cached historical coverage, and add regression tests based on real Kraken CSV samples and overlap checks.