| | |
| | | FirstLevelSellOrderVolumes): |
| | | # 传入:时间,现价,成交总量,买1,买2,买3,买4,买5,卖1,卖2,卖3,卖4,卖5 |
| | | try: |
| | | buys = [(pDepthMarketData['BidPrice1'], pDepthMarketData['BidVolume1']), |
| | | (pDepthMarketData['BidPrice2'], pDepthMarketData['BidVolume2']), |
| | | (pDepthMarketData['BidPrice3'], pDepthMarketData['BidVolume3']), |
| | | (pDepthMarketData['BidPrice4'], pDepthMarketData['BidVolume4']), |
| | | (pDepthMarketData['BidPrice5'], pDepthMarketData['BidVolume5'])] |
| | | for i in range(6, 11): |
| | | if not pDepthMarketData[f"BidVolume{i}"]: |
| | | break |
| | | buys.append((pDepthMarketData[f'BidPrice{i}'], pDepthMarketData[f'BidVolume{i}'])) |
| | | |
| | | sells = [ |
| | | (pDepthMarketData['AskPrice1'], pDepthMarketData['AskVolume1']), |
| | | (pDepthMarketData['AskPrice2'], pDepthMarketData['AskVolume2']), |
| | | (pDepthMarketData['AskPrice3'], pDepthMarketData['AskVolume3']), |
| | | (pDepthMarketData['AskPrice4'], pDepthMarketData['AskVolume4']), |
| | | (pDepthMarketData['AskPrice5'], pDepthMarketData['AskVolume5']) |
| | | ] |
| | | for i in range(6, 11): |
| | | if not pDepthMarketData[f"AskVolume{i}"]: |
| | | break |
| | | sells.append((pDepthMarketData[f'AskPrice{i}'], pDepthMarketData[f'AskVolume{i}'])) |
| | | |
| | | d = {"dataTimeStamp": pDepthMarketData['DataTimeStamp'], "securityID": pDepthMarketData['SecurityID'], |
| | | "lastPrice": pDepthMarketData['LastPrice'], |
| | | "totalVolumeTrade": pDepthMarketData['TotalVolumeTrade'], |
| | | "totalValueTrade": pDepthMarketData['TotalValueTrade'], |
| | | "totalAskVolume": pDepthMarketData['TotalAskVolume'], |
| | | "avgAskPrice": pDepthMarketData["AvgAskPrice"], |
| | | "buy": [(pDepthMarketData['BidPrice1'], pDepthMarketData['BidVolume1']), |
| | | (pDepthMarketData['BidPrice2'], pDepthMarketData['BidVolume2']), |
| | | (pDepthMarketData['BidPrice3'], pDepthMarketData['BidVolume3']), |
| | | (pDepthMarketData['BidPrice4'], pDepthMarketData['BidVolume4']), |
| | | (pDepthMarketData['BidPrice5'], pDepthMarketData['BidVolume5'])], |
| | | "sell": [ |
| | | (pDepthMarketData['AskPrice1'], pDepthMarketData['AskVolume1']), |
| | | (pDepthMarketData['AskPrice2'], pDepthMarketData['AskVolume2']), |
| | | (pDepthMarketData['AskPrice3'], pDepthMarketData['AskVolume3']), |
| | | (pDepthMarketData['AskPrice4'], pDepthMarketData['AskVolume4']), |
| | | (pDepthMarketData['AskPrice5'], pDepthMarketData['AskVolume5']) |
| | | ]} |
| | | "buy": buys, |
| | | "sell": sells} |
| | | market_code_dict[pDepthMarketData['SecurityID']] = time.time() |
| | | self.l2_data_upload_manager.add_market_data(d) |
| | | except: |
| | |
| | | local_today_datas.get(code)) |
| | | return False |
| | | else: |
| | | l2_log.debug(code, "可以下单,原因:{}", reason) |
| | | l2_log.debug(code, "可以下单,原因:{}, 下单模式:{}", reason, order_begin_pos.mode) |
| | | try: |
| | | l2_log.debug(code, "开始执行买入") |
| | | trade_manager.start_buy(code, capture_timestamp, last_data, |
| | |
| | | RedisUtils.delete_async(self.__db, k) |
| | | |
| | | # 设置当前的总卖 |
| | | def set_current_total_sell_data(self, code, time_str, money, volume, sell_1_info): |
| | | def set_current_total_sell_data(self, code, time_str, money, volume, sell_1_info, sell_n_info): |
| | | """ |
| | | @param code: |
| | | @param time_str: |
| | | @param money: |
| | | @param volume: |
| | | @param sell_1_info: 格式(卖1价格,卖1量) |
| | | @param sell_n_info:卖挡位 |
| | | @return: |
| | | """ |
| | | # 记录日志 |
| | | async_log_util.info(logger_l2_market_sell, f"{code}: {time_str}-{money} {sell_1_info}") |
| | | async_log_util.info(logger_l2_market_sell, f"{code}: {time_str}-{money} {sell_1_info} {sell_n_info}") |
| | | |
| | | if code not in self.__total_sell_data_cache_list_cache: |
| | | self.__total_sell_data_cache_list_cache[code] = [] |
| | |
| | | 0] == time_str: |
| | | return |
| | | |
| | | self.__total_sell_data_cache_list_cache[code].append((time_str, round(money), volume, sell_1_info)) |
| | | self.__total_sell_data_cache_list_cache[code].append((time_str, round(money), volume, sell_1_info, sell_n_info)) |
| | | # 保留最多10条数据 |
| | | if len(self.__total_sell_data_cache_list_cache[code]) > 10: |
| | | self.__total_sell_data_cache_list_cache[code] = self.__total_sell_data_cache_list_cache[code][-10:] |
| | |
| | | def get_current_total_sell_data(self, code): |
| | | """ |
| | | @param code: |
| | | @return:(时间, 总买额, 总量, 卖1信息) |
| | | @return:(时间, 总买额, 总量, 卖1信息, 卖挡位信息) |
| | | """ |
| | | total_sell_data_cache_list = self.__total_sell_data_cache_list_cache.get(code) |
| | | if not total_sell_data_cache_list: |
| | |
| | | 获取可引用的总卖额 |
| | | @param code: |
| | | @param time_str: 当前数据截止时间 |
| | | @return: (time_str, round(money), volume, sell_1_info) |
| | | @return: (time_str, round(money), volume, sell_1_info, sell_n_infos) |
| | | """ |
| | | total_sell_data_cache_list = self.__total_sell_data_cache_list_cache.get(code) |
| | | if total_sell_data_cache_list: |
| | |
| | | |
| | | # 统计所有的成交量 |
| | | __deal_volume_list_dict = {} |
| | | # 统计主动买的成交量 |
| | | # 统计涨停主动买的成交量 |
| | | __deal_active_buy_volume_list_dict = {} |
| | | |
| | | @classmethod |
| | | def statistic_total_deal_volume(cls, code, datas): |
| | | def statistic_total_deal_volume(cls, code, datas, limit_up_price): |
| | | # 只统计被动买 |
| | | if code not in cls.__deal_volume_list_dict: |
| | | cls.__deal_volume_list_dict[code] = [] |
| | |
| | | # 只统计主动买 |
| | | if d[7] > d[6]: |
| | | continue |
| | | # 只统计涨停买 |
| | | if d[1] != limit_up_price: |
| | | continue |
| | | if d[3] in time_dict: |
| | | time_str = time_dict[d[3]] |
| | | else: |
| | |
| | | @classmethod |
| | | def process_huaxin_transaction_datas(cls, code, datas): |
| | | __start_time = time.time() |
| | | limit_up_price = gpcode_manager.get_limit_up_price(code) |
| | | if limit_up_price: |
| | | limit_up_price = round(float(limit_up_price), 2) |
| | | limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) |
| | | # 设置成交价 |
| | | try: |
| | | current_price_process_manager.set_trade_price(code, datas[-1][1]) |
| | |
| | | # GCancelBigNumComputer().set_big_sell_order_info(code, big_sell_order_info) |
| | | use_time_list.append(("处理卖单相关撤数据", time.time() - _start_time)) |
| | | _start_time = time.time() |
| | | HuaXinSellOrderStatisticManager.statistic_total_deal_volume(code, datas) |
| | | HuaXinSellOrderStatisticManager.statistic_total_deal_volume(code, datas, limit_up_price) |
| | | use_time_list.append(("统计成交量数据", time.time() - _start_time)) |
| | | except Exception as e: |
| | | async_log_util.error(logger_debug, f"卖单统计异常:{big_sell_order_info}") |
| | |
| | | sell_1_info = data["sell"][0] if data.get("sell") else None |
| | | L2MarketSellManager().set_current_total_sell_data(code, time_str, |
| | | data["totalAskVolume"] * data["avgAskPrice"], |
| | | data["totalAskVolume"], sell_1_info) |
| | | data["totalAskVolume"], sell_1_info, data.get("sell")) |
| | | |
| | | @classmethod |
| | | def trading_order_canceled(cls, code, order_no): |
| | |
| | | if refer_sell_data: |
| | | # 如果总卖额大于500w,成交到一半就直接扫 |
| | | if refer_sell_data[1] >= 500 * 1e4: |
| | | THRESH_HOLD_VOLUME = refer_sell_data[2] |
| | | if refer_sell_data[4] and len(refer_sell_data[4]) < 10: |
| | | # 小于10挡,最后一档才是涨停价 |
| | | if refer_sell_data[4][-1][1] > 0: |
| | | THRESH_HOLD_VOLUME = refer_sell_data[4][-1][1] |
| | | |
| | | refer_sell_time = refer_sell_data[0] |
| | | # 获取最近的主动买成交量 |
| | | deal_infos = HuaXinSellOrderStatisticManager.get_latest_6s_active_buy_deal_volumes(code) |
| | | async_log_util.info(logger_l2_radical_buy, f"最近主动买成交:{code}-{deal_infos}") |
| | | limit_up_deal_infos = HuaXinSellOrderStatisticManager.get_latest_6s_active_buy_deal_volumes( |
| | | code) |
| | | async_log_util.info(logger_l2_radical_buy, f"最近涨停主动买成交:{code}-{limit_up_deal_infos}") |
| | | # 总卖额要大于100w |
| | | deal_volume = 0 |
| | | for i in range(0, len(deal_infos)): |
| | | for i in range(0, len(limit_up_deal_infos)): |
| | | # >=统计到的总卖 |
| | | if int(refer_sell_time.replace(":", "")) > int(deal_infos[i][0].replace(":", "")): |
| | | if int(refer_sell_time.replace(":", "")) > int( |
| | | limit_up_deal_infos[i][0].replace(":", "")): |
| | | break |
| | | deal_volume += deal_infos[i][1] |
| | | async_log_util.info(logger_l2_radical_buy, f"成交量:{deal_volume}/{refer_sell_data[2]}") |
| | | deal_rate = round(deal_volume / refer_sell_data[2], 2) |
| | | deal_volume += limit_up_deal_infos[i][1] |
| | | async_log_util.info(logger_l2_radical_buy, f"成交量:{deal_volume}/{THRESH_HOLD_VOLUME}") |
| | | deal_rate = round(deal_volume / THRESH_HOLD_VOLUME, 2) |
| | | if deal_rate > 0.5: |
| | | # 判断参考时间之后是否有大单成交 |
| | | # big_deal_money_list = BigOrderDealManager().get_total_buy_money_list(code) |