Esempio n. 1
0
  @Override
  protected synchronized void doConnect() {
    super.doConnect();
    if (isConnected()) {
      logger.info("Requesting account updates for {}", ACCOUNT_CODE.get());
      socket.reqAccountUpdates(true, ACCOUNT_CODE.get());
      socket.reqOpenOrders();
      try {
        while (accountCode == null) {
          wait();
        }
      } catch (InterruptedException e) {
        throw new JTradeException(e);
      }
      commission = new Commission(0.0, 0.0, 0.0, 0.0, 0.0);

      if (!ACCOUNT_CODE.get().equals(accountCode)) {
        logger.info(
            "Account code does not match specified account {} <> {}, exiting.",
            accountCode,
            ACCOUNT_CODE.get());
        disconnect();
      } else if (!accountCode.startsWith("D")) {
        if (!REAL_MONEY_ACCOUNT.get()) {
          logger.info(
              "Connected to real money account {} without #REAL_MONEY_ACCOUNT set to true, exiting.",
              accountCode);
          disconnect();
        }
        logger.info("Connected to real money account {} (Manage risk accordingly!)", accountCode);
      } else {
        logger.info("Connected to paper money account {}", accountCode);
      }
    }
  }
Esempio n. 2
0
  @Override
  public void error(int reqId, int errorCode, String errorMsg) {
    try {
      Object req = openOrdersById.get(reqId);
      if (req == null) {
        super.error(reqId, errorCode, errorMsg);
        return;
      }
      OpenOrder openOrder = (OpenOrder) req;

      String message = errorCode + ": " + errorMsg;
      lastMessage = message;

      switch (errorCode) {
        case 161:
          // 161: Cancel attempted when order is not in a cancellable
          // state
          logger.warn("Received error for {}: {}", openOrder, message);
          break;
        case 202:
          // 202: Order Cancelled
          break;
        case 110:
          // 110: price does not conform to the minimum price variation
          // for this
          // contract
        default:
          openOrder.setFailed();
          openOrdersById.remove(reqId);
          logger.warn("Received error for {}: {}", openOrder, message);
      }
    } catch (Throwable t) {
      // Do not allow exceptions come back to the socket -- it will cause
      // disconnects
      logger.error(t.getMessage(), t);
    }
  }
Esempio n. 3
0
 @Override
 public synchronized void removeAllListeners() {
   super.removeAllListeners();
   orderListeners.clear();
 }