| | |
| | | |
| | | |
| | | # 获取量比(今日量/max(60天最大量,昨日量)) |
| | | def get_volume_rate(code, with_info=False): |
| | | # 将总卖量计算在内 |
| | | def get_volume_rate(code, total_sell_volume=0, with_info=False): |
| | | today = get_today_volumn(code) |
| | | max60, yesterday = get_histry_volumn(code) |
| | | if today is None or max60 is None or yesterday is None: |
| | | raise Exception("获取量失败") |
| | | rate = round(int(today) / max(int(max60[0]), int(yesterday)), 2) |
| | | rate = round((int(today) + total_sell_volume) / max(int(max60[0]), int(yesterday)), 2) |
| | | if not with_info: |
| | | return rate |
| | | return rate, (today, max(int(max60[0]), int(yesterday))) |
| | |
| | | prices.append( |
| | | {"code": code, "time": limit_up_time, "rate": rate, |
| | | "limit_up": is_limit_up}) |
| | | if code in new_add_codes: |
| | | if is_limit_up: |
| | | place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count( |
| | | code) |
| | | if place_order_count == 0: |
| | | trade_data_manager.PlaceOrderCountManager().place_order(code) |
| | | |
| | | gpcode_first_screen_manager.process_ticks(prices) |
| | | logger_l2_codes_subscript.info(f"({request_id})l2代码相关数据加载完成") |
| | |
| | | from trade import l2_trade_util, trade_manager |
| | | from l2.cancel_buy_strategy import L2LimitUpSellStatisticUtil, LCancelBigNumComputer, DCancelBigNumComputer |
| | | from log_module.log import logger_juejin_tick, logger_system |
| | | from trade.trade_data_manager import CodeActualPriceProcessor |
| | | from trade.trade_data_manager import CodeActualPriceProcessor, PlaceOrderCountManager |
| | | from trade.trade_queue_manager import JueJinBuy1VolumnManager |
| | | |
| | | redisManager = redis_manager.RedisManager(0) |
| | |
| | | HighIncreaseCodeManager().clear() |
| | | # 股性清除 |
| | | CodeNatureRecordManager().clear() |
| | | # 下单次数清除 |
| | | PlaceOrderCountManager().clear() |
| | | |
| | | |
| | | # 每日初始化 |
| | |
| | | |
| | | |
| | | def convert_time(time_str, with_ms=False): |
| | | time_str = str(time_str) |
| | | if time_str.startswith("9"): |
| | | time_str = f"0{time_str}" |
| | | ms = "{:0<3}".format(time_str[6:]) |
| | |
| | | import l2.l2_data_util |
| | | from log_module.log import logger_l2_trade_buy, logger_l2_process, logger_l2_error, logger_debug |
| | | |
| | | from trade.trade_data_manager import CodeActualPriceProcessor |
| | | from trade.trade_data_manager import CodeActualPriceProcessor, PlaceOrderCountManager |
| | | |
| | | from trade.trade_manager import TradeTargetCodeModeManager, AccountAvailableMoneyManager |
| | | |
| | |
| | | __LatestCancelIndexManager = LatestCancelIndexManager() |
| | | __L2MarketSellManager = L2MarketSellManager() |
| | | __L2LimitUpSellManager = L2LimitUpSellManager() |
| | | __PlaceOrderCountManager = PlaceOrderCountManager() |
| | | |
| | | # 获取代码评分 |
| | | @classmethod |
| | |
| | | # 是否为首板代码 |
| | | is_first_code = True # gpcode_manager.FirstCodeManager().is_in_first_record(code) |
| | | # 计算量 |
| | | volume_rate = code_volumn_manager.get_volume_rate(code) |
| | | current_sell = cls.__L2MarketSellManager.get_current_total_sell_data(code) |
| | | total_sell_volume = 0 |
| | | if current_sell and len(current_sell) > 2: |
| | | total_sell_volume = current_sell[2] |
| | | volume_rate = code_volumn_manager.get_volume_rate(code, total_sell_volume=total_sell_volume) |
| | | volume_rate_index = code_volumn_manager.get_volume_rate_index(volume_rate) |
| | | # 计算分值 |
| | | limit_up_time = cls.__LimitUpTimeManager.get_limit_up_time_cache(code) |
| | |
| | | HighIncreaseCodeManager().add_code(code) |
| | | return False, True, f"股价大于{constant.MAX_CODE_PRICE}块" |
| | | |
| | | place_order_count = cls.__PlaceOrderCountManager.get_place_order_count(code) |
| | | if place_order_count and place_order_count >= 10: |
| | | l2_trade_util.forbidden_trade(code, msg="当日下单次数已达10次") |
| | | return False, True, f"当日下单次数已达10次" |
| | | |
| | | # -------量的约束-------- |
| | | if cls.volume_rate_info[code][0] < 0.2: |
| | | return False, True, f"当日量比({cls.volume_rate_info[code][0]})小于0.2" |
| | | k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code) |
| | | if k_format and (k_format[1][0] or k_format[3][0]): |
| | | # 股价创新高或者逼近前高 |
| | | if cls.volume_rate_info[code][0] < 0.3: |
| | | return False, True, f"股价创新高或者逼近前高,当日量比({cls.volume_rate_info[code][0]})小于0.3" |
| | | if code_nature_analyse.LatestMaxVolumeManager().is_latest_max_volume(code): |
| | | # 最近几天有最大量,判断量比是否大于60% |
| | | if cls.volume_rate_info[code][0] < 0.6: |
| | | HighIncreaseCodeManager().add_code(code) |
| | | return False, True, f"近日出现最大量,当日量比({cls.volume_rate_info[code][0]})小于0.6" |
| | | |
| | | # ------自由流通市值约束------ |
| | | zyltgb = global_util.zyltgb_map.get(code) |
| | | if zyltgb: |
| | | if zyltgb < 10 * 100000000: |
| | | return False, True, f"自由流通小于10亿({zyltgb})" |
| | | |
| | | total_data = local_today_datas.get(code) |
| | | if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_HUAXIN: |
| | | total_data = local_today_datas.get(code) |
| | | trade_price = current_price_process_manager.get_trade_price(code) |
| | | if trade_price is None: |
| | | return False, True, f"尚未获取到当前成交价" |
| | |
| | | return False, True, f"炸板后最低价跌至5%以下" |
| | | |
| | | # 回封的票,下13:15买入需要判断板块是否为独苗 |
| | | if open_limit_up_lowest_price and int(tool.get_now_time_str().replace(":", "")) > 131500: |
| | | if open_limit_up_lowest_price and int(total_data[-1]["val"]["time"].replace(":", "")) > 131500: |
| | | # 获取当前票的涨停原因 |
| | | if code in LimitUpCodesPlateKeyManager.today_total_limit_up_reason_dict: |
| | | limit_up_reason = kpl_data_manager.KPLLimitUpDataRecordManager.get_current_block(code) |
| | |
| | | RedisUtils.delete_async(self.__db, k) |
| | | |
| | | # 设置当前的总卖 |
| | | def set_current_total_sell_data(self, code, time_str, money): |
| | | def set_current_total_sell_data(self, code, time_str, money, volume): |
| | | # 记录日志 |
| | | async_log_util.info(logger_l2_market_sell, f"{code}: {time_str}-{money}") |
| | | if code in self.__current_total_sell_data_cache: |
| | | self.__last_total_sell_data_cache[code] = self.__current_total_sell_data_cache.get(code) |
| | | self.__current_total_sell_data_cache[code] = (time_str, round(money)) |
| | | self.__current_total_sell_data_cache[code] = (time_str, round(money), volume) |
| | | |
| | | def get_current_total_sell_data(self, code): |
| | | return self.__current_total_sell_data_cache.get(code) |
| | |
| | | def test_trade(self): |
| | | trade_manager.TradeStateManager().open_buy() |
| | | threading.Thread(target=async_log_util.run_sync, daemon=True).start() |
| | | code = "002528" |
| | | code = "002848" |
| | | clear_trade_data(code) |
| | | l2.l2_data_util.load_l2_data(code) |
| | | total_datas = deepcopy(l2.l2_data_util.local_today_datas[code]) |
| | |
| | | time_str = time_str[:6] |
| | | time_str = f"{time_str[0:2]}:{time_str[2:4]}:{time_str[4:6]}" |
| | | L2MarketSellManager().set_current_total_sell_data(code, time_str, |
| | | l2_m["totalAskVolume"] * l2_m["avgAskPrice"]) |
| | | l2_m["totalAskVolume"] * l2_m["avgAskPrice"], l2_m["totalAskVolume"]) |
| | | break |
| | | |
| | | for tp in trade_progress_list: |
| | |
| | | yesterday_codes, |
| | | block_info.get_before_blocks_dict()) |
| | | |
| | | @unittest.skip("跳过此单元测试") |
| | | def test_transaction(self): |
| | | threading.Thread(target=async_log_util.run_sync, daemon=True).start() |
| | | code = "003019" |
| | |
| | | (k, len(limit_up_reason_dict[k]), limit_up_reason_want_count_dict.get(k), limit_up_reason_dict[k][0][5]) for |
| | | k in |
| | | limit_up_reason_dict] |
| | | limit_up_reason_statistic_info.sort(key=lambda x: int(x[3])) |
| | | limit_up_reason_statistic_info.sort(key=lambda x: int(x[1])) |
| | | limit_up_reason_statistic_info.reverse() |
| | | |
| | | codes_set = set([d[3] for d in total_datas]) |
| | | # 判断是龙几,判断是否涨停,判断是否炸板,加载分数 |
| | |
| | | |
| | | async_log_util.info(hx_logger_l2_market_data, f"{code}#{data}") |
| | | L2MarketSellManager().set_current_total_sell_data(code, time_str, |
| | | data["totalAskVolume"] * data["avgAskPrice"]) |
| | | data["totalAskVolume"] * data["avgAskPrice"], data["totalAskVolume"]) |
| | | |
| | | @classmethod |
| | | def trading_order_canceled(cls, code, order_no): |
| | |
| | | return cls.__instance |
| | | |
| | | def __load_datas(self): |
| | | rules = self.__list_rules() |
| | | rules = self.list_rules() |
| | | self.__sell_rules_dict_cache.clear() |
| | | for rule in rules: |
| | | self.__sell_rules_dict_cache[rule.id_] = rule |
| | |
| | | key = "place_order_count-{}".format(code) |
| | | RedisUtils.delete_async(self.__db, key) |
| | | |
| | | def clear(self): |
| | | self.__place_order_count_cache.clear() |
| | | keys = RedisUtils.keys(self.__get_redis(), "place_order_count-*") |
| | | for k in keys: |
| | | RedisUtils.delete(self.__get_redis(), k) |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | processor = CodeActualPriceProcessor() |
| | |
| | | from l2.l2_data_util import local_today_datas, local_today_num_operate_map |
| | | from l2.l2_sell_manager import L2MarketSellManager |
| | | from log_module.log import logger_l2_error |
| | | from trade.trade_data_manager import PlaceOrderCountManager |
| | | from trade.trade_queue_manager import THSBuy1VolumnManager |
| | | |
| | | __thsBuy1VolumnManager = THSBuy1VolumnManager() |
| | |
| | | # 记录卖盘统计时间被用 |
| | | L2MarketSellManager().set_sell_time_used(code, order_begin_pos.sell_info[0]) |
| | | FastCancelBigNumComputer().set_trade_progress(code, order_begin_pos.buy_exec_index) |
| | | # 下单成功 |
| | | PlaceOrderCountManager().place_order(code) |
| | | |
| | | |
| | | # 真实撤成功 |
| | |
| | | process_indexs = log_export.get_l2_process_position(code, date) |
| | | trade_indexs = log_export.get_l2_trade_position(code, date) |
| | | real_position_indexes = log_export.get_real_place_order_positions(code, date) |
| | | fdatas = export_l2_data(code, datas, process_indexs, trade_indexs, real_position_indexes) |
| | | deal_list = log_export.load_huaxin_deal_record(code) |
| | | deal_list_dict = {} |
| | | for d in deal_list: |
| | | deal_list_dict[d[0]] = d |
| | | fdatas = export_l2_data(code, datas, process_indexs, trade_indexs, real_position_indexes, deal_list_dict) |
| | | __save_l2_datas(code, fdatas) |
| | | |
| | | |
| | |
| | | # 买 |
| | | if cancel_data: |
| | | try: |
| | | cancel_info = "{}-{}".format(cancel_data["index"], f"{cancel_data['val']['time']}.{cancel_data['val']['tms']}") |
| | | cancel_info = "{}-{}".format(cancel_data["index"],f"{cancel_data['val']['time']}") + (f".{cancel_data['val']['tms']}" if "tms" in cancel_data["val"] else '') |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | else: |
| | | if int(data["val"].get("orderNo")) in deal_list_dict: |
| | | cancel_info = l2_huaxin_util.convert_time(deal_list_dict[int(data["val"].get("orderNo"))][3]) |
| | | cancel_info = l2_huaxin_util.convert_time(deal_list_dict[int(data["val"].get("orderNo"))][3], |
| | | with_ms=True) |
| | | format_data.append(cancel_info) |
| | | cancel_order_info = None |
| | | if trade_info: |
| | |
| | | |
| | | if __name__ == "__main__": |
| | | try: |
| | | export_l2_excel("605218") |
| | | export_l2_excel("000536") |
| | | except Exception as e: |
| | | logging.exception(e) |