Example #1
0
  public static void main(String[] args) throws IOException {

    Exchange mtgox = MtGoxV1ExamplesUtils.createExchange();

    // Interested in the private trading functionality (authentication)
    PollingTradeService tradeService = mtgox.getPollingTradeService();

    boolean success = tradeService.cancelOrder("fa432315-a929-4202-a681-9a8fbd0e2549");
    System.out.println("success= " + success);

    // get open orders
    OpenOrders openOrders = tradeService.getOpenOrders();
    for (LimitOrder openOrder : openOrders.getOpenOrders()) {
      System.out.println(openOrder.toString());
    }
  }
  @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;
  }
  private static void printOpenOrders(PollingTradeService tradeService) {

    OpenOrders openOrders = tradeService.getOpenOrders();
    System.out.println("Open Orders: " + openOrders.toString());
  }