From 95e18d831b6e1e3509e24e1fe3eed9f1d0b70f6d Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期四, 31 七月 2025 14:13:27 +0800 Subject: [PATCH] 添加推送日志 --- middle_api_server.py | 657 ++++++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 423 insertions(+), 234 deletions(-) diff --git a/middle_api_server.py b/middle_api_server.py index c0fc0b2..fd3799e 100644 --- a/middle_api_server.py +++ b/middle_api_server.py @@ -1,6 +1,7 @@ import hashlib import json import logging +import random import socket import socketserver import threading @@ -9,8 +10,13 @@ import constant import socket_manager import trade_manager +from code_attribute.code_price_manager import CodesLimitRateManager from db import mysql_data, redis_manager from db.redis_manager import RedisUtils +from log_module import log, request_log_util +from log_module.log import logger_request_debug +from middle_l1_data_server import L1DataManager +from output import push_msg_manager from utils import socket_util, hosting_api_util, huaxin_trade_record_manager, huaxin_util, tool, global_data_cache_util from utils.history_k_data_util import HistoryKDatasUtils, JueJinApi from utils.huaxin_trade_record_manager import PositionManager @@ -63,261 +69,401 @@ # print("鏀跺埌鏁版嵁------", f"{data_str[:20]}......{data_str[-20:]}") data_json = json.loads(data_str) type_ = data_json['type'] - if type(type_) == int: - # 澶勭悊鏁板瓧鍨婽YPE - return_str = self.process_num_type(sk, type_, data_str) - break + try: + request_log_util.request_info("middle_api_server", f"璇锋眰寮�濮嬶細{type_}") + if type(type_) == int: + # 澶勭悊鏁板瓧鍨婽YPE + return_str = self.process_num_type(sk, type_, data_str) + break - is_sign_right = socket_util.is_client_params_sign_right(data_json) - # ------瀹㈡埛绔姹傛帴鍙�------- - if type_ == 'buy': - # 楠岃瘉绛惧悕 - if not is_sign_right: - raise Exception("绛惧悕閿欒") - codes_data = data_json["data"] - code = codes_data["code"] - volume = codes_data["volume"] - price = codes_data["price"] - try: - if not code: - raise Exception("璇蜂笂浼燾ode") - if not volume: - raise Exception("璇蜂笂浼爒olume") + is_sign_right = socket_util.is_client_params_sign_right(data_json) + # ------瀹㈡埛绔姹傛帴鍙�------- + if type_ == 'buy': + # 楠岃瘉绛惧悕 + if not is_sign_right: + raise Exception("绛惧悕閿欒") + codes_data = data_json["data"] + code = codes_data["code"] + money = codes_data.get("money") + volume = codes_data.get("volume") + price = codes_data.get("price") + price_type = codes_data.get("price_type") + try: + if not code: + raise Exception("璇蜂笂浼燾ode") - if round(float(price), 2) <= 0: - prices = HistoryKDatasUtils.get_now_price([code]) - if not prices: - raise Exception("鐜颁环鑾峰彇澶辫触") - price = prices[0][1] - # 涓嬪崟 - result = hosting_api_util.trade_order(hosting_api_util.TRADE_DIRECTION_BUY, code, volume, - round(float(price), 2)) - if result: - resultJSON = result - print("涓嬪崟缁撴灉锛�", resultJSON) - if resultJSON['code'] == 0: + if not price or round(float(price), 2) <= 0: + if price_type is None: + price_type = 0 + # 榛樿涓虹瀛愪环 + pre_close = HistoryKDatasUtils.get_gp_latest_info([code], "sec_id,pre_close")[0][ + "pre_close"] + if price_type == 0: # 浠锋牸绗煎瓙 + # 鑾峰彇鐜颁环 + prices = HistoryKDatasUtils.get_now_price([code]) + if not prices: + raise Exception("鐜颁环鑾峰彇澶辫触") + now_price = prices[0][1] + limit_up_price = round( + float(tool.get_limit_up_price_by_preprice(code, pre_close)), + 2) + price = min(tool.get_buy_max_price(now_price), limit_up_price) + elif price_type == 1: # 璺屽仠浠� + limit_down_price = round( + float(tool.get_limit_down_price_by_preprice(code, pre_close)), + 2) + price = limit_down_price + elif price_type == 2: # 娑ㄥ仠浠� + limit_up_price = round( + float(tool.get_limit_up_price_by_preprice(code, pre_close)), + 2) + price = limit_up_price + elif price_type == 3: # 鐜颁环 + prices = HistoryKDatasUtils.get_now_price([code]) + if not prices: + raise Exception("鐜颁环鑾峰彇澶辫触") + now_price = prices[0][1] + price = now_price + elif price_type == 4: # 涔�5浠� + prices = HistoryKDatasUtils.get_now_price([code]) + if not prices: + raise Exception("鐜颁环鑾峰彇澶辫触") + now_price = prices[0][1] + price = now_price - 0.04 + if not volume and money: + volume = (money // int(round(float(price) * 100))) * 100 + if volume < 100: + volume = 100 + # 涓嬪崟 + result = hosting_api_util.trade_order(hosting_api_util.TRADE_DIRECTION_BUY, code, + volume, price) + if result: + resultJSON = result + print("涓嬪崟缁撴灉锛�", resultJSON) + if resultJSON['code'] == 0: + return_str = json.dumps({"code": 0}) + else: + raise Exception(resultJSON['msg']) + break + except Exception as e: + raise e + elif type_ == 'cancel_order': + # 楠岃瘉绛惧悕 + if not is_sign_right: + raise Exception("绛惧悕閿欒") + codes_data = data_json["data"] + code = codes_data["code"] + orderSysID = codes_data.get("orderSysID") + accountId = codes_data.get("accountId") + if code: + result = hosting_api_util.trade_cancel_order(hosting_api_util.TRADE_DIRECTION_BUY, code, + accountId, + orderSysID, True) + print("---鎾ゅ崟缁撴灉----") + print(result) + if result["code"] == 0: return_str = json.dumps({"code": 0}) else: - raise Exception(resultJSON['msg']) + raise Exception(result["msg"]) + else: + return_str = json.dumps({"code": 1, "msg": "璇蜂笂浼犱唬鐮�"}) break - except Exception as e: - raise e - elif type_ == 'cancel_order': - # 楠岃瘉绛惧悕 - if not is_sign_right: - raise Exception("绛惧悕閿欒") - codes_data = data_json["data"] - code = codes_data["code"] - orderSysID = codes_data.get("orderSysID") - accountId = codes_data.get("accountId") - if code: - result = hosting_api_util.trade_cancel_order(hosting_api_util.TRADE_DIRECTION_BUY, code, - accountId, - orderSysID, True) - print("---鎾ゅ崟缁撴灉----") - print(result) + + elif type_ == 'sell': + # 楠岃瘉绛惧悕 + if not is_sign_right: + raise Exception("绛惧悕閿欒") + codes_data = data_json["data"] + code = codes_data["code"] + volume = codes_data["volume"] + price_type = codes_data["price_type"] + result = hosting_api_util.trade_order(hosting_api_util.TRADE_DIRECTION_SELL, code, volume, + '', price_type=price_type) if result["code"] == 0: - return_str = json.dumps({"code": 0}) + return_str = json.dumps(result) else: raise Exception(result["msg"]) - else: - return_str = json.dumps({"code": 1, "msg": "璇蜂笂浼犱唬鐮�"}) - break - - elif type_ == 'sell': - # 楠岃瘉绛惧悕 - if not is_sign_right: - raise Exception("绛惧悕閿欒") - codes_data = data_json["data"] - code = codes_data["code"] - volume = codes_data["volume"] - price_type = codes_data["price_type"] - result = hosting_api_util.trade_order(hosting_api_util.TRADE_DIRECTION_SELL, code, volume, - '',price_type=price_type) - if result["code"] == 0: + print("---鍗栧嚭缁撴灉----") + print(result) + break + elif type_ == 'get_code_position_info': + # 楠岃瘉绛惧悕 + if not is_sign_right: + raise Exception("绛惧悕閿欒") + codes_data = data_json["data"] + code = codes_data["code"] + result = hosting_api_util.get_code_position_info(code) return_str = json.dumps(result) - else: - raise Exception(result["msg"]) - print("---鍗栧嚭缁撴灉----") - print(result) - break - elif type_ == 'get_code_position_info': - # 楠岃瘉绛惧悕 - if not is_sign_right: - raise Exception("绛惧悕閿欒") - codes_data = data_json["data"] - code = codes_data["code"] - result = hosting_api_util.get_code_position_info(code) - return_str = json.dumps(result) - break + break - elif type_ == 'common': - # 楠岃瘉绛惧悕 - if not is_sign_right: - raise Exception("绛惧悕閿欒") - params = data_json["data"] - result = hosting_api_util.common_request(params) - return_str = json.dumps(result) - break + elif type_ == 'common': + params = data_json["data"] + ctype = params.get("ctype") + trade_sell_types = {"get_current_l1_codes", "get_positions", "get_l2_deal_price", + "buy_cb_for_commission", "sell_cb_for_commission", "get_deal_queue", "auto_cancel_sell_mode", "auto_cancel_sell_mode", "get_sell_env"} + if ctype in trade_sell_types: + result = hosting_api_util.common_request(params, + client_type=socket_manager.ClientSocketManager.CLIENT_TYPE_TRADE_SELL) + else: + result = hosting_api_util.common_request(params) + return_str = json.dumps(result) + break - elif type_ == 'get_cost_price': - # 鑾峰彇鎴愭湰浠� - codes_data = data_json["data"] - code = codes_data["code"] - try: - price = PositionManager.get_cost_price(code) - return_str = json.dumps({"code": 0, "data": {"price": price}}) - except Exception as e: - return_str = json.dumps({"code": 1, "msg": str(e)}) - break - elif type_ == 'delegate_list': - # 濮旀墭鍒楄〃 - update_time = data_json["data"]["update_time"] - # 鏄惁鍙挙 0/1 - can_cancel = data_json["data"]["can_cancel"] - results, update_time = None, None - if can_cancel: - results, update_time = huaxin_trade_record_manager.DelegateRecordManager.list_by_day( - tool.get_now_date_str("%Y%m%d"), None, - [huaxin_util.TORA_TSTP_OST_Accepted, huaxin_util.TORA_TSTP_OST_PartTraded]) - else: - results, update_time = huaxin_trade_record_manager.DelegateRecordManager.list_by_day( - tool.get_now_date_str("%Y%m%d"), update_time) - return_str = json.dumps( - {"code": 0, "data": {"list": results, "updateTime": update_time}, "msg": "璇蜂笂浼犱唬鐮�"}) - break - elif type_ == 'deal_list': - # 鎴愪氦鍒楄〃 - results = huaxin_trade_record_manager.DealRecordManager.list_by_day( - tool.get_now_date_str("%Y%m%d")) - return_str = json.dumps( - {"code": 0, "data": {"list": results}, "msg": ""}) - elif type_ == 'position_list': - # 鎸佷粨鑲″垪琛� - results, update_time = huaxin_trade_record_manager.PositionManager.list_by_day( - tool.get_now_date_str("%Y%m%d")) - return_str = json.dumps( - {"code": 0, "data": {"list": results}, "msg": ""}) - elif type_ == 'money_list': - # 璧勯噾璇︽儏 - money_data = huaxin_trade_record_manager.MoneyManager.get_data() - return_str = json.dumps( - {"code": 0, "data": money_data, "msg": ""}) - elif type_ == 'sync_trade_data': - # 鍚屾浜ゆ槗鏁版嵁 - sync_type = data_json["data"]["type"] - hosting_api_util.refresh_trade_data(sync_type) - return_str = json.dumps( - {"code": 0, "data": {}, "msg": ""}) - elif type_ == "get_huaxin_subscript_codes": - # 鑾峰彇鍗庨懌璁㈤槄鐨勪唬鐮� - fresults = global_data_cache_util.huaxin_subscript_codes - update_time = global_data_cache_util.huaxin_subscript_codes_update_time - if update_time is None: - update_time = '' - return_str = json.dumps( - {"code": 0, "data": {"count": len(fresults), "list": fresults, "update_time": update_time}, - "msg": ""}) - pass - elif type_ == "export_l2_data": - # 瀵煎嚭L2鏁版嵁 - code = data_json["data"]["code"] - hosting_api_util.export_l2_data(code) - return_str = json.dumps( - {"code": 0, "data": {}, "msg": ""}) - elif type_ == 'everyday_init': - # 姣忔棩鍒濆鍖� - hosting_api_util.everyday_init() - return_str = json.dumps( - {"code": 0, "data": {}, "msg": ""}) - elif type_ == 'huaxin_channel_state': - # 鍗庨懌閫氶亾鐘舵�� - types = [] - fdata = {} - return_str = json.dumps( - {"code": 0, "data": fdata, "msg": ""}) - elif type_ == 'juejin_is_valid': - # 鎺橀噾鏄惁鍙敤 - try: - date = JueJinApi.get_previous_trading_date(tool.get_now_date_str()) - if date: + elif type_ == 'get_cost_price': + # 鑾峰彇鎴愭湰浠� + codes_data = data_json["data"] + code = codes_data["code"] + try: + price = PositionManager.get_cost_price(code) + return_str = json.dumps({"code": 0, "data": {"price": price}}) + except Exception as e: + return_str = json.dumps({"code": 1, "msg": str(e)}) + break + elif type_ == 'delegate_list': + # 濮旀墭鍒楄〃 + update_time = data_json["data"]["update_time"] + # 鏄惁鍙挙 0/1 + can_cancel = data_json["data"]["can_cancel"] + results, update_time = None, None + if can_cancel: + results, update_time = huaxin_trade_record_manager.DelegateRecordManager.list_by_day( + tool.get_now_date_str("%Y%m%d"), None, + [huaxin_util.TORA_TSTP_OST_Accepted, huaxin_util.TORA_TSTP_OST_PartTraded]) + else: + results, update_time = huaxin_trade_record_manager.DelegateRecordManager.list_by_day( + tool.get_now_date_str("%Y%m%d"), update_time) + return_str = json.dumps( + {"code": 0, "data": {"list": results, "updateTime": update_time}, "msg": "璇蜂笂浼犱唬鐮�"}) + break + elif type_ == 'deal_list': + # 鎴愪氦鍒楄〃 + results = huaxin_trade_record_manager.DealRecordManager.list_by_day( + tool.get_now_date_str("%Y%m%d")) + return_str = json.dumps( + {"code": 0, "data": {"list": results}, "msg": ""}) + elif type_ == 'position_list': + # 鎸佷粨鑲″垪琛� + results, update_time = huaxin_trade_record_manager.PositionManager.list_by_day( + tool.get_now_date_str("%Y%m%d")) + return_str = json.dumps( + {"code": 0, "data": {"list": results}, "msg": ""}) + elif type_ == 'money_list': + # 璧勯噾璇︽儏 + money_data = huaxin_trade_record_manager.MoneyManager.get_data() + return_str = json.dumps( + {"code": 0, "data": money_data, "msg": ""}) + elif type_ == 'sync_trade_data': + # 鍚屾浜ゆ槗鏁版嵁 + sync_type = data_json["data"]["type"] + hosting_api_util.refresh_trade_data(sync_type) + hosting_api_util.refresh_trade_data(sync_type, blocking=False, + client_type=socket_manager.ClientSocketManager.CLIENT_TYPE_TRADE_SELL) + return_str = json.dumps( + {"code": 0, "data": {}, "msg": ""}) + elif type_ == "get_huaxin_subscript_codes": + # 鑾峰彇鍗庨懌璁㈤槄鐨勪唬鐮� + fresults = global_data_cache_util.huaxin_subscript_codes + fdata = [] + try: + # 鑾峰彇褰撳墠娑ㄥ仠姣斾緥 + rate_results_dict = global_data_cache_util.huaxin_subscript_codes_rate + for r in fresults: + fdata.append( + (r[0], r[1], rate_results_dict.get(r[0]) if r[0] in rate_results_dict else 0, + r[2])) + fdata.sort(key=lambda r: r[2], reverse=True) + except: + fdata = fresults + update_time = global_data_cache_util.huaxin_subscript_codes_update_time + if update_time is None: + update_time = '' + return_str = json.dumps( + {"code": 0, + "data": {"count": len(fresults), "list": fdata, "update_time": update_time}, + "msg": ""}) + pass + elif type_ == "get_huaxin_position_subscript_codes": + # 鑾峰彇鍗庨懌璁㈤槄鐨勪唬鐮� + fresults = global_data_cache_util.huaxin_position_subscript_codes + update_time = global_data_cache_util.huaxin_position_subscript_codes_update_time + if update_time is None: + update_time = '' + return_str = json.dumps( + {"code": 0, + "data": {"count": len(fresults), "list": fresults, "update_time": update_time}, + "msg": ""}) + pass + elif type_ == "export_l2_data": + # 瀵煎嚭L2鏁版嵁 + code = data_json["data"]["code"] + hosting_api_util.export_l2_data(code) + return_str = json.dumps( + {"code": 0, "data": {}, "msg": ""}) + elif type_ == 'everyday_init': + # 姣忔棩鍒濆鍖� + hosting_api_util.everyday_init() + return_str = json.dumps( + {"code": 0, "data": {}, "msg": ""}) + elif type_ == 'huaxin_channel_state': + # 鍗庨懌閫氶亾鐘舵�� + types = [] + fdata = {} + return_str = json.dumps( + {"code": 0, "data": fdata, "msg": ""}) + elif type_ == 'juejin_is_valid': + # 鎺橀噾鏄惁鍙敤 + try: + date = JueJinApi.get_previous_trading_date(tool.get_now_date_str()) + if date: + return_str = json.dumps( + {"code": 0, "msg": ""}) + except Exception as e: return_str = json.dumps( - {"code": 0, "msg": ""}) - except Exception as e: - return_str = json.dumps( - {"code": 0, "msg": str(e)}) - elif type_ == 'get_env_info': - # 鑾峰彇鐜淇℃伅 - result = hosting_api_util.get_env_info() - return_str = json.dumps(result) - elif type_ == 'sync_l1_subscript_codes': - # 鑾峰彇鐜淇℃伅 - result = hosting_api_util.sync_l1_subscript_codes() - return_str = json.dumps(result) + {"code": 0, "msg": str(e)}) + elif type_ == 'get_env_info': + # 鑾峰彇鐜淇℃伅 + result = hosting_api_util.get_env_info() + return_str = json.dumps(result) + elif type_ == 'sync_l1_subscript_codes': + # 鑾峰彇鐜淇℃伅 + result = hosting_api_util.sync_l1_subscript_codes() + return_str = json.dumps(result) - elif type_ == 'get_system_logs': - # 鑾峰彇鐜淇℃伅 - start_index = data_json["data"]["start_index"] - count = data_json["data"]["count"] - result = hosting_api_util.get_system_logs(start_index, count) - return_str = json.dumps(result) - elif type_ == 'test_redis': - redis = redis_manager.RedisManager(5).getRedisNoPool() - try: - _start_time = time.time() - times = [] - for i in range(0, 100): - RedisUtils.sadd(redis, "test_set", f"000000:{i}", auto_free=False) - times.append(time.time() - _start_time) - _start_time = time.time() - for i in range(0, 20): - RedisUtils.smembers(redis, "test_set", auto_free=False) - times.append(time.time() - _start_time) - return_str = json.dumps( - {"code": 0, "data": times, "msg": ""}) - finally: - redis.close() - elif type_ == 'get_code_trade_info': - # 鑾峰彇鐜淇℃伅 - code = data_json["data"]["code"] - result = hosting_api_util.get_code_trade_info(code) - return_str = json.dumps(result) - elif type_ == 'get_l2_listen_active_count': - result = hosting_api_util.get_l2_listen_active_count() - return_str = json.dumps(result) - elif type_ == "trade_server_channels": - channels = socket_manager.ClientSocketManager.list_client() - return_str = json.dumps({"code": 0, "data": channels}) - elif type_ == "save_running_data": - result = hosting_api_util.save_running_data() - return_str = json.dumps(result) - elif type_ == "add_sell_rule": - result = hosting_api_util.sell_rule(hosting_api_util.OPERRATE_ADD, data=data_json["data"]) - return_str = json.dumps(result) - elif type_ == "del_sell_rule": - id_ = data_json["data"]["id"] - result = hosting_api_util.sell_rule(hosting_api_util.OPERRATE_DELETE, data={"id": id_}) - return_str = json.dumps(result) - elif type_ == "list_sell_rule": - result = hosting_api_util.sell_rule(hosting_api_util.OPERRATE_GET, data={}) - return_str = json.dumps(result) - elif type_ == "get_code_position_info": - code = data_json["data"]["code"] - result = hosting_api_util.get_code_position_info(code) - return_str = json.dumps(result) - elif type_ == "common": - params = data_json["data"] - result = hosting_api_util.common_request(params) - return_str = json.dumps(result) - + elif type_ == 'get_system_logs': + # 鑾峰彇鐜淇℃伅 + start_index = data_json["data"]["start_index"] + count = data_json["data"]["count"] + result = hosting_api_util.get_system_logs(start_index, count) + return_str = json.dumps(result) + elif type_ == 'test_redis': + redis = redis_manager.RedisManager(5).getRedisNoPool() + try: + _start_time = time.time() + times = [] + for i in range(0, 100): + RedisUtils.sadd(redis, "test_set", f"000000:{i}", auto_free=False) + times.append(time.time() - _start_time) + _start_time = time.time() + for i in range(0, 20): + RedisUtils.smembers(redis, "test_set", auto_free=False) + times.append(time.time() - _start_time) + return_str = json.dumps( + {"code": 0, "data": times, "msg": ""}) + finally: + redis.close() + elif type_ == 'get_code_trade_info': + # 鑾峰彇鐜淇℃伅 + code = data_json["data"]["code"] + result = hosting_api_util.get_code_trade_info(code) + return_str = json.dumps(result) + elif type_ == 'get_l2_listen_active_count': + result = hosting_api_util.get_l2_listen_active_count() + return_str = json.dumps(result) + elif type_ == "trade_server_channels": + trade_channels = socket_manager.ClientSocketManager.list_client( + socket_manager.ClientSocketManager.CLIENT_TYPE_TRADE_SELL) + common_channels = socket_manager.ClientSocketManager.list_client( + socket_manager.ClientSocketManager.CLIENT_TYPE_COMMON) + data = {} + available_count = 0 + active_count = 0 + now_time_str = tool.get_now_time_str() + for t in trade_channels: + if not t[1]: + available_count += 1 + if tool.trade_time_sub(now_time_str, t[2]) < 60: + active_count += 1 + data["trade"] = (len(trade_channels), available_count, active_count) + available_count = 0 + active_count = 0 + for t in common_channels: + if not t[1]: + available_count += 1 + if tool.trade_time_sub(now_time_str, t[2]) < 60: + active_count += 1 + data["common"] = (len(common_channels), available_count, active_count) + return_str = json.dumps({"code": 0, "data": data}) + elif type_ == "save_running_data": + result = hosting_api_util.save_running_data() + return_str = json.dumps(result) + elif type_ == "add_sell_rule": + result = hosting_api_util.sell_rule(hosting_api_util.OPERRATE_ADD, data=data_json["data"]) + return_str = json.dumps(result) + elif type_ == "update_sell_rule": + result = hosting_api_util.sell_rule(hosting_api_util.OPERRATE_SET, data=data_json["data"]) + return_str = json.dumps(result) + elif type_ == "del_sell_rule": + id_ = data_json["data"]["id"] + result = hosting_api_util.sell_rule(hosting_api_util.OPERRATE_DELETE, data={"id": id_}) + return_str = json.dumps(result) + elif type_ == "list_sell_rule": + result = hosting_api_util.sell_rule(hosting_api_util.OPERRATE_GET, data={}) + return_str = json.dumps(result) + elif type_ == "get_code_position_info": + code = data_json["data"]["code"] + result = hosting_api_util.get_code_position_info(code) + return_str = json.dumps(result) + elif type_ == "register_msg_receiver": + params = data_json["data"] + msg_types = params["types"] + try: + push_msg_manager.SocketManager.regirster_socket(sk, msg_types) + result = {"code": 0} + except Exception as e: + result = {"code": 1, "msg": str(e)} + return_str = json.dumps(result) + sk.sendall(socket_util.load_header(return_str.encode(encoding='utf-8'))) + while True: + try: + buf = sk.recv(1024) + print(f"鏀跺埌鏁版嵁锛歿buf.decode(encoding='utf-8')}") + time.sleep(1) + except: + print("鏁版嵁鏂紑") + break + elif type_ == "get_latest_cancel_orders": + # 鑾峰彇鏈�杩戠殑鎾ゅ崟 + results = huaxin_trade_record_manager.DelegateRecordManager.list_latest_cancel_records(10) + fresults = [] + for result in results: + temp = {} + for key in result: + if key in ["securityID", "securityName", "direction", "orderSysID", "acceptTime", + "cancelTime", "limitPrice", "volume"]: + temp[key] = result[key] + # 杩囨护铏氭嫙鍗曚笌鍗栧崟 + if int(temp["volume"] <= 100): + continue + if int(temp["direction"] != 0): + continue + fresults.append(temp) + return_str = json.dumps(json.dumps({"code": 0, "data": fresults})) + elif type_ == "get_buy1_info": + code = data_json["data"]["code"] + result = hosting_api_util.common_request({"ctype": "get_buy1_info", "code": code}, + client_type=socket_manager.ClientSocketManager.CLIENT_TYPE_TRADE_SELL) + return_str = json.dumps(result) + elif type_ == "get_l1_data": + results = L1DataManager().get_current_l1_data() + return_str = json.dumps({"code": 0, "data": results}) + elif type_ == "set_l1_codes": + codes = data_json["data"]["codes"] + # 灏嗕唬鐮佹殏瀛樺埌鏈湴 + # 璁剧疆L1浠g爜 + L1DataManager().save_target_codes(codes) + return_str = json.dumps({"code": 0, "data": {}}) + finally: + request_log_util.request_info("middle_api_server", f"璇锋眰缁撴潫锛歿type_}-{len(return_str.encode(encoding='utf-8'))}") break # sk.close() except Exception as e: logging.exception(e) + logger_request_debug.exception(e) return_str = json.dumps({"code": 401, "msg": str(e)}) break finally: sk.sendall(socket_util.load_header(return_str.encode(encoding='utf-8'))) + sk.close() @classmethod def process_num_type(cls, sk, type, _str): @@ -420,6 +566,49 @@ else: return_str = json.dumps({"code": 1, "msg": "涓嶅彲浠ュ彇娑�"}) + elif type == 421: + # 鍔犵孩 + data = json.loads(_str) + codes = data["data"]["codes"] + for code in codes: + hosting_api_util.add_code_list(code, hosting_api_util.CODE_LIST_MUST_BUY) + return_str = json.dumps({"code": 0}) + + elif type == 422: + # 绉荤孩 + data = json.loads(_str) + codes = data["data"]["codes"] + for code in codes: + hosting_api_util.remove_code_list(code, hosting_api_util.CODE_LIST_MUST_BUY) + return_str = json.dumps({"code": 0}) + + elif type == 423: + # 绾㈠崟鍒楄〃 + result = hosting_api_util.get_code_list(hosting_api_util.CODE_LIST_MUST_BUY) + return_str = json.dumps(result) + + elif type == 441: + # 鍔犵豢 + data = json.loads(_str) + codes = data["data"]["codes"] + for code in codes: + hosting_api_util.add_code_list(code, hosting_api_util.CODE_LIST_GREEN) + return_str = json.dumps({"code": 0}) + + elif type == 442: + # 绉荤豢 + data = json.loads(_str) + codes = data["data"]["codes"] + for code in codes: + hosting_api_util.remove_code_list(code, hosting_api_util.CODE_LIST_GREEN) + return_str = json.dumps({"code": 0}) + + elif type == 443: + # 缁垮崟鍒楄〃 + result = hosting_api_util.get_code_list(hosting_api_util.CODE_LIST_GREEN) + return_str = json.dumps(result) + + elif type == 430: # 鏌ヨ浠g爜灞炴�� data = json.loads(_str) -- Gitblit v1.8.0