| | |
| | | return data_json[1] |
| | | return [] |
| | | |
| | | def set_code_special_watch_volume(self, code, volume): |
| | | # 有效期为3s |
| | | # self.special_code_volume_for_order_dict[code] = (volume, time.time() + 3) |
| | | d = self.codes_volume_and_price_dict.get(code) |
| | | if d: |
| | | min_volume, limit_up_price, special_price, buy_volume = d[0], d[1], d[2], d[3] |
| | | self.l2_data_upload_manager.set_order_fileter_condition(code, min_volume, limit_up_price, special_price, |
| | | buy_volume, |
| | | {volume, constant.SHADOW_ORDER_VOLUME}, |
| | | time.time() + 3) |
| | | huaxin_l2_log.info(logger_local_huaxin_l2_subscript, f"设置下单量监听:{code}-{volume}") |
| | | |
| | | def OnFrontConnected(self): |
| | | print("OnFrontConnected") |
| | | logger_system.info(f"l2_client OnFrontConnected 线程ID:{tool.get_thread_id()}") |
| | |
| | | value = value.decode("utf-8") |
| | | data = json.loads(value) |
| | | _type = data["type"] |
| | | if _type == "listen_volume": |
| | | volume = data["data"]["volume"] |
| | | code = data["data"]["code"] |
| | | spi.set_code_special_watch_volume(code, volume) |
| | | elif _type == "l2_cmd": |
| | | if _type == "l2_cmd": |
| | | __start_time = time.time() |
| | | # 线程池 |
| | | __l2_cmd_thread_pool.submit( |
| | |
| | | |
| | | # 设置订单过滤条件 |
| | | # special_price:过滤的1手的价格 |
| | | def set_order_fileter_condition(self, code, min_volume, limit_up_price, special_price, buy_volume, |
| | | special_volumes=None, |
| | | special_volumes_expire_time=None): |
| | | if special_volumes is None: |
| | | special_volumes = set() |
| | | if code in self.filter_order_condition_dict and not special_volumes and not special_volumes_expire_time: |
| | | self.filter_order_condition_dict[code][0] = (min_volume, limit_up_price, special_price, buy_volume) |
| | | def set_order_fileter_condition(self, code, min_volume, limit_up_price, shadow_price, buy_volume): |
| | | if code not in self.filter_order_condition_dict: |
| | | self.filter_order_condition_dict[code] = [(min_volume, limit_up_price, shadow_price, buy_volume)] |
| | | huaxin_l2_log.info(logger_local_huaxin_l2_subscript, |
| | | f"({code})常规过滤条件设置:{self.filter_order_condition_dict[code]}") |
| | | else: |
| | | self.filter_order_condition_dict[code] = [(min_volume, limit_up_price, special_price, buy_volume), |
| | | special_volumes, |
| | | special_volumes_expire_time] |
| | | huaxin_l2_log.info(logger_local_huaxin_l2_subscript, |
| | | f"({code})下单后过滤条件设置:{self.filter_order_condition_dict[code]}") |
| | | |
| | | # 过滤订单 |
| | | def __filter_order(self, item): |
| | |
| | | if item[2] >= filter_condition[0][0]: |
| | | return item |
| | | # 1手的买单满足价格 |
| | | if item[2] == 100 and item[3] == '1' and abs(filter_condition[0][2] - item[1]) < 0.001: |
| | | if item[2] == 100 and abs(filter_condition[0][2] - item[1]) < 0.001: |
| | | return item |
| | | # 买量 |
| | | if item[2] == filter_condition[0][3] and item[3] == '1': |
| | | return item |
| | | |
| | | if filter_condition[1] and item[2] in filter_condition[1]: |
| | | if filter_condition[2] and time.time() > filter_condition[2]: |
| | | # 超时了,需要清除特殊量数据 |
| | | filter_condition[1] = set() |
| | | filter_condition[2] = None |
| | | return None |
| | | if item[2] == filter_condition[0][3]: |
| | | return item |
| | | return None |
| | | return item |
| | |
| | | # 统计未撤订单的数量与金额 |
| | | total_datas = local_today_datas.get(code) |
| | | # 是否是下单5分钟内 |
| | | if tool.trade_time_sub(tool.get_now_time_str(), total_datas[real_order_index]['val']['time']) > 2 * 60: |
| | | return False, "下单超过2分钟" |
| | | if tool.trade_time_sub(tool.get_now_time_str(), total_datas[real_order_index]['val']['time']) > 1 * 60: |
| | | return False, "下单超过1分钟" |
| | | |
| | | total_left_count = 0 |
| | | total_left_num = 0 |
| | |
| | | trade_rules_count = len(TradeRuleManager().list_can_excut_rules_cache()) |
| | | |
| | | fdata = {"code": code, "total": 0, "available": 0, "sell_orders": [], "sell_rules_count": trade_rules_count, |
| | | "cost_price": 0, |
| | | "cost_price": 0, "cost_price_rate":0, |
| | | "code_info": (code, code_name), "desc": "".join(desc_list)} |
| | | if positions: |
| | | for d in positions: |
| | |
| | | current_price = TradeServerProcessor.get_l1_current_price(code) |
| | | if current_price: |
| | | fdata["cost_price"] = current_price |
| | | pre_close_price = CodePrePriceManager.get_price_pre_cache(code) |
| | | if current_price and pre_close_price: |
| | | rate = round((float(current_price) - float(pre_close_price)) / float(pre_close_price), 4) |
| | | fdata["cost_price_rate"] = rate |
| | | # 获取涨幅 |
| | | |
| | | async_log_util.info(logger_trade_position_api_request, f"{fdata}") |
| | | result = {"code": 0, "data": fdata} |