| | |
| | | def __init__(self): |
| | | # L后撤单 |
| | | self.l_down = {} |
| | | self.__db = 3 |
| | | self.__redis_manager = redis_manager.RedisManager(self.__db) |
| | | self.__load_data() |
| | | |
| | | def __load_data(self): |
| | | keys = RedisUtils.keys(self.__get_redis(), "l_down_cancel_rate_human-{}") |
| | | if keys: |
| | | for k in keys: |
| | | code = k.split("-")[1] |
| | | val = RedisUtils.get(self.__get_redis(), k) |
| | | if val: |
| | | self.l_down[code] = round(float(val), 2) |
| | | |
| | | def __get_redis(self): |
| | | return self.__redis_manager.getRedis() |
| | | |
| | | def set_l_down(self, code, rate): |
| | | """ |
| | | 设置L后撤比例 |
| | | @param code: |
| | | @param rate: |
| | | @return: |
| | | """ |
| | | async_log_util.info(logger_l2_l_cancel, f"人为修改L后撤单比例:{code}-{rate}") |
| | | self.l_down[code] = rate |
| | | RedisUtils.setex_async(self.__db, f"l_down_cancel_rate_human-{code}", tool.get_expire(), rate) |
| | | |
| | | def get_l_down(self, code): |
| | | return self.l_down.get(code) |
| | |
| | | def remove_l_down(self, code): |
| | | if code in self.l_down: |
| | | self.l_down.pop(code) |
| | | RedisUtils.delete_async(self.__db, f"l_down_cancel_rate_human-{code}") |
| | | |
| | | |
| | | @tool.singleton |
| | |
| | | logger_l2_l_cancel.exception(e) |
| | | if len(watch_indexes) >= MAX_COUNT: |
| | | break |
| | | if not watch_indexes: |
| | | l2_log.l_cancel_debug(code, f"计算L后囊括范围没找到可囊括索引,{start_index}, {re_start_index}, {end_index}") |
| | | return |
| | | |
| | | if watch_indexes: |
| | | ##判断监听的数据中是否有大单## |
| | | # 之前的大单为100w,现在改为正常大单 |
| | |
| | | |
| | | real_place_order_info = self.__real_place_order_index_dict.get(code) |
| | | is_default_place_order_index = real_place_order_info[1] if real_place_order_info else False |
| | | if is_default_place_order_index: |
| | | if is_default_place_order_index and not cancel_rate_info[2][1]: |
| | | # 人为设置的不能取最小 |
| | | thresh_hold_rate = min(0.49, thresh_hold_rate) |
| | | l2_log.l_cancel_debug(code, |
| | | f"L后计算范围:{start_index}-{end_index},已撤单比例:{rate}/{thresh_hold_rate}, 下单位之后的索引:{after_place_order_index_dict}, 最大单-({max_num},{max_num_count}), 人为设置-{cancel_rate_info}, 真实下单位-{real_place_order_info}") |
| | |
| | | """ |
| | | 统计L后的大单信息 |
| | | @param code: |
| | | @return: 囊括金额列表, 成交金额列表, 撤单金额列表, 待成交列表 |
| | | @return: [(索引,金额,手数,状态)] |
| | | """ |
| | | watch_indexes_info = self.__get_watch_indexes_cache(code) |
| | | if not watch_indexes_info: |
| | |
| | | deal_indexes.add(index) |
| | | continue |
| | | not_deal_indexes.add(index) |
| | | all_money_list = [int(float(total_datas[x]['val']['price'] * total_datas[x]['val']['num'] * 100)) for x in |
| | | all_indexes] |
| | | deal_money_list = [int(float(total_datas[x]['val']['price'] * total_datas[x]['val']['num'] * 100)) for x in |
| | | deal_indexes] |
| | | canceled_money_list = [int(float(total_datas[x]['val']['price'] * total_datas[x]['val']['num'] * 100)) for x in |
| | | canceled_indexes] |
| | | not_deal_money_list = [int(float(total_datas[x]['val']['price'] * total_datas[x]['val']['num'] * 100)) for x in |
| | | not_deal_indexes] |
| | | return all_money_list, deal_money_list, canceled_money_list, not_deal_money_list |
| | | fdatas = [] |
| | | for x in all_indexes: |
| | | item = [x, int(float(total_datas[x]['val']['price'] * total_datas[x]['val']['num'] * 100)), total_datas[x]['val']['num']] |
| | | if x in deal_indexes: |
| | | item.append(trade_constant.TRADE_STATE_BUY_SUCCESS) |
| | | elif x in canceled_indexes: |
| | | item.append(trade_constant.TRADE_STATE_BUY_CANCEL_SUCCESS) |
| | | elif x in not_deal_indexes: |
| | | item.append(trade_constant.TRADE_STATE_BUY_DELEGATED) |
| | | else: |
| | | item.append(trade_constant.TRADE_STATE_NOT_TRADE) |
| | | fdatas.append(item) |
| | | fdatas.sort(key=lambda x: x[0]) |
| | | return fdatas |
| | | |
| | | # def statistic_total_big_order_info(self, code): |
| | | # """ |
| | |
| | | """ |
| | | self.__l_cancel_triggered_codes.add(code) |
| | | self.__compute_watch_index(code, buy_single_index) |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | CancelRateHumanSettingManager() |
| | |
| | | return False |
| | | return True |
| | | |
| | | def set_price_info(self, code, price, time, sell1_info): |
| | | def set_price_info(self, code, price, time_str, sell1_info): |
| | | """ |
| | | 设置价格信息 |
| | | @param sell1_info: 卖1信息:(卖1价, 卖1量) |
| | | @param code: |
| | | @param price: |
| | | @param time: |
| | | @param time_str: |
| | | @return: |
| | | """ |
| | | price_info = (price, time_str, sell1_info) |
| | | old_price_info = self.__max_price_info_cache.get(code) |
| | | if old_price_info and old_price_info[0] >= price: |
| | | return |
| | | price_info = (price, time, sell1_info) |
| | | if not old_price_info or old_price_info[0] < price: |
| | | tool.CodeDataCacheUtil.set_cache(self.__max_price_info_cache, code, price_info) |
| | | RedisUtils.setex_async( |
| | | self.__db, "max_price_info-{}".format(code), tool.get_expire(), json.dumps(price_info)) |
| | | # async_log_util.info(logger_debug, f"最大现价:{code}-{price_info}") |
| | | # 统计涨停持续时间 |
| | | if self.__is_limit_up(code, price, sell1_info): |
| | | if code not in self.__limit_up_latest_info_cache: |
| | | self.__limit_up_latest_info_cache[code] = time |
| | | self.__limit_up_latest_info_cache[code] = time_str |
| | | else: |
| | | if code not in self.__limit_up_records_cache: |
| | | self.__limit_up_records_cache[code] = [] |
| | | if code in self.__limit_up_latest_info_cache: |
| | | limit_up_info = (self.__limit_up_latest_info_cache.get(code), time) |
| | | limit_up_info = (self.__limit_up_latest_info_cache.get(code), time_str) |
| | | self.__limit_up_records_cache[code].append(limit_up_info) |
| | | self.__limit_up_latest_info_cache.pop(code) |
| | | async_log_util.info(logger_limit_up_record, f"{code}-{limit_up_info}") |
| | |
| | | else: |
| | | data.append("--") |
| | | zylt_volume = global_util.zylt_volume_map.get(code) |
| | | if limit_up_price and zylt_volume: |
| | | zyltgb = zylt_volume * limit_up_price |
| | | else: |
| | | zyltgb = None |
| | | if latest_transaction_data: |
| | | data.append( |
| | | (latest_transaction_data[2] // 100, |
| | |
| | | response_data = json.dumps({"code": 0, "data": fdatas}) |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | elif url.path == "/get_l2_down_watch_index_overview": |
| | | elif url.path == "/get_l_down_watch_index_overview": |
| | | try: |
| | | ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) |
| | | code = ps_dict.get('code') |
| | | # 大单概览 |
| | | l2_down_data = LCancelBigNumComputer().statistic_l_down_watch_indexes_of_big_order_info(code) |
| | | # total_big_order_info = LCancelBigNumComputer().statistic_total_big_order_info(code) |
| | | response_data = json.dumps({"code": 0, "data": {"l_down": l2_down_data}}) |
| | | response_data = json.dumps({"code": 0, "data": l2_down_data}) |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | |
| | |
| | | if len(deal_codes) >= MAX_COUNT: |
| | | l2_log.info(code, logger_l2_radical_buy, f"扫入成交代码个数大于{MAX_COUNT}个:{code}-{deal_codes}") |
| | | return True |
| | | if code in deal_codes: |
| | | if code in deal_codes and not CodesContinueBuyMoneyManager().get_continue_buy_money(code): |
| | | l2_log.info(code, logger_l2_radical_buy, f"该代码已经成交:{code}") |
| | | return True |
| | | |
| | |
| | | l2_trade_util.forbidden_trade(code, msg="交易成功", force=True) |
| | | state = CodesTradeStateManager().get_trade_state_cache(code) |
| | | if state != trade_constant.TRADE_STATE_BUY_SUCCESS: |
| | | if not CodesContinueBuyMoneyManager().get_continue_buy_money(code): |
| | | # 没设置续买 |
| | | CodesTradeStateManager().set_trade_state(code, trade_constant.TRADE_STATE_BUY_SUCCESS) |
| | | # 删除买撤记录的临时信息 |
| | | kp_client_msg_manager.add_msg(code, "买入成交") |