| | |
| | | from db import mysql_data, redis_manager |
| | | from db.redis_manager import RedisUtils |
| | | from log import logger_request_debug |
| | | 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 |
| | |
| | | raise Exception("现价获取失败") |
| | | price = prices[0][1] |
| | | # 下单 |
| | | result = hosting_api_util.trade_order(hosting_api_util.TRADE_DIRECTION_BUY, code, volume, |
| | | result = hosting_api_util.trade_order(hosting_api_util.TRADE_DIRECTION_BUY, code, |
| | | volume, |
| | | round(float(price), 2)) |
| | | if result: |
| | | resultJSON = result |
| | |
| | | |
| | | elif type_ == 'common': |
| | | # 验证签名 |
| | | if not is_sign_right: |
| | | raise Exception("签名错误") |
| | | # if not is_sign_right: |
| | | # raise Exception("签名错误") |
| | | params = data_json["data"] |
| | | result = hosting_api_util.common_request(params) |
| | | return_str = json.dumps(result) |
| | |
| | | if update_time is None: |
| | | update_time = '' |
| | | return_str = json.dumps( |
| | | {"code": 0, "data": {"count": len(fresults), "list": fresults, "update_time": update_time}, |
| | | {"code": 0, |
| | | "data": {"count": len(fresults), "list": fresults, "update_time": update_time}, |
| | | "msg": ""}) |
| | | pass |
| | | elif type_ == "export_l2_data": |
| | |
| | | params = data_json["data"] |
| | | result = hosting_api_util.common_request(params) |
| | | 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: |
| | | sk.recv(1024) |
| | | time.sleep(1) |
| | | except: |
| | | print("数据断开") |
| | | break |
| | | |
| | | |
| | | |
| | | finally: |
| | | log.request_info("middle_api_server", f"请求结束:{type_}") |
| | | break |