| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import importlib.util
- import json
- import sys
- from pathlib import Path
- from okx_codex_trader.models import Candle
- def load_export_module():
- path = Path(__file__).resolve().parents[1] / "scripts" / "export_freqtrade_data.py"
- spec = importlib.util.spec_from_file_location("export_freqtrade_data", path)
- assert spec is not None
- module = importlib.util.module_from_spec(spec)
- assert spec.loader is not None
- sys.modules[spec.name] = module
- spec.loader.exec_module(module)
- return module
- def test_export_ohlcv_json_writes_freqtrade_futures_filename(tmp_path):
- module = load_export_module()
- cache_dir = tmp_path / "cache"
- explore = __import__("scripts.explore_ultrashort", fromlist=["save_cached_candles"])
- explore.save_cached_candles(
- cache_dir,
- "BTC-USDT-SWAP",
- "15m",
- [
- Candle("BTC-USDT-SWAP", 1_700_000_000_000, 100.0, 101.0, 99.0, 100.5, 10.0),
- Candle("BTC-USDT-SWAP", 1_700_000_900_000, 100.5, 102.0, 100.0, 101.5, 11.0),
- ],
- history_exhausted=True,
- )
- output_file = module.export_ohlcv_json(
- symbol="BTC-USDT-SWAP",
- bar="15m",
- cache_dir=cache_dir,
- output_dir=tmp_path / "freqtrade",
- )
- assert output_file.name == "BTC_USDT_USDT-15m-futures.json"
- assert json.loads(output_file.read_text()) == [
- [1_700_000_000_000, 100.0, 101.0, 99.0, 100.5, 10.0],
- [1_700_000_900_000, 100.5, 102.0, 100.0, 101.5, 11.0],
- ]
|