| | |
| | | import concurrent.futures |
| | | import copy |
| | | import json |
| | | import logging |
| | | import threading |
| | |
| | | logger_trade, logger_trade_position_api_request, logger_request_api, \ |
| | | logger_real_place_order_position, logger_device |
| | | from output import l2_output_util |
| | | from third_data import kpl_data_manager, kpl_util, history_k_data_manager |
| | | from third_data.code_plate_key_manager import CodePlateKeyBuyManager |
| | | from third_data import kpl_util, history_k_data_manager, huaxin_l1_data_manager, third_blocks_manager, kpl_data_manager |
| | | from third_data.code_plate_key_manager import CodePlateKeyBuyManager, KPLCodeJXBlockManager, RealTimeKplMarketData, \ |
| | | RadicalBuyBlockManager |
| | | from third_data.history_k_data_manager import HistoryKDataManager |
| | | from third_data.history_k_data_util import JueJinApi, HistoryKDatasUtils |
| | | from third_data.kpl_data_manager import KPLDataManager |
| | | from third_data.kpl_limit_up_data_manager import CodeLimitUpSequenceManager |
| | | from third_data.kpl_util import KPLDataType |
| | | from trade import trade_manager, l2_trade_util |
| | | from third_data.third_blocks_manager import CodeThirdBlocksManager, SOURCE_TYPE_KPL, BlockMapManager |
| | | from trade import trade_manager, l2_trade_util, trade_data_manager, trade_constant |
| | | import l2_data_util as l2_data_util_old |
| | | from trade.buy_money_count_setting import BuyMoneyAndCountSetting |
| | | |
| | | from trade.huaxin import huaxin_trade_api, huaxin_trade_data_update, \ |
| | | huaxin_trade_record_manager, huaxin_trade_order_processor, huaxin_sell_util |
| | |
| | | raise Exception("尚未获取到现价") |
| | | # 获取买1金额 |
| | | price = round(float(current_price), 2) |
| | | buy1_info = L1DataManager.current_buy1_dict.get(code) |
| | | buy1_info = huaxin_l1_data_manager.get_buy1_info(code) |
| | | if buy1_info and buy1_info[0] * buy1_info[1] > 50 * 10000: |
| | | # 如果买1在50w以上就加一档 |
| | | price += 0.01 |
| | |
| | | accountID = data["accountID"] |
| | | orderSysID = data["orderSysID"] |
| | | sinfo = data["sinfo"] |
| | | async_log_util.info(logger_trade, f"API撤单: {data}") |
| | | if orderSysID: |
| | | result = huaxin_trade_api.cancel_order(direction, code, orderSysID, sinfo=sinfo, |
| | | blocking=True, request_id=request_id) |
| | |
| | | msg_list.append(f"撤卖单数量:{sell_count}") |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | can_cancel = l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, "手动撤单") |
| | | can_cancel = l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, "手动撤单", |
| | | cancel_type=trade_constant.CANCEL_TYPE_HUMAN) |
| | | if not can_cancel: |
| | | msg_list.append(f"无法撤买单") |
| | | else: |
| | | msg_list.append(f"已撤买单") |
| | | async_log_util.info(logger_trade, f"API撤单结果: {msg_list}") |
| | | self.send_response({"code": 0, "data": {"code": 0, "msg": ";".join(msg_list)}}, client_id, |
| | | request_id) |
| | | except Exception as e: |
| | |
| | | code_list_type = data["code_list_type"] |
| | | operate = data["operate"] |
| | | code = data.get("code") |
| | | if code and not tool.is_can_buy_code(code): |
| | | raise Exception(f"不是可以交易的代码:{code}") |
| | | fresult = {"code": 0} |
| | | if code_list_type == outside_api_command_manager.CODE_LIST_WANT: |
| | | if operate == outside_api_command_manager.OPERRATE_SET: |
| | | gpcode_manager.WantBuyCodesManager().add_code(code) |
| | | # 加想买单要从黑名单移除 |
| | | l2_trade_util.remove_from_forbidden_trade_codes(code) |
| | | name = gpcode_manager.get_code_name(code) |
| | | if not name: |
| | | results = HistoryKDatasUtils.get_gp_codes_names([code]) |
| | |
| | | if operate == outside_api_command_manager.OPERRATE_SET: |
| | | # 先手动撤单 |
| | | try: |
| | | l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, "手动拉黑") |
| | | l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, "手动拉黑", |
| | | cancel_type=trade_constant.CANCEL_TYPE_HUMAN) |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | l2_trade_util.forbidden_trade(code, msg="手动加入 trade_server") |
| | |
| | | name = gpcode_manager.get_code_name(code) |
| | | datas.append(f"{name}:{code}") |
| | | fresult = {"code": 0, "data": datas} |
| | | elif code_list_type == outside_api_command_manager.CODE_LIST_GREEN: |
| | | if operate == outside_api_command_manager.OPERRATE_SET: |
| | | gpcode_manager.GreenListCodeManager().add_code(code) |
| | | name = gpcode_manager.get_code_name(code) |
| | | if not name: |
| | | results = HistoryKDatasUtils.get_gp_codes_names([code]) |
| | | if results: |
| | | gpcode_manager.CodesNameManager.add_first_code_name(code, results[code]) |
| | | elif operate == outside_api_command_manager.OPERRATE_DELETE: |
| | | gpcode_manager.GreenListCodeManager().remove_code(code) |
| | | elif operate == outside_api_command_manager.OPERRATE_GET: |
| | | codes = gpcode_manager.GreenListCodeManager().list_codes_cache() |
| | | datas = [] |
| | | for code in codes: |
| | | name = gpcode_manager.get_code_name(code) |
| | | datas.append(f"{name}:{code}") |
| | | fresult = {"code": 0, "data": datas} |
| | | |
| | | self.send_response(fresult, client_id, request_id) |
| | | except Exception as e: |
| | |
| | | white = gpcode_manager.WhiteListCodeManager().is_in_cache(code) |
| | | black = l2_trade_util.is_in_forbidden_trade_codes(code) |
| | | pause_buy = gpcode_manager.PauseBuyCodesManager().is_in_cache(code) |
| | | |
| | | must_buy = gpcode_manager.MustBuyCodesManager().is_in_cache(code) |
| | | desc_list = [] |
| | | if want: |
| | | desc_list.append("【想买单】") |
| | |
| | | desc_list.append("【黑名单】") |
| | | if pause_buy: |
| | | desc_list.append("【暂不买】") |
| | | if must_buy: |
| | | desc_list.append("【红名单】") |
| | | |
| | | result = {"code": 0, "data": {"code_info": (code, code_name), "desc": "".join(desc_list)}} |
| | | self.send_response(result, client_id, request_id) |
| | | except Exception as e: |
| | |
| | | l1_subscript_codes_manager.save_codes(codes_sh, codes_sz) |
| | | result = {"code": 0, "data": {"codes_sh": len(codes_sh), "codes_sz": len(codes_sz)}} |
| | | self.send_response(result, client_id, request_id) |
| | | # 拉取三方板块 |
| | | codes = [] |
| | | codes.extend(codes_sh) |
| | | codes.extend(codes_sz) |
| | | threading.Thread(target=third_blocks_manager.load_if_less, args=(codes,), daemon=True).start() |
| | | except Exception as e: |
| | | logger_debug.error(e) |
| | | |
| | |
| | | except Exception as e: |
| | | self.send_response({"code": 1, "msg": str(e)}, client_id, request_id) |
| | | elif ctype == "get_delegated_buy_code_infos": |
| | | account_available_money = trade_manager.AccountAvailableMoneyManager().get_available_money_cache() |
| | | account_available_money = trade_data_manager.AccountMoneyManager().get_available_money_cache() |
| | | # 获取委托中的代码 |
| | | # current_delegates = huaxin_trade_record_manager.DelegateRecordManager().list_current_delegates() |
| | | current_delegates, update_time = huaxin_trade_record_manager.DelegateRecordManager.list_by_day( |
| | |
| | | limit_up_data = kpl_data_manager.KPLLimitUpDataRecordManager.record_code_dict.get(code) |
| | | # 获取当前板块 |
| | | try: |
| | | can_buy_result = CodePlateKeyBuyManager.can_buy(code) |
| | | if can_buy_result: |
| | | if can_buy_result[0]: |
| | | fdata['block'] = ",".join( |
| | | [f"{x[0]}-{x[1] + 1}({x[2]}&{x[3] - x[2]})" for x in can_buy_result[0]]) |
| | | else: |
| | | if can_buy_result[1]: |
| | | if limit_up_data: |
| | | fdata['block'] = f"{limit_up_data[5]}-独苗" |
| | | else: |
| | | fdata['block'] = f"独苗" |
| | | limit_up_sequence = CodeLimitUpSequenceManager.get_current_limit_up_sequence(code) |
| | | if limit_up_sequence: |
| | | fdata[ |
| | | 'block'] = f"{limit_up_sequence[0]}-{limit_up_sequence[1]}({limit_up_sequence[2]}&{limit_up_sequence[2] - limit_up_sequence[3]})" |
| | | except: |
| | | pass |
| | | # 获取涨停时间 |
| | |
| | | elif ctype == "get_buy_block_mode": |
| | | # 获取买入板块的模式 |
| | | can_buy_unique_block = TradeBlockBuyModeManager().can_buy_unique_block() |
| | | self.send_response({"code": 0, "data": {"unique_block": 1 if can_buy_unique_block else 0 }, "msg": f""}, client_id, |
| | | self.send_response({"code": 0, "data": {"unique_block": 1 if can_buy_unique_block else 0}, "msg": f""}, |
| | | client_id, |
| | | request_id) |
| | | |
| | | elif ctype == "set_buy_unique_block_mode": |
| | |
| | | self.send_response({"code": 0, "data": {}, "msg": f""}, |
| | | client_id, |
| | | request_id) |
| | | elif ctype == "get_code_third_blocks": |
| | | # 获取第三方板块数据 |
| | | code = data["code"] |
| | | source_dict = copy.deepcopy(CodeThirdBlocksManager().get_source_blocks(code)) |
| | | if not source_dict: |
| | | source_dict = {} |
| | | source_origin_dict = copy.deepcopy(CodeThirdBlocksManager().get_source_blocks_origin(code)) |
| | | if not source_origin_dict: |
| | | source_origin_dict = {} |
| | | kpl_blocks = RadicalBuyBlockManager.get_code_kpl_blocks(code) |
| | | if kpl_blocks is None: |
| | | kpl_blocks = set() |
| | | if not kpl_blocks: |
| | | KPLCodeJXBlockManager().load_jx_blocks_radical(code) |
| | | |
| | | filter_blocks, match_blocks = RadicalBuyBlockManager.get_code_blocks(code) |
| | | source_origin_dict[SOURCE_TYPE_KPL] = kpl_blocks |
| | | source_dict[SOURCE_TYPE_KPL] = BlockMapManager().filter_blocks(kpl_blocks) |
| | | data = { |
| | | "blocks": {}, |
| | | "origin_blocks": {}, |
| | | "match_blocks": [list(filter_blocks), list(match_blocks)] |
| | | } |
| | | for s in source_origin_dict: |
| | | data["origin_blocks"][s] = list(source_origin_dict[s]) |
| | | for s in source_dict: |
| | | data["blocks"][s] = list(source_dict[s]) |
| | | |
| | | |
| | | self.send_response({"code": 0, "data": data, "msg": f""}, |
| | | client_id, |
| | | request_id) |
| | | elif ctype == "set_buy_money_count_setting": |
| | | # 设置买入金额和数量 |
| | | normal = data["normal"] |
| | | radical = data["radical"] |
| | | BuyMoneyAndCountSetting().set_normal_buy_data(normal[0], json.loads(normal[1])) |
| | | BuyMoneyAndCountSetting().set_radical_buy_data(radical[0], json.loads(radical[1])) |
| | | data = { |
| | | "normal": BuyMoneyAndCountSetting().get_normal_buy_setting(), |
| | | "radical": BuyMoneyAndCountSetting().get_radical_buy_setting() |
| | | } |
| | | self.send_response({"code": 0, "data": data, "msg": f""}, |
| | | client_id, |
| | | request_id) |
| | | elif ctype == "get_buy_money_count_setting": |
| | | # 设置买入金额和数量 |
| | | data = { |
| | | "normal": BuyMoneyAndCountSetting().get_normal_buy_setting(), |
| | | "radical": BuyMoneyAndCountSetting().get_radical_buy_setting(), |
| | | "moneys":constant.AVAILABLE_BUY_MONEYS |
| | | } |
| | | self.send_response({"code": 0, "data": data, "msg": f""}, |
| | | client_id, |
| | | request_id) |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | logger_debug.exception(e) |
| | | self.send_response({"code": 1, "msg": f"数据处理出错:{e}"}, client_id, request_id) |
| | | finally: |
| | | use_time = time.time() - __start_time |