Esempio n. 1
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");
      }
    }
  }