| | |
| | | """ |
| | | import time |
| | | |
| | | from code_attribute import gpcode_manager |
| | | from code_attribute import gpcode_manager, code_volumn_manager |
| | | from l2 import l2_data_util, l2_data_source_util, transaction_progress |
| | | from l2.l2_data_util import L2DataUtil |
| | | from l2.l2_transaction_data_manager import HuaXinSellOrderStatisticManager |
| | | from log_module import async_log_util |
| | | from log_module.log import logger_l2_error |
| | | from settings.trade_setting import MarketSituationManager, TradeBlockBuyModeManager |
| | | from trade import trade_data_manager |
| | | from utils import tool, buy_condition_util, global_util |
| | |
| | | break |
| | | continue |
| | | # 与当前时间相差3s的结束 |
| | | if tool.trade_time_sub_with_ms(end_time_with_ms, l2_data_util.L2DataUtil.get_time_with_ms(val)) > 6000: |
| | | if tool.trade_time_sub_with_ms(end_time_with_ms, l2_data_util.L2DataUtil.get_time_with_ms(val)) > 10000: |
| | | break |
| | | |
| | | cancel_count += 1 |
| | |
| | | if buy_index and start_index <= buy_index: |
| | | cancel_count += 1 |
| | | if buy_count == 0: |
| | | return False |
| | | return False, "买入数量为0" |
| | | if round(cancel_count / buy_count, 2) > threshhold_rate: |
| | | return True |
| | | return False |
| | | return True, f"买入数量-{buy_count} 撤单数量-{cancel_count}" |
| | | return False, f"买入数量-{buy_count} 撤单数量-{cancel_count}" |
| | | |
| | | |
| | | def is_far_away_from_trade_index(code, trade_index, buy1_money): |
| | |
| | | @param trade_index: |
| | | @return: |
| | | """ |
| | | total_data = l2_data_util.local_today_datas.get(code) |
| | | total_count = 0 |
| | | total_big_count = 0 |
| | | for i in range(trade_index + 1, total_data[-1]["index"] + 1): |
| | | data = total_data[i] |
| | | val = data["val"] |
| | | if not l2_data_util.L2DataUtil.is_limit_up_price_buy(val): |
| | | continue |
| | | money = val["num"] * float(val["price"]) |
| | | if money < 5000: |
| | | continue |
| | | # 获取今日成交量与参考量 |
| | | # today = get_today_volumn(code) |
| | | # max60, yesterday = get_histry_volumn(code) |
| | | try: |
| | | today_volume = code_volumn_manager.CodeVolumeManager().get_today_volumn_cache(code) |
| | | histry_volumn = code_volumn_manager.CodeVolumeManager().get_histry_volumn(code) |
| | | if not today_volume or not histry_volumn: |
| | | return False, "尚未获取到量" |
| | | threshhold_volume = (histry_volumn[0][0] - today_volume) // 3 |
| | | limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) |
| | | threshhold_volumes = threshhold_volume // 100, int(50000 / limit_up_price), int(200000 / limit_up_price) |
| | | |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2( |
| | | code, |
| | | i, |
| | | total_data, |
| | | l2_data_util.local_today_canceled_buyno_map.get( |
| | | code)) |
| | | if left_count > 0: |
| | | total_count += 1 |
| | | if money > 29900: |
| | | total_big_count += 1 |
| | | if total_count > 10: |
| | | break |
| | | if total_count > 10 or total_big_count < 1: |
| | | return False, f"未成交数量-{total_count},大单数量-{total_big_count}" |
| | | return True, "" |
| | | total_data = l2_data_util.local_today_datas.get(code) |
| | | total_count = 0 |
| | | total_big_count = 0 |
| | | total_num = 0 |
| | | for i in range(trade_index + 1, total_data[-1]["index"] + 1): |
| | | data = total_data[i] |
| | | val = data["val"] |
| | | if not l2_data_util.L2DataUtil.is_limit_up_price_buy(val): |
| | | continue |
| | | money = val["num"] * float(val["price"]) |
| | | if money < 5000: |
| | | continue |
| | | |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2( |
| | | code, |
| | | i, |
| | | total_data, |
| | | l2_data_util.local_today_canceled_buyno_map.get( |
| | | code)) |
| | | if left_count > 0: |
| | | total_num += val["num"] |
| | | total_count += 1 |
| | | if money > 29900: |
| | | total_big_count += 1 |
| | | if threshhold_volumes[2] < total_num: |
| | | break |
| | | if threshhold_volumes[1] <= total_num <= threshhold_volumes[2] and total_num < threshhold_volumes[ |
| | | 0] and total_big_count > 0: |
| | | # 剩余的值在500w-2000w之间才会参与计算 |
| | | return True, "" |
| | | return False, f"未成交手数-{total_num},阈值-{threshhold_volumes[0]},大单数量-{total_big_count}" |
| | | except Exception as e: |
| | | async_log_util.error(logger_l2_error, f"计算是否距离成交进度位置近:{str(e)}") |
| | | return False, "计算异常" |
| | | |
| | | |
| | | def is_quantization(code, start_index, end_index): |
| | |
| | | @param end_index: |
| | | @return:(是否是量化, 下次可以下单时间) |
| | | """ |
| | | THRESHOLD_BUY_COUNT = 20 |
| | | if end_index - start_index + 1 < THRESHOLD_BUY_COUNT: |
| | | # 总数小于阈值 |
| | | return False, None |
| | | |
| | | # 阈值的取值范围 |
| | | THRESHOLD_MONEY_RANGE = 1e5, 3e5 |
| | | today_volume = code_volumn_manager.CodeVolumeManager().get_today_volumn_cache(code) |
| | | histry_volumn = code_volumn_manager.CodeVolumeManager().get_histry_volumn(code) |
| | | if not today_volume or not histry_volumn: |
| | | return False, "尚未获取到量" |
| | | threshhold_volume = (histry_volumn[0][0] - today_volume) // 6 // 100 |
| | | limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) |
| | | threshhold_volumes_range = int(THRESHOLD_MONEY_RANGE[0] / limit_up_price), int( |
| | | THRESHOLD_MONEY_RANGE[1] / limit_up_price) |
| | | if threshhold_volume < threshhold_volumes_range[0]: |
| | | threshhold_volume = threshhold_volumes_range[0] |
| | | if threshhold_volume > threshhold_volumes_range[1]: |
| | | threshhold_volume = threshhold_volumes_range[1] |
| | | total_datas = l2_data_util.local_today_datas.get(code) |
| | | |
| | | time_as_ms = tool.trade_time_sub_with_ms( |
| | | L2DataUtil.get_time_with_ms(total_datas[end_index]["val"]), |
| | | L2DataUtil.get_time_with_ms(total_datas[start_index]["val"])) |
| | | if time_as_ms > (10 if tool.is_sz_code(code) else 100): |
| | | return False, "非量化" |
| | | |
| | | limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) |
| | | |
| | | buy_count = 0 |
| | | total_buy_nums = 0 |
| | | min_num = int(5000 / limit_up_price) |
| | | trade_index, is_default = transaction_progress.TradeBuyQueue().get_traded_index(code) |
| | | if trade_index is None: |
| | | trade_index = 0 |
| | | # 获取成交进度位 |
| | | for i in range(start_index, end_index + 1): |
| | | val = total_datas[i]["val"] |
| | |
| | | continue |
| | | if val["num"] < min_num: |
| | | continue |
| | | buy_count += 1 |
| | | if buy_count > THRESHOLD_BUY_COUNT: |
| | | total_buy_nums += val["num"] |
| | | if total_buy_nums > threshhold_volume: |
| | | break |
| | | if buy_count > THRESHOLD_BUY_COUNT: |
| | | if total_buy_nums > threshhold_volume: |
| | | # 判断是否为量化 |
| | | time_as_ms = tool.trade_time_sub_with_ms( |
| | | L2DataUtil.get_time_with_ms(total_datas[end_index]["val"]), |
| | | L2DataUtil.get_time_with_ms(total_datas[start_index]["val"])) |
| | | if time_as_ms <= 10 if tool.is_sz_code(code) else 100: |
| | | # 深证10ms内,上证100ms内就判定为量化 |
| | | HuaXinSellOrderStatisticManager.clear_latest_deal_volume(code) |
| | | next_buy_time = time.time() + buy_condition_util.get_cancel_and_buy_space_time( |
| | | code) / 1000 |
| | | # 如果是首次下单,增加一次下单次数 |
| | | 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 True, next_buy_time, f"执行位批次数据量({buy_count})大于{THRESHOLD_BUY_COUNT} {start_index}-{end_index}" |
| | | return False, None |
| | | # 深证10ms内,上证100ms内就判定为量化 |
| | | HuaXinSellOrderStatisticManager.clear_latest_deal_volume(code) |
| | | next_buy_time = time.time() + buy_condition_util.get_cancel_and_buy_space_time( |
| | | code) / 1000 |
| | | # 如果是首次下单,增加一次下单次数 |
| | | 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 True, next_buy_time, f"执行位批次数据量({total_buy_nums})大于{threshhold_volume} {start_index}-{end_index}" |
| | | else: |
| | | return False, None |
| | | |