Administrator
2024-07-25 9d39b293bde97f31f522010373aad1dd3f654c07
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 撤卖单
import threading
import time
 
from log_module import async_log_util
from log_module.log import logger_trade
import concurrent.futures
 
from trade import huaxin_trade_api
from utils import huaxin_util, sell_util
 
__cancel_sell_thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=8)
 
 
def __cancel_sell_order(code, order_ref):
    time.sleep(2)
    try:
        result = huaxin_trade_api.cancel_order(2, code, None, orderRef=order_ref)
    except Exception as e:
        logger_trade.exception(e)
 
 
# 开始撤单
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)
    # 2S不成交就撤单
    threading.Thread(target=lambda: __cancel_sell_order(code, order_ref), daemon=True).start()
    return result