Administrator
2023-08-25 0dd67c24540b3e638a2da4832a973cf904d48dbd
trade/trade_huaxin.py
@@ -6,7 +6,8 @@
import time
import constant
from log_module.log import logger_juejin_trade, hx_logger_trade_debug
from log_module import async_log_util
from log_module.log import logger_juejin_trade, hx_logger_trade_debug, logger_trade
from trade.huaxin import huaxin_trade_api
from trade.huaxin.huaxin_trade_record_manager import TradeOrderIdManager
from utils import tool, huaxin_util
@@ -45,11 +46,11 @@
    try:
        result = huaxin_trade_api.order(1, code, count, price, blocking=blocking)
        print("华鑫下单耗时", time.time() - start_time)
        hx_logger_trade_debug.info(f"{code}:下单耗时{round(time.time() - start_time, 3)}s")
        async_log_util.info(hx_logger_trade_debug, f"{code}:下单耗时{round(time.time() - start_time, 3)}s")
    except Exception as e:
        if str(e).find("超时") >= 0:
            # 此处出现超时,需要通过读取委托列表来设置订单信息
            hx_logger_trade_debug.error(f"{code}:下单结果反馈出错-{str(e)}")
            async_log_util.error(hx_logger_trade_debug, f"{code}:下单结果反馈出错-{str(e)}")
        else:
            raise e
@@ -59,18 +60,18 @@
            if result['code'] == 0:
                result = result["data"]
                if result["orderStatus"] == huaxin_util.TORA_TSTP_OST_Rejected:
                    logger_juejin_trade.info(f"{code}:下单失败:{result.get('statusMsg')}")
                    async_log_util.info(hx_logger_trade_debug, f"{code}:下单失败:{result.get('statusMsg')}")
                    raise Exception(result.get('statusMsg'))
                else:
                    __TradeOrderIdManager.add_order_id(code, result["accountID"], result["orderSysID"])
                    logger_juejin_trade.info(f"{code}:下单成功 orderSysID:{result['orderSysID']}")
                    async_log_util.info(hx_logger_trade_debug, f"{code}:下单成功 orderSysID:{result['orderSysID']}")
                    return result["securityId"], result["accountID"], result["orderSysID"]
            else:
                raise Exception(result['msg'])
        else:
            local_order_id = result["local_order_id"]
            __TradeOrderIdManager.add_local_order_id(code, local_order_id)
            logger_juejin_trade.info(f"{code}:下单成功 localOrderId:{local_order_id}")
            async_log_util.info(hx_logger_trade_debug, f"{code}:下单成功 localOrderId:{local_order_id}")
            return code, "local", local_order_id
    else:
        raise Exception("下单失败,无返回")
@@ -94,11 +95,11 @@
            order_info = json.loads(order)
            orders.append({'orderSysID': order_info[1], 'accountId': order_info[0]})
        if orders:
            logger_juejin_trade.info(f"{code}:开始执行撤单")
            logger_juejin_trade.info(f"{code}:撤单成功,撤单数量:{len(orders)}")
            async_log_util.info(logger_trade, f"{code}:华鑫开始执行撤单")
            for order in orders:
                huaxin_trade_api.cancel_order(1, code, order["orderSysID"])
                __TradeOrderIdManager.remove_order_id(code, order["accountId"], order["orderSysID"])
            async_log_util.info(logger_trade, f"{code}:华鑫撤单结束,撤单数量:{len(orders)}")
        # 查询是否有本地订单号
    local_orders_info = __TradeOrderIdManager.list_local_order_ids_cache(code)
@@ -106,10 +107,11 @@
    if local_orders_info:
        local_orders_info = copy.deepcopy(local_orders_info)
        for order_id in local_orders_info:
            logger_juejin_trade.info(f"{code}:开始执行撤单")
            async_log_util.info(logger_trade, f"{code}:华鑫开始执行撤单")
            huaxin_trade_api.cancel_order(1, code, '', localOrderID=order_id)
            __TradeOrderIdManager.remove_local_order_id(code, order_id)
            logger_juejin_trade.info(f"{code}:执行撤单结束")
            async_log_util.info(logger_trade, f"{code}:华鑫执行撤单结束")
if __name__ == "__main__":
    pass