| | |
| | | type_ = data_json['type'] |
| | | if type(type_) == int: |
| | | # 处理数字型TYPE |
| | | return_str = self.process_num_type(sk, type_, data_str) |
| | | return_str = self.process_num_type(sk, type_, data_str) |
| | | break |
| | | |
| | | is_sign_right = socket_util.is_client_params_sign_right(data_json) |
| | |
| | | price = prices[0][1] |
| | | # 下单 |
| | | result = hosting_api_util.trade_order(hosting_api_util.TRADE_DIRECTION_BUY, code, volume, |
| | | round(float(price), 2)) |
| | | round(float(price), 2)) |
| | | if result: |
| | | resultJSON = result |
| | | print("下单结果:", resultJSON) |
| | |
| | | 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, |
| | | orderSysID, True) |
| | | result = hosting_api_util.trade_cancel_order(hosting_api_util.TRADE_DIRECTION_BUY, code,accountId, |
| | | orderSysID, True) |
| | | print("---撤单结果----") |
| | | print(result) |
| | | if result["code"] == 0: |
| | |
| | | # 已现价的5档价卖 |
| | | price = prices[0][1] - 0.04 |
| | | |
| | | result = hosting_api_util.trade_order(hosting_api_util.TRADE_DIRECTION_SELL, code, volume, price) |
| | | result = hosting_api_util.trade_order(hosting_api_util.TRADE_DIRECTION_SELL, code, volume, |
| | | price) |
| | | if result["code"] == 0: |
| | | return_str = json.dumps({"code": 0, "msg": ""}) |
| | | else: |
| | |
| | | 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}, "msg": ""}) |
| | | {"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": ""}) |
| | | {"code": 0, "data": {}, "msg": ""}) |
| | | elif type_ == 'everyday_init': |
| | | # 每日初始化 |
| | | hosting_api_util.everyday_init() |
| | |
| | | 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() |
| | |
| | | elif type == 504: |
| | | # 获取交易目标代码模式 |
| | | result = hosting_api_util.get_trade_mode() |
| | | return_str =json.dumps(result) |
| | | return_str = json.dumps(result) |
| | | except Exception as e: |
| | | return_str = json.dumps({"code": 1, "msg": str(e)}) |
| | | return return_str |
| | |
| | | from db import mysql_data |
| | | from db.redis_manager import RedisUtils, RedisManager |
| | | from log import logger_debug |
| | | from utils import socket_util, kpl_api_util, hosting_api_util, kp_client_msg_manager, global_data_cache_util |
| | | from utils import socket_util, kpl_api_util, hosting_api_util, kp_client_msg_manager, global_data_cache_util, tool |
| | | from utils.juejin_util import JueJinHttpApi |
| | | |
| | | trade_data_request_queue = queue.Queue() |
| | |
| | | datas = data["data"] |
| | | print("l2_subscript_codes", data_json) |
| | | global_data_cache_util.huaxin_subscript_codes = datas |
| | | global_data_cache_util.huaxin_subscript_codes_update_time = tool.get_now_time_str() |
| | | finally: |
| | | sk.sendall(socket_util.load_header(json.dumps({"code": 0}).encode(encoding='utf-8'))) |
| | | elif data_json["type"] == "redis": |
| | |
| | | """ |
| | | 全局缓存 |
| | | """ |
| | | |
| | | huaxin_subscript_codes = [] |
| | | huaxin_subscript_codes = [] |
| | | huaxin_subscript_codes_update_time =None |
| | |
| | | API_TYPE_CODE_ATRRIBUTE = "code_attribute" # 代码属性 |
| | | API_TYPE_CODE_TRADE_STATE = "code_trade_state" # 代码交易状态 |
| | | API_TYPE_GET_ENV = "get_env" # 获取环境信息 |
| | | API_TYPE_SYNC_L1_TARGET_CODES = "sync_l1_subscript_codes" # 同步L1需要订阅的代码 |
| | | API_TYPE_SYSTEM_LOG = "system_log" # 系统日志 |
| | | |
| | | # 超时时间2s |
| | | TIMEOUT = 5.0 |
| | | |
| | |
| | | def export_l2_data(code, blocking=True): |
| | | request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE, |
| | | {"type": API_TYPE_EXPORT_L2, "code": code, |
| | | "sinfo": f"cb_{API_TYPE_CODE_LIST}_{round(time.time() * 1000)}"}) |
| | | "sinfo": f"cb_{API_TYPE_EXPORT_L2}_{round(time.time() * 1000)}"}) |
| | | return __read_response(client, request_id, blocking) |
| | | |
| | | |
| | |
| | | def everyday_init(blocking=True): |
| | | request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE, |
| | | {"type": API_TYPE_INIT, |
| | | "sinfo": f"cb_{API_TYPE_CODE_LIST}_{round(time.time() * 1000)}"}) |
| | | "sinfo": f"cb_{API_TYPE_INIT}_{round(time.time() * 1000)}"}) |
| | | return __read_response(client, request_id, blocking) |
| | | |
| | | |
| | |
| | | def refresh_trade_data(type, blocking=True): |
| | | request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE, |
| | | {"type": API_TYPE_REFRESH_TRADE_DATA, "ctype": type, |
| | | "sinfo": f"update_trade_data_{round(time.time() * 1000)}"}) |
| | | "sinfo": f"cb_{API_TYPE_REFRESH_TRADE_DATA}_{round(time.time() * 1000)}"}) |
| | | return __read_response(client, request_id, blocking) |
| | | |
| | | |
| | |
| | | def get_code_attribute(code, blocking=True): |
| | | request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE, |
| | | {"type": API_TYPE_CODE_ATRRIBUTE, "code": code, |
| | | "sinfo": f"update_trade_data_{round(time.time() * 1000)}"}) |
| | | "sinfo": f"cb_{API_TYPE_CODE_ATRRIBUTE}_{round(time.time() * 1000)}"}) |
| | | return __read_response(client, request_id, blocking) |
| | | |
| | | |
| | |
| | | def get_code_trade_state(code, blocking=True): |
| | | request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE, |
| | | {"type": API_TYPE_CODE_TRADE_STATE, "code": code, |
| | | "sinfo": f"update_trade_data_{round(time.time() * 1000)}"}) |
| | | "sinfo": f"{API_TYPE_CODE_TRADE_STATE}_{round(time.time() * 1000)}"}) |
| | | return __read_response(client, request_id, blocking) |
| | | |
| | | |
| | |
| | | def get_env_info(blocking=True): |
| | | request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE, |
| | | {"type": API_TYPE_GET_ENV, |
| | | "sinfo": f"update_trade_data_{round(time.time() * 1000)}"}) |
| | | "sinfo": f"cb_{API_TYPE_GET_ENV}_{round(time.time() * 1000)}"}) |
| | | return __read_response(client, request_id, blocking) |
| | | |
| | | |
| | | # 获取环境信息 |
| | | def sync_l1_subscript_codes(blocking=True): |
| | | request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE, |
| | | {"type": API_TYPE_SYNC_L1_TARGET_CODES, |
| | | "sinfo": f"cb_{API_TYPE_SYNC_L1_TARGET_CODES}_{round(time.time() * 1000)}"}) |
| | | return __read_response(client, request_id, blocking) |
| | | |
| | | |
| | | # 获取系统日志 |
| | | def get_system_logs(start_index, count, blocking=True): |
| | | request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE, |
| | | {"type": API_TYPE_SYSTEM_LOG, "start_index": start_index, "count": count, |
| | | "sinfo": f"cb_{API_TYPE_SYSTEM_LOG}_{round(time.time() * 1000)}"}) |
| | | return __read_response(client, request_id, blocking) |
| | | |
| | | |
| | |
| | | results = mysqldb.select_all( |
| | | f"select * from hx_trade_delegate_record r where {' and '.join(where_list)} order by createTime") |
| | | # 转dict |
| | | key_list = ["orderLocalID", "securityID", "securityName", "direction", "orderSysID", "insertTime", |
| | | key_list = ["id", "orderLocalID", "securityID", "securityName", "direction", "orderSysID", "insertTime", |
| | | "insertDate", "acceptTime", "cancelTime", "limitPrice", "turnover", "volume", "volumeTraded", |
| | | "orderStatus", "orderSubmitStatus", "statusMsg", "createTime", "updateTime", "accountID"] |
| | | fresults = [] |
| | |
| | | if results: |
| | | for r in results: |
| | | if not max_update_time: |
| | | max_update_time = r[17] |
| | | if r[17] > max_update_time: |
| | | max_update_time = r[17] |
| | | max_update_time = r[18] |
| | | if r[18] > max_update_time: |
| | | max_update_time = r[18] |
| | | |
| | | temp = {} |
| | | for i in range(len(r)): |