Skip to main content

Crate brk_fetcher

Crate brk_fetcher 

Source
Expand description

§brk_fetcher

Bitcoin price data fetcher with multi-source fallback.

§What It Enables

Fetch OHLC (Open/High/Low/Close) price data from Binance, Kraken, or the public Bitview API. Automatically falls back between sources on failure, with up to 12 hours of retries when every source is unavailable.

§Key Features

  • Multi-source fallback: Binance → Kraken → Bitview API
  • Health tracking: Temporarily disables failing sources
  • Two resolution modes: Per-date (daily) or per-block (OHLC aggregated from 1-minute candles)
  • HAR file support: Import Binance 1mn data from browser network captures for historical fills
  • Permanent block detection: Stops retrying on DNS/TLS failures

§Core API

let mut fetcher = Fetcher::import(Some(&hars_path))?;

// Daily price
let ohlc = fetcher.get_date(Date::new(2024, 4, 20))?;

// Block-level price (uses 1mn data when available)
let ohlc = fetcher.get_height(height, block_timestamp, prev_timestamp)?;

§Sources

SourceResolutionLookbackNotes
Binance1mn~16 hoursBest for recent blocks
Kraken1mn~10 hoursFallback for recent
Bitview APIPer-height and dailyFull historyFallback for older data

§HAR Import

For historical 1-minute data beyond API limits, export network requests from Binance’s web interface and place the HAR file in the imports directory.

§Built On

  • brk_error for error handling
  • brk_logger for retry logging
  • brk_types for Date, Height, Timestamp, OHLCCents

Structs§

BRK
Binance
Fetcher
Kraken
TrackedSource
Wraps a price source with health tracking. Automatically skips blocked/unreachable sources and rechecks after cooldown.

Traits§

PriceSource
A price data source that can fetch OHLC data by date or timestamp.

Functions§

checked_get
Perform a GET request and check the response status.
compute_ohlc_from_range
Compute OHLC for a block from a time series of minute data. Aggregates all candles between previous_timestamp and timestamp.
new_agent
Create a shared HTTP agent with connection pooling and default timeout. Status codes are not treated as errors — callers use checked_get for status handling.