| | |
| | | return time_ |
| | | |
| | | |
| | | def __get_async_log_time(line): |
| | | line = line.split(" - ")[1] |
| | | time_str = line[line.find("[") + 1:line.find("[") + 9] |
| | | return time_str |
| | | |
| | | |
| | | # 获取L2每次批量处理数据的位置范围 |
| | | def get_l2_process_position(code, date=None): |
| | | if not date: |
| | |
| | | except: |
| | | pass |
| | | return index_list, buy_queues |
| | | |
| | | |
| | | # 获取l2不能买的原因 |
| | | def get_l2_cant_buy_reasons(code, date=None): |
| | | if not date: |
| | | date = datetime.datetime.now().strftime("%Y-%m-%d") |
| | | fdatas = [] |
| | | path_str = "{}/logs/gp/l2/l2_not_buy_reasons.{}.log".format(constant.get_path_prefix(), date) |
| | | lines = __load_file_content(path_str) |
| | | for line in lines: |
| | | if not line: |
| | | break |
| | | if line.find(f"{code}#") < 0: |
| | | continue |
| | | |
| | | line = line.split(" - ")[1] |
| | | time_str = line[line.find("[") + 1:line.find("[") + 9] |
| | | data = line[line.find("]") + 1:].strip() |
| | | code_ = data.split("#")[0].strip() |
| | | data = data.split("#")[1].strip() |
| | | if code_ != code: |
| | | continue |
| | | fdatas.append((time_str, data)) |
| | | return fdatas |
| | | |
| | | |
| | | # 获取H级撤单计算结果 |
| | |
| | | if data.startswith("["): |
| | | data = data[data.find("]") + 1:].strip() |
| | | code = data.split("#")[0] |
| | | l2_data = eval( data.split("#")[1]) |
| | | l2_data = eval(data.split("#")[1]) |
| | | if code not in fdatas: |
| | | fdatas[code]=[] |
| | | fdatas[code] = [] |
| | | fdatas[code].append(l2_data) |
| | | except: |
| | | pass |
| | |
| | | logging.exception(e) |
| | | |
| | | # 获取评分信息 |
| | | pass |
| | | elif url.path == "/get_l2_cant_buy_reasons": |
| | | # 获取L2没买的原因 |
| | | ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) |
| | | code = ps_dict['code'] |
| | | fdatas = log_export.get_l2_cant_buy_reasons(code) |
| | | response_data = json.dumps({"code": 0, "data": fdatas}) |
| | | |
| | | elif url.path == "/get_kpl_block_info": |
| | | start_time = time.time() |
| | | ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) |
| | |
| | | class OutsideApiCommandCallback(outside_api_command_manager.ActionCallback): |
| | | __cancel_sell_thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=8) |
| | | __DealRecordManager = DealRecordManager() |
| | | __code_sell_way_dict={} |
| | | |
| | | @classmethod |
| | | def __send_response(cls, data_bytes): |
| | |
| | | logging.exception(e) |
| | | self.send_response({"code": 1, "msg": f"数据处理出错:{e}"}, client_id, request_id) |
| | | finally: |
| | | use_time = time.time()-__start_time |
| | | use_time = time.time() - __start_time |
| | | if use_time > 0.01: |
| | | # 耗时10ms以上才记录日志 |
| | | async_log_util.info(logger_trade_position_api_request, f"{code}请求持仓耗时:{use_time*1000}ms") |
| | | |
| | | async_log_util.info(logger_trade_position_api_request, f"{code}请求持仓耗时:{use_time * 1000}ms") |
| | | |
| | | def OnCommonRequest(self, client_id, request_id, data): |
| | | # 通用请求 |
| | |
| | | buy_single_index=order_begin_pos.buy_single_index) |
| | | result = {"code": 0, "data": {}} |
| | | self.send_response(result, client_id, request_id) |
| | | elif ctype == "get_positions": |
| | | # 获取所有持仓信息 |
| | | positions = PositionManager.latest_positions |
| | | fdatas=[] |
| | | if positions: |
| | | for d in positions: |
| | | code_ = d["securityID"] |
| | | code_name = gpcode_manager.get_code_name(d["securityID"]) |
| | | if not code_name: |
| | | # 判断是否有名称 |
| | | results = HistoryKDatasUtils.get_gp_codes_names([code_]) |
| | | threading.Thread( |
| | | target=CodesNameManager.add_first_code_name(code_, |
| | | results[code_])).start() |
| | | if d["prePosition"] <= 0: |
| | | continue |
| | | fdatas.append({"code":code_,"code_name":code_name,"total":d["prePosition"],"available": d["availablePosition"]}) |
| | | result = {"code": 0, "data": fdatas} |
| | | self.send_response(result, client_id, request_id) |
| | | elif ctype == "set_code_sell_way": |
| | | # 设置卖出方式 |
| | | # mode : 1-均分 2-百分比 |
| | | sell_manager.set_code_sell_way(data) |
| | | result = {"code": 0, "data": {}} |
| | | self.send_response(result, client_id, request_id) |
| | | |
| | | |
| | | except Exception as e: |
| | | logging.exception(e) |
| | |
| | | import time |
| | | |
| | | from log_module import async_log_util |
| | | from log_module.log import logger_trade |
| | | from log_module.log import logger_trade, logger_trade_position_api_request |
| | | from trade.huaxin import huaxin_trade_order_processor, huaxin_trade_api |
| | | from utils import huaxin_util, sell_util, tool |
| | | |
| | |
| | | if int("092958") <= int(tool.get_now_time_str().replace(":", "")) <= int("145655"): |
| | | __cancel_sell_thread_pool.submit(lambda: __cancel_sell_order(code, order_ref)) |
| | | return result |
| | | |
| | | |
| | | __code_sell_way_dict = {} |
| | | |
| | | |
| | | def set_code_sell_way(data): |
| | | fdata = {} |
| | | code = data["code"] |
| | | mode = data["mode"] |
| | | if mode == 1: |
| | | mode1_rate_index = data["mode1_rate_index"] |
| | | fdata["mode1_rate_index"] = mode1_rate_index |
| | | elif mode == 2: |
| | | # 第一笔卖的索引 |
| | | mode2_first_index = data["mode2_first_index"] |
| | | # 剩下几笔卖的索引 |
| | | mode2_left_index = data["mode2_left_index"] |
| | | fdata["mode2_first_index"] = mode2_first_index |
| | | fdata["mode2_left_index"] = mode2_left_index |
| | | fdata["code"] = code |
| | | fdata["mode"] = mode |
| | | __code_sell_way_dict[code] = fdata |
| | | # 保存卖的方式 |
| | | async_log_util.info(logger_trade_position_api_request, f"设置卖出方式:{fdata}") |
| | | |
| | | |
| | | # 计算卖出量 |
| | | def compute_sell_volume(code): |
| | | if code not in __code_sell_way_dict: |
| | | raise Exception("还没设置卖出方式") |
| | | sell_way = __code_sell_way_dict.get(code) |
| | | # TODO |
| | | return 100 |
| | | |