diff --git a/src/easy_tdx/mac/commands/tick_charts.py b/src/easy_tdx/mac/commands/tick_charts.py index b3e4d04..c25dedd 100644 --- a/src/easy_tdx/mac/commands/tick_charts.py +++ b/src/easy_tdx/mac/commands/tick_charts.py @@ -12,6 +12,10 @@ from ...commands.base import BaseCommand from ..models import MacMultiTickChart, MacMultiTickDay, MacTick _MSG_ID = 0x123E +_TICK_OFFSET = 71 +_TICK_SIZE = struct.calcsize("= count * page_size: + tick_counts = [page_size] * count + else: + # start_date=None returns the latest partial trading day first, + # followed by complete historical days. + complete_days = min(count - 1, actual_total // page_size) + first_day_count = actual_total - complete_days * page_size + empty_days = count - complete_days - 1 + tick_counts = [first_day_count] + [page_size] * complete_days + [0] * empty_days + days: list[MacMultiTickDay] = [] - for d in range(count): + tick_index = 0 + for d, tick_count in enumerate(tick_counts): ticks: list[MacTick] = [] - for t in range(page_size): - index = d * page_size + t - offset = 71 + index * 14 + for t in range(tick_count): + offset = _TICK_OFFSET + tick_index * _TICK_SIZE (minutes, price, avg, vol, tick_reserved) = unpack_from( "