# Copyright (c) 2026 fxtradingguide.com
# SPDX-License-Identifier: MIT

"""Fixtures for the loader and the spread formula. Not a market test."""

from __future__ import annotations

import hashlib

from fxstudy.data import DATA_PATH, EXPECTED_SHA256, assert_sample, load_observations
from fxstudy.report import SPREAD_FRACTION, fill_price


def run() -> None:
    digest = hashlib.sha256(DATA_PATH.read_bytes()).hexdigest()
    if digest != EXPECTED_SHA256:
        raise SystemExit(f"ECB file hash is {digest}, expected {EXPECTED_SHA256}")
    observations = load_observations()
    assert_sample(observations)
    spread = SPREAD_FRACTION
    buy = fill_price(1.0, 1, spread)
    sell = fill_price(1.0, -1, spread)
    if buy != 1.0 * (1.0 + spread) or sell != 1.0 * (1.0 - spread):
        raise SystemExit("fill_price does not apply the spread fraction")
    if not (sell < 1.0 < buy):
        raise SystemExit("spread was not charged against the trader")
    print("fixture_status: ok")
    print(f"fixture_rows: {len(observations)}")


if __name__ == "__main__":
    run()
