From 8e8a2a2767e2784a6548cd07a2bf7dd6558e3f43 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期二, 19 三月 2024 18:50:14 +0800 Subject: [PATCH] S撤实现 --- utils/tool.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 44 insertions(+), 0 deletions(-) diff --git a/utils/tool.py b/utils/tool.py index c4d0bab..6aa8236 100644 --- a/utils/tool.py +++ b/utils/tool.py @@ -156,12 +156,27 @@ return int(ts[0]) * 3600 + int(ts[1]) * 60 + int(ts[2]) +def get_time_as_millionsecond(time_str): + s_str,ms_str = time_str.split(".") + ts = s_str.split(":") + return int(ts[0]) * 3600 + int(ts[1]) * 60 + int(ts[2])*1000 + int(ms_str) + + # 灏嗙鏁版牸寮忓寲涓烘椂闂� def time_seconds_format(seconds): h = seconds // 3600 m = seconds % 3600 // 60 s = seconds % 60 return "{0:0>2}:{1:0>2}:{2:0>2}".format(h, m, s) + + +def time_millionseconds_format(millionseconds): + ms = millionseconds % 1000 + seconds = millionseconds // 1000 + h = seconds // 3600 + m = seconds % 3600 // 60 + s = seconds % 60 + return "{0:0>2}:{1:0>2}:{2:0>2}.{3:0>3}".format(h, m, s, ms) # 浜ゆ槗鏅傞枔鐨勫樊鍊� @@ -174,6 +189,17 @@ time_2 = time_2 - 90 * 60 elif time_2 < split_time < time_1: time_2 = time_2 + 90 * 60 + + return time_1 - time_2 + +def trade_time_sub_with_ms(time_str_1, time_str_2): + split_time = get_time_as_second("11:30:00")*1000 + time_1 = get_time_as_millionsecond(time_str_1) + time_2 = get_time_as_millionsecond(time_str_2) + if time_1 < split_time < time_2: + time_2 = time_2 - 90 * 60*1000 + elif time_2 < split_time < time_1: + time_2 = time_2 + 90 * 60*1000 return time_1 - time_2 @@ -191,6 +217,19 @@ if s >= 11 * 3600 + 30 * 60 > s_: s += 90 * 60 return time_seconds_format(s) + + +def trade_time_add_millionsecond(time_str, millionsecond): + s_str, ms_str = time_str.split(".") + ts = s_str.split(":") + s_ = int(ts[0]) * 3600 + int(ts[1]) * 60 + int(ts[2]) + ms_ = s_ * 1000 + ms_ += int(ms_str) + ms = ms_ + millionsecond + # 鏄惁鍦�11:30:00 + if ms >= 11 * 3600 * 1000 + 30 * 60 * 1000 > ms_: + ms += 90 * 60 * 1000 + return time_millionseconds_format(ms) def compute_buy1_real_time(time_): @@ -282,3 +321,8 @@ if count < 100: count = 100 return count + + +if __name__ == "__main__": + print(trade_time_add_millionsecond("10:36:00.123", 1000)) + print(trade_time_add_millionsecond("11:29:59.123", 1888)) -- Gitblit v1.8.0