| | |
| | | /** |
| | | * 平仓 |
| | | */ |
| | | List<ContractOrder> list = this.contractOrderService.findSubmitted(applyOrder.getPartyId().toString(), |
| | | applyOrder.getSymbol(), applyOrder.getDirection()); |
| | | if (list.size() == 0) { |
| | | List<ContractOrder> list = this.contractOrderService.findSubmitted( |
| | | applyOrder.getPartyId().toString(), applyOrder.getSymbol(), applyOrder.getDirection()); |
| | | |
| | | if (list == null || list.isEmpty()) { |
| | | applyOrder.setVolume(0D); |
| | | applyOrder.setState(ContractApplyOrder.STATE_CREATED); |
| | | this.contractApplyOrderService.update(applyOrder); |
| | | } |
| | | for (int i = 0; i < list.size(); i++) { |
| | | ContractOrder order = list.get(i); |
| | | boolean lock_order = false; |
| | | try { |
| | | if (!ContractLock.add(order.getOrder_no())) { |
| | | continue; |
| | | } |
| | | lock_order = true; |
| | | applyOrder = this.contractOrderService.saveClose(applyOrder, realtime, order.getOrder_no()); |
| | | |
| | | if (ContractApplyOrder.STATE_CREATED.equals(applyOrder.getState())) { |
| | | break; |
| | | } |
| | | } catch (Exception e) { |
| | | logger.error("error:", e); |
| | | } finally { |
| | | if (lock_order) { |
| | | ThreadUtils.sleep(100); |
| | | ContractLock.remove(order.getOrder_no()); |
| | | } else { |
| | | for (ContractOrder order : list) { |
| | | synchronized (this){ |
| | | try { |
| | | if (!ContractLock.add(order.getOrder_no())) { |
| | | continue; |
| | | } |
| | | applyOrder = this.contractOrderService.saveClose(applyOrder, realtime, order.getOrder_no()); |
| | | if (ContractApplyOrder.STATE_CREATED.equals(applyOrder.getState())) { |
| | | break; |
| | | } |
| | | } catch (Exception e) { |
| | | logger.error("Error processing order. Apply order: " + applyOrder.getOrder_no() + ", Contract order: " + order.getOrder_no(), e); |
| | | } finally { |
| | | ContractLock.remove(order.getOrder_no()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | logger.error("error:", e); |
| | | } finally { |