import juejin_core
|
from utils import tool
|
|
|
class TickDataProcess:
|
# 最高价
|
__highest_price_infos = {}
|
|
@classmethod
|
def init_origin_price(cls, code, price, rate_percent):
|
cls.__highest_price_infos[code] = ("09:25:00", price, rate_percent)
|
|
# 价格信息(时间,现价,涨幅)
|
# return 是否减仓
|
@classmethod
|
def process_tick_data(cls, code, time_str, price, rate_percent, max_amplitude_rate_percent=1):
|
# 非交易时间
|
if tool.trade_time_sub(time_str, "09:30:00") < 0:
|
return False
|
now_price_info = (time_str, price, rate_percent)
|
# 如果比最高价高就取最高价
|
if code not in cls.__highest_price_infos:
|
cls.__highest_price_infos[code] = now_price_info
|
if cls.__highest_price_infos.get(code)[2] < now_price_info[2]:
|
cls.__highest_price_infos[code] = now_price_info
|
else:
|
# 低于最高点阈值
|
if cls.__highest_price_infos.get(code)[2] - now_price_info[2] > max_amplitude_rate_percent:
|
# 触发卖
|
cls.__highest_price_infos[code] = now_price_info
|
return True
|
return False
|
|
@classmethod
|
def clear(cls, code):
|
if code in cls.__highest_price_infos:
|
cls.__highest_price_infos.pop(code)
|
|
|
|
if __name__ == '__main__':
|
day = tool.get_now_date_str()
|
code = "603189"
|
time_range = ["09:25:00", "15:00:00"]
|
results = juejin_core.GPCodeManager().get_history_tick(code, day + " " + time_range[0],
|
day + " " + time_range[1])
|
pre_price = 14.74
|
TickDataProcess.init_origin_price(code, results[0]['price'],
|
round((results[0]['price'] - pre_price) * 100 / pre_price, 2))
|
for result in results:
|
rate = round((result['price'] - pre_price) * 100 / pre_price, 2)
|
r = TickDataProcess.process_tick_data(code, result['created_at'].strftime("%H:%M:%S"), result['price'],
|
rate, max_amplitude_rate_percent=0.6)
|
if r:
|
print("减仓", result['created_at'].strftime("%H:%M:%S"), rate, result['price'])
|