Пример #1
0
  @Override
  @Transient
  public Collection<SpecificOrder> getPendingOrders(Market market, Portfolio portfolio) {
    com.xeiam.xchange.Exchange exchange = XchangeUtil.getExchangeForMarket(market.getExchange());
    PollingTradeService tradeService = exchange.getPollingTradeService();
    Collection<SpecificOrder> pendingOrders = new ConcurrentLinkedQueue<SpecificOrder>();
    SpecificOrder specificOrder;
    try {
      OpenOrders openOrders = tradeService.getOpenOrders();
      for (LimitOrder xchangeOrder : openOrders.getOpenOrders()) {
        for (org.cryptocoinpartners.schema.Order cointraderOrder : orderStateMap.keySet()) {
          if (cointraderOrder instanceof SpecificOrder) {
            specificOrder = (SpecificOrder) cointraderOrder;
            if (xchangeOrder.getId().equals(specificOrder.getRemoteKey())
                && specificOrder.getMarket().equals(market)) {
              specificOrder.update(xchangeOrder);
              updateOrderState(specificOrder, OrderState.PLACED, false);
              pendingOrders.add(specificOrder);
              break;
            } else {
              Date time =
                  (xchangeOrder.getTimestamp() != null) ? xchangeOrder.getTimestamp() : new Date();
              specificOrder = new SpecificOrder(xchangeOrder, exchange, portfolio, time);
              updateOrderState(specificOrder, OrderState.PLACED, false);
              pendingOrders.add(specificOrder);
              break;
            }
          }
        }
        Date time =
            (xchangeOrder.getTimestamp() != null) ? xchangeOrder.getTimestamp() : new Date();

        specificOrder = new SpecificOrder(xchangeOrder, exchange, portfolio, time);
        updateOrderState(specificOrder, OrderState.PLACED, false);
        pendingOrders.add(specificOrder);

        log.debug("completed itteration of orders");
      }

    } catch (IOException e) {
      log.error("Threw a Execption, full stack trace follows:", e);

      e.printStackTrace();
    }
    return pendingOrders;
  }
Пример #2
0
  @Override
  protected void handleSpecificOrder(SpecificOrder specificOrder) {
    Exchange exchange = XchangeUtil.getExchangeForMarket(specificOrder.getMarket().getExchange());
    PollingTradeService tradeService = exchange.getPollingTradeService();
    if (specificOrder.getLimitPrice() != null && specificOrder.getStopPrice() != null)
      reject(specificOrder, "Stop-limit orders are not supported");
    Order.OrderType orderType = specificOrder.isBid() ? Order.OrderType.BID : Order.OrderType.ASK;
    BigDecimal tradeableVolume = specificOrder.getVolume().abs().asBigDecimal();
    CurrencyPair currencyPair =
        XchangeUtil.getCurrencyPairForListing(specificOrder.getMarket().getListing());
    String id = specificOrder.getId().toString();
    Date timestamp = specificOrder.getTime().toDate();
    if (specificOrder.getLimitPrice() != null) {
      LimitOrder limitOrder =
          new LimitOrder(
              orderType,
              tradeableVolume,
              currencyPair,
              "",
              null,
              specificOrder.getLimitPrice().asBigDecimal());
      // todo put on a queue
      try {
        specificOrder.setRemoteKey(tradeService.placeLimitOrder(limitOrder));
        updateOrderState(specificOrder, OrderState.PLACED, false);
      } catch (IOException e) {
        log.error("Threw a Execption, full stack trace follows:", e);

        e.printStackTrace();
        // todo retry until expiration or reject as invalid
      }
    } else {
      MarketOrder marketOrder =
          new MarketOrder(orderType, tradeableVolume, currencyPair, id, timestamp);
      // todo put on a queue
      try {
        specificOrder.setRemoteKey(tradeService.placeMarketOrder(marketOrder));
        updateOrderState(specificOrder, OrderState.PLACED, false);
      } catch (IOException e) {
        // todo retry until expiration or reject as invalid
        log.warn("Could not place this order: " + specificOrder, e);
      } catch (NotYetImplementedForExchangeException e) {
        log.warn(
            "XChange adapter " + exchange + " does not support this order: " + specificOrder, e);
        reject(specificOrder, "XChange adapter " + exchange + " does not support this order");
      }
    }
  }