| | |
| | | MAX_SUBSCRIPT_CODE_PRICE = 100 |
| | | |
| | | # 扫入价格区间 |
| | | MAX_CODE_RADICAL_BUY_PRICE = 40 |
| | | MAX_CODE_RADICAL_BUY_PRICE = 50 |
| | | MIN_CODE_RADICAL_BUY_PRICE = 2 |
| | | |
| | | # 扫入的自由流通市值区间:[[(自由流通最小值,自由流通最大值),(股价最小值,股价最大值)]] |
| | | RADICAL_BUY_ZYLTGB_AS_YI_RANGES = [[(5, 1000), (3, 40)], [(50, 1000), (2, 3)]] |
| | | RADICAL_BUY_ZYLTGB_AS_YI_RANGES = [[(5, 1000), (3, 50)], [(50, 1000), (2, 3)]] |
| | | |
| | | # L2数据是否载入完成 |
| | | L2_DATA_IS_LOADED = False |
| | |
| | | from l2 import l2_data_util, l2_data_source_util |
| | | from l2.huaxin import l2_huaxin_util |
| | | from l2.l2_data_util import L2DataUtil |
| | | from l2.transaction_progress import TradeBuyQueue |
| | | from log_module import async_log_util |
| | | from log_module.log import hx_logger_trade_debug, logger_real_place_order_position, logger_debug |
| | | from trade.huaxin import huaxin_trade_record_manager |
| | |
| | | if set(target_volumes) != set(volumes_list[i:i + len(target_volumes)]): |
| | | continue |
| | | # 委托间隔时间不能相差100ms以上 |
| | | # volumes_info_list:目标量列表 |
| | | temp_volumes_info_list = volumes_info_list[i:i + len(target_volumes)] |
| | | sub_time_list = [] |
| | | sub_index_list = [] |
| | | for j in range(0, len(temp_volumes_info_list) - 1): |
| | | sub_ms = tool.trade_time_sub_with_ms( |
| | | L2DataUtil.get_time_with_ms(temp_volumes_info_list[j + 1][2]["val"]), |
| | | L2DataUtil.get_time_with_ms(temp_volumes_info_list[j][2]["val"])) |
| | | sub_index = temp_volumes_info_list[j + 1][2]["index"] - temp_volumes_info_list[j][2]["index"] |
| | | sub_time_list.append(abs(sub_ms)) |
| | | sub_index_list.append(sub_index) |
| | | max_sub_time = max(sub_time_list) |
| | | max_sub_index = max(sub_index_list) |
| | | if max_sub_time > THRESHOLD_MS: |
| | | continue |
| | | # 最大的时间差 |
| | | match_list.append((max_sub_time, temp_volumes_info_list[0][2])) |
| | | # 最大的时间差,最大的索引差, 数据 |
| | | match_list.append((max_sub_time, max_sub_index, temp_volumes_info_list[0][2])) |
| | | if not match_list: |
| | | # 没有找到真实下单位 |
| | | return None |
| | | # 最合适的是时间相差为0,索引相差为1 |
| | | for m in match_list: |
| | | if m[0] == 0 and m[1] == 1: |
| | | return m[2] |
| | | |
| | | # 获取时间差最小的数据 |
| | | real_place_order_info = match_list[0] |
| | | for x in match_list: |
| | | if x[0] < real_place_order_info[0]: |
| | | real_place_order_info = x |
| | | return real_place_order_info[1] |
| | | return real_place_order_info[2] |
| | | |
| | | @classmethod |
| | | def compute_l2_place_order_position(cls, code, add_datas): |
| | |
| | | return None, order_info, None |
| | | |
| | | @classmethod |
| | | def recompute_for_slow_time(cls, code, order_info, real_place_index, compute_type): |
| | | def recompute_l2_place_order_position(cls, code, order_info, real_place_index, compute_type): |
| | | """ |
| | | 因为L2数据延迟问题而重新计算真实下单位 |
| | | 重新计算真实下单位 |
| | | @param code: |
| | | @param order_info: |
| | | @param real_place_index: |
| | | @param compute_type: |
| | | @return: |
| | | """ |
| | | # TODO 重新计算, 根据实际订单来计算 |
| | | pass |
| | | # 重新计算, 根据实际订单来计算 |
| | | # 如果真实下单位在实际成交位置之后就需要矫正 |
| | | trade_index, is_default = TradeBuyQueue().get_traded_index(code) |
| | | if is_default: |
| | | return None |
| | | # if real_place_index >= trade_index: |
| | | # return None |
| | | current_delegates = huaxin_trade_record_manager.DelegateRecordManager().list_current_delegates(code) |
| | | if not current_delegates: |
| | | return None |
| | | accept_time = current_delegates[0]["acceptTime"] |
| | | accept_time = int(accept_time.replace(":", "")) |
| | | # 从真实下单位置开始,到委托时间截止 |
| | | total_datas = l2_data_util.local_today_datas.get(code) |
| | | end_index = None |
| | | for i in range(trade_index + 1, total_datas[-1]["index"]): |
| | | data = total_datas[i] |
| | | val = data["val"] |
| | | if int(val["time"].replace(":", "")) > accept_time: |
| | | end_index = data["index"] |
| | | break |
| | | if end_index is None: |
| | | return None |
| | | |
| | | order_info_list = order_info[0] # [(量,价格, order_ref)] |
| | | exec_data = order_info[1] |
| | | place_order_data = cls.__compute_real_place_order_position(code, exec_data, order_info_list, |
| | | total_datas[trade_index + 1:end_index]) |
| | | if not place_order_data: |
| | | return None |
| | | real_place_index_info = place_order_data["index"], RELIABILITY_TYPE_REAL |
| | | return real_place_index_info[0] |
| | | |
| | | @classmethod |
| | | def get_place_order_position(cls, code): |
| | |
| | | import copy |
| | | import logging |
| | | import threading |
| | | import time |
| | | import time as t |
| | | |
| | | from cancel_strategy.s_l_h_cancel_strategy import HourCancelBigNumComputer, LCancelRateManager |
| | |
| | | |
| | | @classmethod |
| | | def __recompute_real_order_index(cls, code, pre_real_order_index, order_info, compute_type): |
| | | # 因为数据慢的问题重新计算 |
| | | real_order_index = huaxin_delegate_postion_manager.recompute_for_slow_time(code, order_info, |
| | | pre_real_order_index, compute_type) |
| | | if real_order_index: |
| | | # 1s之后重新计算 |
| | | time.sleep(1) |
| | | real_order_index = huaxin_delegate_postion_manager.RealDelegateOrderPositionManager().recompute_l2_place_order_position(code, order_info, pre_real_order_index, compute_type) |
| | | if real_order_index and pre_real_order_index!=real_order_index: |
| | | try: |
| | | exec_index = order_info[6] |
| | | order_begin_pos = cls.__get_order_begin_pos( |
| | |
| | | return False, None, "距离上次统计大单时间过去60s", set() |
| | | |
| | | if lack_money == 0: |
| | | min_num = int(5000 / limit_up_price) |
| | | if not tool.is_sh_code(code): |
| | | # 非上证的票看50w |
| | | min_num = int(5000 / limit_up_price) |
| | | # 需要监听的大单 |
| | | watch_indexes = set() |
| | | # 总委托大单金额 |
| | |
| | | cls.__dealing_order_info_dict[code][4] = data[3] |
| | | cls.__dealing_order_info_dict[code][5] = data[1] |
| | | cls.__dealing_order_info_dict[code][6] = data[7] |
| | | cls.__dealing_order_info_dict[code][7] += money |
| | | if is_limit_up: |
| | | cls.__dealing_order_info_dict[code][7] += money |
| | | else: |
| | | # 保存上一条数据 |
| | | async_log_util.info(hx_logger_l2_transaction_desc, f"{code}#{cls.__dealing_order_info_dict[code]}") |
| | |
| | | code = ps_dict.get('code') |
| | | money_info = CodeInMoneyManager().get_money_info(code) |
| | | response_data = json.dumps({"code": 0, "data": money_info}) |
| | | |
| | | elif url.path == "/get_codes_money_info": |
| | | ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) |
| | | codes_str = ps_dict.get('codes') |
| | | codes = json.loads(codes_str) |
| | | fresults = {} |
| | | for code in codes: |
| | | money_info = CodeInMoneyManager().get_money_info(code) |
| | | fresults[code] = money_info |
| | | response_data = json.dumps({"code": 0, "data": fresults}) |
| | | self.send_response(200) |
| | | # 发给请求客户端的响应数据 |
| | | self.send_header('Content-type', 'application/json') |
| | |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | |
| | | |
| | | @classmethod |
| | | def get_gp_current_info(cls, codes): |
| | | return JueJinApi.get_gp_current_info(codes) |
| | |
| | | latest_trading_date = tool.get_now_date_str() |
| | | return latest_trading_date |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | print(HistoryKDatasUtils.get_previous_trading_date("2024-12-31")) |
| | | print(HistoryKDatasUtils.get_history_tick_n("000095", 10)) |
| | | |
| | | |
| | | # now_day = tool.get_now_date_str() |
| | | # results = JueJinApi.get_history_instruments(JueJinApi.get_juejin_code_list_with_prefix(["600265"]), |
| | |
| | | 获取板块有辨识度的代码 |
| | | @return: |
| | | """ |
| | | trading_dates = HistoryKDatasUtils.get_latest_trading_date(15) |
| | | trading_dates = HistoryKDatasUtils.get_latest_trading_date(8) |
| | | max_day = trading_dates[-1] |
| | | min_day = tool.date_sub(max_day, 365) |
| | | min_day = tool.date_sub(max_day, 180) |
| | | |
| | | block_map = self.__get_block_map() |
| | | # [(板块名称,代码, 在板块中的涨停次数)] |
| | |
| | | # 非正常票 |
| | | continue |
| | | |
| | | if juejin_result_dict[code][2] < 3 or juejin_result_dict[code][2] > 40: |
| | | # 小于3块/大于40块 |
| | | if juejin_result_dict[code][2] < 3 or juejin_result_dict[code][2] > 50: |
| | | # 小于3块/大于50块 |
| | | continue |
| | | |
| | | if int(float(limit_up_info_map[code][2])) < 50: |
| | | continue |
| | | |
| | | index += 1 |
| | | # [(板块, 代码名称, 代码, 涨停次数, 自由市值)] |
| | | fdatas.append( |
| | | (b, limit_up_info_map[code][1], code, code_block_dict[code][b], |
| | | int(float(limit_up_info_map[code][2])))) |
| | |
| | | |
| | | if __name__ == "__main__": |
| | | # print(datas) |
| | | print( BlockSpecialCodesManager().get_code_blocks("002582")) |
| | | print(BlockSpecialCodesManager().get_code_blocks("002582")) |
| | |
| | | import json |
| | | import logging |
| | | import time |
| | | import urllib |
| | | |
| | | import requests |
| | | |
| | |
| | | pre_limit_up_price_money_list = [] |
| | | deal_order_list = BigOrderDealManager().get_total_buy_data_list(code) |
| | | deal_order_ids = set() |
| | | for x in deal_order_list: |
| | | if opened_time and int(opened_time.replace(":", "")) > int( |
| | | l2_huaxin_util.convert_time(x[3]).replace(":", "")): |
| | | # 开板时间之前 |
| | | continue |
| | | deal_order_ids.add(x[0]) |
| | | if deal_order_list: |
| | | for x in deal_order_list: |
| | | if opened_time and int(opened_time.replace(":", "")) > int( |
| | | l2_huaxin_util.convert_time(x[3]).replace(":", "")): |
| | | # 开板时间之前 |
| | | continue |
| | | deal_order_ids.add(x[0]) |
| | | for info in buy_money_list: |
| | | if info[1] != limit_up_price: |
| | | continue |
| | |
| | | return False |
| | | return True |
| | | |
| | | def set_temp_deal_big_orders(self, code, money_list): |
| | | def set_temp_deal_big_orders(self, code, money_info_list): |
| | | """ |
| | | 设置临时大单 |
| | | @param code: |
| | | @param money_list: 成交的大买单 |
| | | @param money_info_list: 成交的大买单:[(订单号,总股数,成交金额,成交开始时间,成交结束时间, 最近的成交价格, 最近的卖单号, 涨停价成交金额)] |
| | | @return: |
| | | """ |
| | | if code in self.__temp_big_order_threshold: |
| | | return |
| | | if not money_list or len(money_list) < 2: |
| | | if not money_info_list or len(money_info_list) < 2: |
| | | return |
| | | fmoney_list = [] |
| | | min_money = l2_data_util.get_big_money_val(gpcode_manager.get_limit_up_price_as_num(code), tool.is_ge_code(code)) |
| | | for info in money_info_list: |
| | | if info[7] >= min_money: |
| | | # 涨停价成交部分是大单 |
| | | fmoney_list.append((info[7], info[0])) |
| | | if len(fmoney_list) < 2: |
| | | return |
| | | money_list = [x[0] for x in fmoney_list] |
| | | # 计算大单: 前2个大单的均值 |
| | | self.__temp_big_order_threshold[code] = int(sum(money_list[:2]) // 2) |
| | | async_log_util.info(logger_l2_radical_buy_data, |
| | | f"首次上板临时买大单:{code}-{self.__temp_big_order_threshold[code]}-{money_list[:2]}") |
| | | f"首次上板临时买大单:{code}-{self.__temp_big_order_threshold[code]}-{fmoney_list[:2]}") |
| | | |
| | | def get_temp_deal_big_order_threshold(self, code): |
| | | return self.__temp_big_order_threshold.get(code) |
| | |
| | | @param code: |
| | | @return: |
| | | """ |
| | | |
| | | if 1 > 0: |
| | | # 大单足够暂时不做处理 |
| | | return |
| | | # 如果加绿了就直接拉白 |
| | | if gpcode_manager.GreenListCodeManager().is_in_cache(code): |
| | | if gpcode_manager.WhiteListCodeManager().is_in_cache(code): |
| | |
| | | """ |
| | | # 原因下面的代码个数 |
| | | deal_reason_codes = {} |
| | | |
| | | # 加想不管板块是否成交 |
| | | if gpcode_manager.WantBuyCodesManager().is_in_cache(code): |
| | | return radical_buy_blocks |
| | | for dc in deal_codes: |
| | | # 获取涨停原因 |
| | | reasons = __get_deal_reasons(dc) |
| | |
| | | logger_debug.exception(e) |
| | | |
| | | |
| | | |
| | | def get_l2_big_order_deal_info(code_): |
| | | """ |
| | | 获取成交大单信息 |
| | |
| | | return None |
| | | |
| | | |
| | | def list_l2_big_order_deal_info(codes): |
| | | """ |
| | | 获取成交大单信息 |
| | | @param code_: |
| | | @return:(净流入金额, (大单买金额, 大单买数量), (大单卖金额, 大单卖数量)) |
| | | """ |
| | | response_data = requests.get( |
| | | "http://127.0.0.1:9005/get_codes_money_info?codes=" + urllib.parse.quote(json.dumps(list(codes)))) |
| | | r_str = response_data.text |
| | | response_data = json.loads(r_str) |
| | | if response_data["code"] == 0: |
| | | datas = response_data["data"] |
| | | return datas |
| | | return None |
| | | |
| | | def is_first_limit_up_buy(code): |
| | | """ |
| | | 是否是首封下单: (下单次数为0+没在涨停代码中) 或者 (处于下单状态 + 下单次数为1,且下单为首次下单) |
| | |
| | | # 初次上板需要计算临时大单 |
| | | if radical_buy_data_manager.is_first_limit_up_buy(code): |
| | | # 首封下单 |
| | | money_list = BigOrderDealManager().get_total_buy_money_list(code) |
| | | radical_buy_data_manager.BeforeSubDealBigOrderManager().set_temp_deal_big_orders(code, money_list) |
| | | |
| | | money_info_list = BigOrderDealManager().get_total_buy_data_list(code) |
| | | radical_buy_data_manager.BeforeSubDealBigOrderManager().set_temp_deal_big_orders(code, money_info_list) |
| | | |
| | | price = transaction_datas[-1][1] |
| | | huaxin_timestamp = transaction_datas[-1][3] |