From 365491c1fcf523994035e4bd28d8b5872dd6ec98 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期四, 31 七月 2025 14:47:48 +0800 Subject: [PATCH] 除权采用掘金更新K线 --- utils/tool.py | 35 ++++++++++++++++++++++++++++++++--- 1 files changed, 32 insertions(+), 3 deletions(-) diff --git a/utils/tool.py b/utils/tool.py index 63bcb43..e191df7 100644 --- a/utils/tool.py +++ b/utils/tool.py @@ -21,6 +21,22 @@ return wrapper +def singleton(cls): + """ + 鍗曚緥瑁呴グ鍣� + @param cls: + @return: + """ + instances = {} + + def get_instance(*args, **kwargs): + if cls not in instances: + instances[cls] = cls(*args, **kwargs) + return instances[cls] + + return get_instance + + def get_expire(): now = int(t.time()) end = int(t.time()) + 60 * 60 * 24 @@ -28,7 +44,7 @@ end = int(t.mktime(t.strptime(local_time, "%Y-%m-%d"))) expire = end - now # 鍔犻殢鏈烘暟锛岄槻姝竴璧烽攢姣佹暟鎹� - expire += random.randint(0, 60 * 60) + expire += random.randint(0, 60 * 30) return expire @@ -52,6 +68,11 @@ def get_now_time_str(): time_str = datetime.datetime.now().strftime("%H:%M:%S") return time_str + + +def get_now_time_as_int(): + time_str = datetime.datetime.now().strftime("%H:%M:%S") + return int(time_str.replace(":", "")) def get_now_time_with_ms_str(): @@ -303,7 +324,11 @@ # if price - 0.1 < fprice: # fprice = price - 0.1 # return round(fprice, 2) - return round(get_buy_min_price(price) - 0.03, 2) + if price < 20: + return round(get_buy_min_price(price) - 0.03, 2) + else: + # 澶ц偂浠风洿鎺ュ悜涓嬪彇2% + return round(price * (1 - 0.02), 2) if __name__ == "__main__": @@ -377,7 +402,11 @@ def get_buy_volume(limit_up_price): - count = (constant.BUY_MONEY_PER_CODE // int(round(float(limit_up_price) * 100))) * 100 + return get_buy_volume_by_money(limit_up_price, constant.BUY_MONEY_PER_CODE) + + +def get_buy_volume_by_money(limit_up_price, money): + count = (money // int(round(float(limit_up_price) * 100))) * 100 if count < 100: count = 100 return count -- Gitblit v1.8.0