| | |
| | | # 撤卖单 |
| | | import threading |
| | | import time |
| | | |
| | | from log_module import async_log_util |
| | |
| | | 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() |
| | |
| | | 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() |
| | |
| | | # 表示全部卖完 |
| | | 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) |