Files
big-qmt/py-client/libs/calc.py

38 lines
1.0 KiB
Python
Raw Normal View History

2026-08-28 18:52:27 +08:00
from datetime import datetime, time
from math import floor
2026-09-07 21:22:51 +08:00
_MORNING_START, _MORNING_END = time(9, 30), time(11, 30)
_AFTERNOON_START, _AFTERNOON_END = time(13), time(15)
2026-08-28 18:52:27 +08:00
def trading_time(now: datetime) -> bool:
if now.weekday() >= 5: return False
2026-09-07 21:22:51 +08:00
clock = now.time()
return _MORNING_START <= clock <= _MORNING_END or _AFTERNOON_START <= clock <= _AFTERNOON_END
2026-08-28 18:52:27 +08:00
def calc_buy_volume(price: float, buy_value: float) -> int:
if price <= 0 or buy_value <= 0: return 0
return max(1, floor(buy_value / (price * 100))) * 100
def calculate_min_profit_rate(price: float, profit_mult: int) -> float:
"""
根据价格返回最小利润率
Args:
price: 股票价格
profit_mult: 利润倍数配置
Returns:
float: 最小利润率百分比
"""
if price >= 300:
return 3 * profit_mult # 3%
if price >= 200:
return 5 * profit_mult # 5%
elif price >= 100:
return 7 * profit_mult # 7%
else:
2026-09-07 21:22:51 +08:00
return 9 * profit_mult # 9%