| | |
| | | from l2.l2_data_manager import L2DataException, TradePointManager |
| | | from l2.l2_data_util import local_today_datas, L2DataUtil, load_l2_data, local_today_num_operate_map, local_latest_datas |
| | | import l2.l2_data_util |
| | | from log import logger_l2_trade, logger_l2_trade_cancel, logger_l2_trade_buy, logger_l2_process, logger_l2_error,logger_buy_score |
| | | from log import logger_l2_trade, logger_l2_trade_cancel, logger_l2_trade_buy, logger_l2_process, logger_l2_error, \ |
| | | logger_buy_score |
| | | |
| | | # TODO l2数据管理 |
| | | from trade.trade_data_manager import CodeActualPriceProcessor |
| | |
| | | __thsBuy1VolumnManager = trade_queue_manager.THSBuy1VolumnManager() |
| | | __buyL2SafeCountManager = safe_count_manager.BuyL2SafeCountManager() |
| | | __l2PlaceOrderParamsManagerDict = {} |
| | | __last_buy_single_dict = {} |
| | | |
| | | @classmethod |
| | | # 数据处理入口 |
| | |
| | | limit_up_time = limit_up_time_manager.get_limit_up_time(code) |
| | | if limit_up_time is None: |
| | | limit_up_time = tool.get_now_time_str() |
| | | score = first_code_score_manager.get_score(code, volume_rate, limit_up_time,True) |
| | | score = first_code_score_manager.get_score(code, volume_rate, limit_up_time, True) |
| | | cls.__l2PlaceOrderParamsManagerDict[code] = l2_trade_factor.L2PlaceOrderParamsManager(code, is_first_code, |
| | | volume_rate, |
| | | volume_rate_index, |
| | |
| | | @classmethod |
| | | def __buy(cls, code, capture_timestamp, last_data, last_data_index, is_first_code): |
| | | __start_time = tool.get_now_timestamp() |
| | | can, need_clear_data, reason = False,False,"" |
| | | can, need_clear_data, reason = False, False, "" |
| | | if not is_first_code: |
| | | can, need_clear_data, reason = cls.__can_buy(code) |
| | | else: |
| | |
| | | @classmethod |
| | | def __can_buy(cls, code): |
| | | __start_time = t.time() |
| | | # 之前的代码 |
| | | # 首板代码且尚未涨停过的不能下单 |
| | | # is_limited_up = gpcode_manager.FirstCodeManager.is_limited_up(code) |
| | | # if not is_limited_up: |
| | | # gpcode_manager.FirstCodeManager.add_limited_up_record([code]) |
| | | # place_order_count = trade_data_manager.placeordercountmanager.get_place_order_count( |
| | | # code) |
| | | # if place_order_count == 0: |
| | | # trade_data_manager.placeordercountmanager.place_order(code) |
| | | # return False, True, "首板代码,且尚未涨停过" |
| | | if not trade_manager.TradeStateManager.is_can_buy(): |
| | | return False, True, f"今日已禁止交易" |
| | | # 之前的代码 |
| | | # 首板代码且尚未涨停过的不能下单 |
| | | # is_limited_up = gpcode_manager.FirstCodeManager.is_limited_up(code) |
| | | # if not is_limited_up: |
| | | # gpcode_manager.FirstCodeManager.add_limited_up_record([code]) |
| | | # place_order_count = trade_data_manager.placeordercountmanager.get_place_order_count( |
| | | # code) |
| | | # if place_order_count == 0: |
| | | # trade_data_manager.placeordercountmanager.place_order(code) |
| | | # return False, True, "首板代码,且尚未涨停过" |
| | | |
| | | try: |
| | | # 买1价格必须为涨停价才能买 |
| | |
| | | if volumn_rate >= 1.3: |
| | | return False, False, "最大量比超过1.3不能买" |
| | | |
| | | |
| | | limit_up_time = limit_up_time_manager.get_limit_up_time(code) |
| | | if limit_up_time is not None: |
| | | limit_up_time_seconds = l2.l2_data_util.L2DataUtil.get_time_as_second( |
| | | limit_up_time) |
| | | if limit_up_time_seconds >= l2.l2_data_util.L2DataUtil.get_time_as_second( |
| | | if limit_up_time_seconds >= l2.l2_data_util.L2DataUtil.get_time_as_second( |
| | | "13:00:00"): |
| | | return False, False, "二板下午涨停的不能买,涨停时间为{}".format(limit_up_time) |
| | | if limit_up_time_seconds >= l2.l2_data_util.L2DataUtil.get_time_as_second("14:55:00"): |
| | |
| | | |
| | | @classmethod |
| | | def __can_buy_first(cls, code): |
| | | if not trade_manager.TradeStateManager.is_can_buy(): |
| | | return False, True, f"今日已禁止交易" |
| | | |
| | | if not gpcode_manager.WantBuyCodesManager.is_in(code): |
| | | # 查看分数等级 |
| | |
| | | score = cls.__l2PlaceOrderParamsManagerDict[code].score |
| | | if score_index < 0: |
| | | return False, True, f"分值:{score}未达到需要买入的分数线" |
| | | # if -1 < score_index < 3: |
| | | # return True, False, f"分值:{score}达到主动买入的分数线,买入等级:f{score_index}" |
| | | # if -1 < score_index < 3 and (0.499 <= cls.volume_rate_info[code][0] <= 0.949): |
| | | # return True, False, f"分值:{score}达到主动买入的分数线且量足够,买入等级:f{score_index},量比:{cls.volume_rate_info[code][0]}" |
| | | is_limited_up = gpcode_manager.FirstCodeManager.is_limited_up(code) |
| | | gpcode_manager.FirstCodeManager.add_limited_up_record([code]) |
| | | if not code_price_manager.Buy1PriceManager.is_can_buy(code): |
| | |
| | | has_single, _index = cls.__compute_order_begin_pos(code, max( |
| | | (compute_start_index - continue_count - 1) if new_add else compute_start_index, 0), continue_count, |
| | | compute_end_index) |
| | | # 如果买入信号与上次的买入信号一样就不能算新的信号 |
| | | if cls.__last_buy_single_dict.get(code) == _index: |
| | | has_single = None |
| | | _index = None |
| | | |
| | | buy_single_index = _index |
| | | if has_single: |
| | | cls.__last_buy_single_dict[code] = buy_single_index |
| | | new_get_single = True |
| | | num = 0 |
| | | count = 0 |
| | |
| | | return |
| | | |
| | | if compute_index is not None: |
| | | l2_log.debug(code, "获取到买入执行位置:{} m值:{} 纯买手数:{} 纯买单数:{} 数据:{} ,量比:{} ", compute_index, threshold_money, buy_nums, |
| | | buy_count, total_datas[compute_index],cls.volume_rate_info[code][0]) |
| | | l2_log.debug(code, "获取到买入执行位置:{} m值:{} 纯买手数:{} 纯买单数:{} 数据:{} ,量比:{} ", compute_index, threshold_money, |
| | | buy_nums, |
| | | buy_count, total_datas[compute_index], cls.volume_rate_info[code][0]) |
| | | |
| | | f1 = dask.delayed(cls.__save_order_begin_data)(code, buy_single_index, compute_index, compute_index, |
| | | buy_nums, buy_count, max_num_set_new, |