| | |
| | | this.userId = accountDetail.getUserId(); |
| | | log.info("[GateGrid] 用户ID: {}", userId); |
| | | |
| | | futuresApi.cancelPriceTriggeredOrderList(SETTLE, contract); |
| | | log.info("[GateGrid] 已取消所有既有止盈止损条件单"); |
| | | |
| | | futuresApi.updateContractPositionLeverageCall( |
| | | SETTLE, contract, leverage, marginMode, positionMode, null); |
| | | log.info("[GateGrid] 已设置杠杆: {}x, 保证金模式: {}", leverage, marginMode); |
| | |
| | | return; |
| | | } |
| | | |
| | | boolean hasPosition = size.compareTo(BigDecimal.ZERO) > 0; |
| | | boolean hasPosition = size.abs().compareTo(BigDecimal.ZERO) > 0; |
| | | |
| | | if ("dual_long".equals(mode)) { |
| | | if (longActive && !hasPosition) { |
| | |
| | | TriggerOrderResponse response = futuresApi.createPriceTriggeredOrder(SETTLE, order); |
| | | log.info("[GateGrid] 止盈条件单已创建, triggerPrice:{}, orderType:{}, autoSize:{}, id:{}", |
| | | triggerPrice, orderType, autoSize, response.getId()); |
| | | } catch (GateApiException e) { |
| | | if ("AUTO_USER_EXIST_POSITION_ORDER".equals(e.getErrorLabel())) { |
| | | log.warn("[GateGrid] 止盈条件单已存在,取消旧单后重试, label:{}", e.getErrorLabel()); |
| | | try { |
| | | futuresApi.cancelPriceTriggeredOrderList(SETTLE, contract); |
| | | TriggerOrderResponse response = futuresApi.createPriceTriggeredOrder(SETTLE, createPriceTriggeredOrderBean(triggerPrice, rule, orderType, autoSize)); |
| | | log.info("[GateGrid] 止盈条件单重试成功, triggerPrice:{}, orderType:{}, autoSize:{}, id:{}", |
| | | triggerPrice, orderType, autoSize, response.getId()); |
| | | } catch (Exception retryEx) { |
| | | log.error("[GateGrid] 止盈条件单重试失败, triggerPrice:{}, orderType:{}, autoSize:{}", |
| | | triggerPrice, orderType, autoSize, retryEx); |
| | | } |
| | | } else { |
| | | log.error("[GateGrid] 止盈条件单创建失败, triggerPrice:{}, orderType:{}, autoSize:{}", |
| | | triggerPrice, orderType, autoSize, e); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("[GateGrid] 止盈条件单创建失败, triggerPrice:{}, orderType:{}, autoSize:{}", |
| | | triggerPrice, orderType, autoSize, e); |
| | | } |
| | | } |
| | | |
| | | private FuturesPriceTriggeredOrder createPriceTriggeredOrderBean(BigDecimal triggerPrice, |
| | | FuturesPriceTrigger.RuleEnum rule, |
| | | String orderType, |
| | | String autoSize) { |
| | | FuturesPriceTrigger trigger = new FuturesPriceTrigger(); |
| | | trigger.setStrategyType(FuturesPriceTrigger.StrategyTypeEnum.NUMBER_0); |
| | | trigger.setPriceType(FuturesPriceTrigger.PriceTypeEnum.NUMBER_0); |
| | | trigger.setPrice(triggerPrice.toString()); |
| | | trigger.setRule(rule); |
| | | trigger.setExpiration(0); |
| | | |
| | | FuturesInitialOrder initial = new FuturesInitialOrder(); |
| | | initial.setContract(contract); |
| | | initial.setSize(0L); |
| | | initial.setPrice("0"); |
| | | initial.setTif(FuturesInitialOrder.TifEnum.IOC); |
| | | initial.setReduceOnly(true); |
| | | initial.setAutoSize(autoSize); |
| | | |
| | | FuturesPriceTriggeredOrder order = new FuturesPriceTriggeredOrder(); |
| | | order.setTrigger(trigger); |
| | | order.setInitial(initial); |
| | | order.setOrderType(orderType); |
| | | return order; |
| | | } |
| | | |
| | | /** |
| | | * 打印当前网格配置和入场信息。 |
| | | */ |