From 6e71fbcb119e7068ba35380edaa5cc66e7c71f1b Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 27 十月 2022 16:21:05 +0800
Subject: [PATCH] 交易体系完善

---
 tool.py |   45 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/tool.py b/tool.py
index bf5971e..da2d8db 100644
--- a/tool.py
+++ b/tool.py
@@ -6,8 +6,16 @@
 import time
 import time as t
 import datetime
+from threading import Thread
 
-import global_util
+import constant
+
+
+def async_call(fn):
+    def wrapper(*args, **kwargs):
+        Thread(target=fn, args=args, kwargs=kwargs).start()
+
+    return wrapper
 
 
 def get_expire():
@@ -34,7 +42,7 @@
 # 鏄惁涓轰氦鏄撴椂闂�
 def is_trade_time():
     # 娴嬭瘯
-    if global_util.TEST:
+    if constant.TEST:
         return True
 
     relative_timestamp = t.time() % (24 * 60 * 60) + 8 * 60 * 60
@@ -61,8 +69,33 @@
     return decorator
 
 
+def get_time_as_second(time_str):
+    ts = time_str.split(":")
+    return int(ts[0]) * 3600 + int(ts[1]) * 60 + int(ts[2])
+
+
+# 灏嗙鏁版牸寮忓寲涓烘椂闂�
+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)
+
+
+# 浜ゆ槗鏅傞枔鐨勫樊鍊�
+# 濡�11:29:59 涓� 13:00:00鍙浉宸�1s
+def trade_time_sub(time_str_1, time_str_2):
+    split_time = get_time_as_second("11:30:00")
+    time_1 = get_time_as_second(time_str_1)
+    time_2 = get_time_as_second(time_str_2)
+    if time_1 < split_time < time_2:
+        time_2 = time_2 - 90 * 60
+
+    return time_1 - time_2
+
+
 if __name__ == "__main__":
-    d1 = decimal.Decimal("0.12")
-    d2 = decimal.Decimal("0.12")
-    if d1 == d2:
-        print("123")
+    print(trade_time_sub("11:29:59", "13:00:00"))
+    print(trade_time_sub("11:29:59", "14:00:00"))
+    print(trade_time_sub("10:29:59", "11:29:59"))
+    print(trade_time_sub("13:29:59", "14:29:59"))

--
Gitblit v1.8.0