from datetime import datetime, time from math import floor _MORNING_START, _MORNING_END = time(9, 30), time(11, 30) _AFTERNOON_START, _AFTERNOON_END = time(13), time(15) def trading_time(now: datetime) -> bool: if now.weekday() >= 5: return False clock = now.time() return _MORNING_START <= clock <= _MORNING_END or _AFTERNOON_START <= clock <= _AFTERNOON_END 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: return 9 * profit_mult # 9%