Administrator
2025-06-12 4e5eed2226fae6a057c454155565211dbc9349e9
卖改为异步
3个文件已修改
31 ■■■■■ 已修改文件
trade/huaxin_sell_util.py 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin_trade_api.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/trade_strategy.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin_sell_util.py
@@ -1,4 +1,5 @@
# 撤卖单
import threading
import time
from log_module import async_log_util
@@ -25,15 +26,23 @@
        logger_trade.exception(e)
__sell_lock = threading.RLock()
# 开始撤单
def start_sell(code, volume, price_type, limit_up_price, limit_down_price, current_price, blocking=False,
               request_id=None, order_ref=None):
    price = sell_util.get_sell_price(price_type, limit_up_price, limit_down_price, current_price)
    if not price:
        raise Exception("价格获取出错")
    async_log_util.info(logger_trade, f"API卖:  单价-{price}")
    if not order_ref:
        order_ref = huaxin_util.create_order_ref()
    result = huaxin_trade_api.order(2, code, volume, price, order_ref=order_ref,
                                    blocking=blocking, request_id=request_id)
    return result
    # 线程锁
    __sell_lock.acquire()
    try:
        price = sell_util.get_sell_price(price_type, limit_up_price, limit_down_price, current_price)
        if not price:
            raise Exception("价格获取出错")
        async_log_util.info(logger_trade, f"API卖:  单价-{price}")
        if not order_ref:
            order_ref = huaxin_util.create_order_ref()
        result = huaxin_trade_api.order(2, code, volume, price, order_ref=order_ref,
                                        blocking=blocking, request_id=request_id)
        return result
    finally:
        __sell_lock.release()
trade/huaxin_trade_api.py
@@ -446,7 +446,7 @@
        if blocking:
            return __read_response(request_id, blocking)
        else:
            return {"order_ref": order_ref}
            return {"code": 0, "data": {"orderRef": order_ref}}
    finally:
        # huaxin_trade_data_update.add_delegate_list("下单", delay=0.2)
        huaxin_trade_data_update.add_money_list()
trade/trade_strategy.py
@@ -97,7 +97,7 @@
                            # 表示全部卖完
                            volume = -1
                        result = huaxin_sell_util.start_sell(code, volume, price_type, limit_up_price, limit_down_price,
                                                             current_price, blocking=True, request_id=request_id,
                                                             current_price, blocking=False, request_id=request_id,
                                                             order_ref=order_ref)
                        async_log_util.info(logger_trade, f"API卖结果: {result}")
                        self.send_response(result, client_id, request_id)