admin
2024-01-08 1110af9cc42cbf6a3ebbb953f18585cb37ba5b8c
utils/hosting_api_util.py
@@ -23,7 +23,7 @@
CODE_LIST_BLACK = "black"
CODE_LIST_WANT = "want"
CODE_LIST_PAUSE_BUY = "pause_buy"
CODE_LIST_MUST_BUY = "must_buy"
# 类型
API_TYPE_TRADE = "trade"  # 交易
API_TYPE_TRADE_STATE = "trade_state"  # 交易状态
@@ -156,7 +156,7 @@
# 设置交易状态
def set_trade_state(state, blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"type": API_TYPE_TRADE_STATE, "operate": OPERRATE_SET,
                                    "state": state,
                                    "sinfo": f"cb_{API_TYPE_TRADE_STATE}_{round(time.time() * 1000)}"})
@@ -165,7 +165,7 @@
# 获取交易状态
def get_trade_state(blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"type": API_TYPE_TRADE_STATE, "operate": OPERRATE_GET,
                                    "sinfo": f"cb_{API_TYPE_TRADE_STATE}_{round(time.time() * 1000)}"})
    return __read_response(client, request_id, blocking)
@@ -173,7 +173,7 @@
# 设置交易模式
def set_trade_mode(mode, blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"type": API_TYPE_TRADE_MODE, "operate": OPERRATE_SET, "mode": mode,
                                    "sinfo": f"cb_{API_TYPE_TRADE_MODE}_{round(time.time() * 1000)}"})
    return __read_response(client, request_id, blocking)
@@ -181,7 +181,7 @@
# 获取交易模式
def get_trade_mode(blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"type": API_TYPE_TRADE_MODE, "operate": OPERRATE_GET,
                                    "sinfo": f"cb_{API_TYPE_TRADE_MODE}_{round(time.time() * 1000)}"})
    return __read_response(client, request_id, blocking)
@@ -189,7 +189,7 @@
# -----代码名单操作----
def add_code_list(code, code_list_type, blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"type": API_TYPE_CODE_LIST, "code_list_type": code_list_type, "code": code,
                                    "operate": OPERRATE_SET,
                                    "sinfo": f"cb_{API_TYPE_CODE_LIST}_{round(time.time() * 1000)}"})
@@ -197,7 +197,7 @@
def remove_code_list(code, code_list_type, blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"type": API_TYPE_CODE_LIST, "code_list_type": code_list_type, "code": code,
                                    "operate": OPERRATE_DELETE,
                                    "sinfo": f"cb_{API_TYPE_CODE_LIST}_{round(time.time() * 1000)}"})
@@ -205,7 +205,7 @@
def get_code_list(code_list_type, blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"type": API_TYPE_CODE_LIST, "code_list_type": code_list_type,
                                    "operate": OPERRATE_GET,
                                    "sinfo": f"cb_{API_TYPE_CODE_LIST}_{round(time.time() * 1000)}"})
@@ -214,7 +214,7 @@
# -----导出L2数据----
def export_l2_data(code, blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"type": API_TYPE_EXPORT_L2, "code": code,
                                    "sinfo": f"cb_{API_TYPE_EXPORT_L2}_{round(time.time() * 1000)}"})
    return __read_response(client, request_id, blocking)
@@ -222,7 +222,7 @@
# -----每日初始化----
def everyday_init(blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"type": API_TYPE_INIT,
                                    "sinfo": f"cb_{API_TYPE_INIT}_{round(time.time() * 1000)}"})
    return __read_response(client, request_id, blocking)
@@ -230,7 +230,7 @@
#  刷新交易数据
def refresh_trade_data(type, blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"type": API_TYPE_REFRESH_TRADE_DATA, "ctype": type,
                                    "sinfo": f"cb_{API_TYPE_REFRESH_TRADE_DATA}_{round(time.time() * 1000)}"})
    return __read_response(client, request_id, blocking)
