移除行情区 3m/10m/20m/6h/8h 周期

保留 30m、2h、12h;12h 仍支持从 1h 聚合

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-02 15:33:33 +08:00
parent eebc50cffa
commit fdca82ea26
4 changed files with 16 additions and 59 deletions
+13 -14
View File
@@ -132,25 +132,24 @@ class TestHubOhlcvLib(unittest.TestCase):
self.assertGreaterEqual(len(ex.calls), 3)
self.assertAlmostEqual(out["bars"][-1]["close"], 3.05)
def test_aggregate_6h_from_1h_when_exchange_lacks_native(self):
"""Gate 等无 6h 时应从 1h 聚合。"""
def test_aggregate_12h_from_1h_when_exchange_lacks_native(self):
"""无原生 12h 时应从 1h 聚合。"""
from hub_ohlcv_lib import TIMEFRAME_MS
h1 = TIMEFRAME_MS["1h"]
h6 = TIMEFRAME_MS["6h"]
base = 1_700_000_000_000
base = (base // h6) * h6
h12 = TIMEFRAME_MS["12h"]
base = (1_700_000_000_000 // h12) * h12
one_h = [
[base + i * h1, 100.0 + i, 101.0 + i, 99.0 + i, 100.5 + i, 10.0]
for i in range(24)
for i in range(48)
]
ex = _FakeExchange(
[one_h],
timeframes={"1h": "1h", "4h": "4h", "8h": "8h"},
timeframes={"1h": "1h", "4h": "4h"},
)
out = fetch_ohlcv_for_hub(
symbol="BTC/USDT",
timeframe="6h",
timeframe="12h",
since_ms=base,
limit=4,
normalize_symbol_input=lambda s: str(s).strip().upper(),
@@ -161,15 +160,15 @@ class TestHubOhlcvLib(unittest.TestCase):
self.assertTrue(out.get("ok"))
bars = out.get("bars") or []
self.assertEqual(len(bars), 4)
self.assertTrue(bars_spacing_matches_timeframe(bars, "6h"))
self.assertTrue(bars_spacing_matches_timeframe(bars, "12h"))
self.assertEqual(ex.calls[0]["timeframe"], "1h")
def test_aggregate_ohlcv_bars_buckets(self):
from hub_ohlcv_lib import TIMEFRAME_MS
h1 = TIMEFRAME_MS["1h"]
h6 = TIMEFRAME_MS["6h"]
base = (1_700_000_000_000 // h6) * h6
h12 = TIMEFRAME_MS["12h"]
base = (1_700_000_000_000 // h12) * h12
src = [
{
"open_time_ms": base + i * h1,
@@ -179,11 +178,11 @@ class TestHubOhlcvLib(unittest.TestCase):
"close": 1.5,
"volume": 1.0,
}
for i in range(6)
for i in range(12)
]
out = aggregate_ohlcv_bars(src, "6h")
out = aggregate_ohlcv_bars(src, "12h")
self.assertEqual(len(out), 1)
self.assertEqual(out[0]["volume"], 6.0)
self.assertEqual(out[0]["volume"], 12.0)
self.assertEqual(out[0]["high"], 2.0)
self.assertEqual(out[0]["low"], 0.5)