feat
This commit is contained in:
32
py-client/libs/calc.py
Normal file
32
py-client/libs/calc.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from datetime import datetime, time
|
||||
from math import floor
|
||||
|
||||
|
||||
def trading_time(now: datetime) -> bool:
|
||||
if now.weekday() >= 5: return False
|
||||
return time(9, 30) <= now.time() <= time(11, 30) or time(13) <= now.time() <= time(15)
|
||||
|
||||
|
||||
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%
|
||||
Reference in New Issue
Block a user