Administrator
2024-10-25 4174d4c0b1b8ab9108320db63197a452cd5698d0
api/outside_api_command_callback.py
@@ -1,3 +1,4 @@
import base64
import concurrent.futures
import copy
import json
@@ -26,7 +27,7 @@
    l2_data_source_util, cancel_buy_strategy
from l2.code_price_manager import Buy1PriceManager
from l2.l2_data_manager import TradePointManager
from l2.l2_data_manager import TradePointManager, OrderBeginPosInfo
from l2.l2_data_util import L2DataUtil
from l2.l2_transaction_data_manager import HuaXinBuyOrderManager, BigOrderDealManager
from log_module import async_log_util, log_export
@@ -45,7 +46,7 @@
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.buy_money_count_setting import BuyMoneyAndCountSetting, RadicalBuyBlockCodeCountManager
from trade.huaxin import huaxin_trade_api, huaxin_trade_data_update, \
    huaxin_trade_record_manager, huaxin_trade_order_processor, huaxin_sell_util
@@ -281,10 +282,14 @@
            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])
@@ -379,6 +384,7 @@
            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)
                    gpcode_manager.WantBuyCodesManager().add_code(code)
                    name = gpcode_manager.get_code_name(code)
                    if not name:
                        results = HistoryKDatasUtils.get_gp_codes_names([code])
@@ -386,6 +392,7 @@
                            gpcode_manager.CodesNameManager.add_first_code_name(code, results[code])
                elif operate == outside_api_command_manager.OPERRATE_DELETE:
                    gpcode_manager.GreenListCodeManager().remove_code(code)
                    gpcode_manager.WantBuyCodesManager().remove_code(code)
                elif operate == outside_api_command_manager.OPERRATE_GET:
                    codes = gpcode_manager.GreenListCodeManager().list_codes_cache()
                    datas = []
@@ -439,7 +446,8 @@
            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)
            green = gpcode_manager.GreenListCodeManager().is_in_cache(code)
            desc_list = []
            if want:
                desc_list.append("【想买单】")
@@ -449,6 +457,11 @@
                desc_list.append("【黑名单】")
            if pause_buy:
                desc_list.append("【暂不买】")
            if must_buy:
                desc_list.append("【红名单】")
            if green:
                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:
@@ -866,14 +879,18 @@
                            # 获取下单位置信息
                            order_begin_pos = TradePointManager().get_buy_compute_start_data_cache(code)
                            if order_begin_pos is None or order_begin_pos.buy_single_index is None:
                                continue
                                order_begin_pos = OrderBeginPosInfo(buy_single_index=0, buy_exec_index=0)
                            l2_data_util.load_l2_data(code)
                            total_datas = l2_data_util.local_today_datas.get(code)
                            if not total_datas:
                                continue
                            trade_index, is_default = transaction_progress.TradeBuyQueue().get_traded_index(code)
                            if trade_index is None:
                                trade_index = 0
                            # 下单位置
                            place_order_index = SCancelBigNumComputer().get_real_place_order_index_cache(code)
                            if place_order_index is None:
                                place_order_index = 0
                            # 计算信号位置到真实下单位置的总买(不管是否已撤)
                            total_nums = 0
                            for i in range(order_begin_pos.buy_single_index, place_order_index):
@@ -1091,6 +1108,14 @@
                            except:
                                pass
                            try:
                                if order_begin_pos:
                                    fdata['mode'] = order_begin_pos.mode
                                else:
                                    fdata['mode'] = -1
                            except:
                                pass
                            fdatas.append(fdata)
                        except Exception as e:
                            logger_debug.exception(e)
@@ -1159,8 +1184,8 @@
            elif ctype == "set_per_code_buy_money":
                # 设置单只票的买入金额
                money = data["money"]
                if money > 30000:
                    raise Exception("最多只能设置3w")
                if money > 50000:
                    raise Exception("最多只能设置5w")
                constant.BUY_MONEY_PER_CODE = money
                self.send_response({"code": 0, "data": {"money": constant.BUY_MONEY_PER_CODE}}, client_id, request_id)
            elif ctype == "get_per_code_buy_money":
@@ -1170,6 +1195,8 @@
                kpl_data_manager.PullTask.repaire_pull_task()
                # 修复数据服务
                server_util.repaire_data_server()
                # 任务修复
                huaxin_trade_data_update.repaire_task()
                self.send_response({"code": 0, "data": {}}, client_id, request_id)
            elif ctype == "get_trade_queue":
                code = data["code"]
@@ -1257,8 +1284,12 @@
                # 设置买入金额和数量
                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]))
                default_buy_money = data["default_buy_money"]
                if int(default_buy_money) not in constant.AVAILABLE_BUY_MONEYS:
                    raise Exception("默认金额不在预设金额内")
                constant.BUY_MONEY_PER_CODE = default_buy_money
                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()
@@ -1270,11 +1301,29 @@
                # 设置买入金额和数量
                data = {
                    "normal": BuyMoneyAndCountSetting().get_normal_buy_setting(),
                    "radical": BuyMoneyAndCountSetting().get_radical_buy_setting()
                    "radical": BuyMoneyAndCountSetting().get_radical_buy_setting(),
                    "moneys": constant.AVAILABLE_BUY_MONEYS,
                    "default_buy_money": constant.BUY_MONEY_PER_CODE
                }
                self.send_response({"code": 0, "data": data, "msg": f""},
                                   client_id,
                                   request_id)
            elif ctype == "set_radical_buy_block_count_setting":
                # 设置买入金额和数量
                data_str = data["data"]
                data_str = base64.b64decode(data_str).decode('utf-8')
                setting = json.loads(data_str)
                RadicalBuyBlockCodeCountManager().set_block_code_count(setting)
                self.send_response({"code": 0, "data": setting, "msg": f""},
                                   client_id,
                                   request_id)
            elif ctype == "get_radical_buy_block_count_setting":
                # 设置买入金额和数量
                data = RadicalBuyBlockCodeCountManager().get_block_code_count_settings()
                self.send_response({"code": 0, "data": data, "msg": f""},
                                   client_id,
                                   request_id)
        except Exception as e:
            logging.exception(e)
            logger_debug.exception(e)