@@ -238,7 +238,7 @@
#  获取代码属性
def get_code_attribute(code, blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"type": API_TYPE_CODE_ATRRIBUTE, "code": code,
                                    "sinfo": f"cb_{API_TYPE_CODE_ATRRIBUTE}_{round(time.time() * 1000)}"})
    return __read_response(client, request_id, blocking)
@@ -246,7 +246,7 @@
#  获取代码交易状态
def get_code_trade_state(code, blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"type": API_TYPE_CODE_TRADE_STATE, "code": code,
                                    "sinfo": f"{API_TYPE_CODE_TRADE_STATE}_{round(time.time() * 1000)}"})
    return __read_response(client, request_id, blocking)
@@ -254,7 +254,7 @@
# 获取环境信息
def get_env_info(blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"type": API_TYPE_GET_ENV,
                                    "sinfo": f"cb_{API_TYPE_GET_ENV}_{round(time.time() * 1000)}"})
    return __read_response(client, request_id, blocking)
@@ -262,7 +262,7 @@
# 获取环境信息
def sync_l1_subscript_codes(blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"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)
@@ -270,7 +270,7 @@
# 获取系统日志
def get_system_logs(start_index, count, blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"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)
@@ -278,7 +278,7 @@
# 拉取data_server的内容
def get_from_data_server(path, params, blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"type": API_TYPE_GET_FROM_DATA_SERVER, "path": path, "params": params,
                                    "sinfo": f"cb_{API_TYPE_GET_FROM_DATA_SERVER}_{round(time.time() * 1000)}"})
    return __read_response(client, request_id, blocking, timeout=30)
@@ -286,7 +286,7 @@
# 获取代码的交易信息
def get_code_trade_info(code, blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"type": API_TYPE_CODE_TRADE_INFO, "code": code,
                                    "sinfo": f"cb_{API_TYPE_CODE_TRADE_INFO}_{round(time.time() * 1000)}"})
    return __read_response(client, request_id, blocking, timeout=30)
@@ -294,7 +294,7 @@
# L2有效监听数量
def get_l2_listen_active_count(blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"type": API_TYPE_CODE_L2_LISTEN_ACTIVE_COUNT,
                                    "sinfo": f"cb_{API_TYPE_CODE_L2_LISTEN_ACTIVE_COUNT}_{round(time.time() * 1000)}"})
    return __read_response(client, request_id, blocking, timeout=30)
@@ -302,7 +302,7 @@
# 保存正在运行的数据
def save_running_data(blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"type": API_TYPE_SAVE_RUNNING_DATA,
                                    "sinfo": f"cb_{API_TYPE_SAVE_RUNNING_DATA}_{round(time.time() * 1000)}"})
    return __read_response(client, request_id, blocking, timeout=30)
@@ -310,10 +310,10 @@
# 保存正在运行的数据
def sell_rule(operate, data={}, blocking=True):
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON,
                                   {"type": API_TYPE_SELL_RULE, "operate": operate, "data": data,
                                    "sinfo": f"cb_{API_TYPE_SELL_RULE}_{round(time.time() * 1000)}"})
    return __read_response(client, request_id, blocking, timeout=30)
    return __read_response(client, request_id, blocking, timeout=10)
# 获取代码持仓信息
@@ -321,7 +321,7 @@
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
                                   {"type": API_TYPE_GET_CODE_POSITION_INFO, "code": code,
                                    "sinfo": f"cb_{API_TYPE_GET_CODE_POSITION_INFO}_{round(time.time() * 1000)}"})
    return __read_response(client, request_id, blocking, timeout=30)
    return __read_response(client, request_id, blocking)
def common_request(params={}, blocking=True):
@@ -330,8 +330,8 @@
    if params:
        for k in params:
            data[k] = params[k]
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE, data)
    return __read_response(client, request_id, blocking, timeout=30)
    request_id, client = __request(ClientSocketManager.CLIENT_TYPE_COMMON, data)
    return __read_response(client, request_id, blocking, timeout=10)
if __name__ == "__main__":