@Override
 public String placeLimitOrder(LimitOrder order) throws IOException, TheRockException {
   final TheRockOrder placedOrder =
       placeOrder(
           order.getCurrencyPair(),
           order.getTradableAmount(),
           order.getLimitPrice(),
           TheRockAdapters.adaptSide(order.getType()),
           TheRockOrder.Type.limit);
   return placedOrder.getId().toString();
 }
  public KrakenOrderResponse placeKrakenLimitOrder(LimitOrder limitOrder) throws IOException {

    KrakenType type = KrakenType.fromOrderType(limitOrder.getType());
    KrakenOrderBuilder krakenOrderBuilder =
        KrakenStandardOrder.getLimitOrderBuilder(
                limitOrder.getCurrencyPair(),
                type,
                limitOrder.getLimitPrice().toString(),
                limitOrder.getTradableAmount())
            .withOrderFlags(limitOrder.getOrderFlags());

    return placeKrakenOrder(krakenOrderBuilder.buildOrder());
  }
Exemple #3
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());
    }
  }
Exemple #4
0
  /**
   * Given a new LimitOrder, it will replace and old matching limit order in the orderbook or simply
   * get added. Finally, it is sorted.
   *
   * @param limitOrder
   */
  public void update(LimitOrder limitOrder) {

    if (limitOrder.getType().equals(OrderType.ASK)) {

      Iterator<LimitOrder> it = asks.iterator();
      while (it.hasNext()) {
        LimitOrder order = it.next();
        if (order.getLimitPrice().compareTo(limitOrder.getLimitPrice())
            == 0) { // they are equal. found it!
          it.remove();
          break;
        }
      }
      asks.add(limitOrder); // just add it
      Collections.sort(asks); // finally sort

    } else {

      Iterator<LimitOrder> it = bids.iterator();
      while (it.hasNext()) {
        LimitOrder order = it.next();
        if (order.getLimitPrice().compareTo(limitOrder.getLimitPrice())
            == 0) { // they are equal. found it!
          it.remove();
          break;
        }
      }
      bids.add(limitOrder); // just add it
      Collections.sort(bids); // finally sort
    }
  }
Exemple #5
0
  /**
   * Given an OrderBookUpdate, it will replace and old matching limit order in the orderbook or
   * simply get added. Finally, it is sorted.
   *
   * @param limitOrder
   */
  public void update(OrderBookUpdate orderBookUpdate) {

    // First, we need to remove orders with the same limit price
    Iterator<LimitOrder> it;
    if (orderBookUpdate.getLimitOrder().getType() == OrderType.ASK) {
      it = this.asks.iterator();
    } else {
      it = this.bids.iterator();
    }
    while (it.hasNext()) {
      LimitOrder order = it.next();
      if (order.getLimitPrice().compareTo(orderBookUpdate.getLimitOrder().getLimitPrice())
          == 0) { // they are equal. found it!
        it.remove();
        break;
      }
    }

    // If volume is not zero we need to add a new limit order with the updated amount
    if (orderBookUpdate.getTotalVolume().compareTo(BigDecimal.ZERO) != 0) {

      OrderType type = orderBookUpdate.getLimitOrder().getType();
      BigDecimal tradeableAmount = orderBookUpdate.getTotalVolume();
      String tradeableIdentifier = orderBookUpdate.getLimitOrder().getTradableIdentifier();
      String transitionCurrency = orderBookUpdate.getLimitOrder().getTransactionCurrency();
      String id = orderBookUpdate.getLimitOrder().getId();
      Date date = orderBookUpdate.getLimitOrder().getTimestamp();
      BigMoney limit = orderBookUpdate.getLimitOrder().getLimitPrice();
      LimitOrder updatedOrder =
          new LimitOrder(
              type, tradeableAmount, tradeableIdentifier, transitionCurrency, id, date, limit);

      if (orderBookUpdate.getLimitOrder().getType() == OrderType.ASK) {
        asks.add(updatedOrder);
        Collections.sort(asks);
      } else {
        bids.add(updatedOrder);
        Collections.sort(bids);
      }
    }
  }
  @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;
  }
  @Override
  public String placeLimitOrder(LimitOrder limitOrder) throws IOException, BitstampException {

    Assert.isTrue(
        limitOrder.getCurrencyPair().equals(CurrencyPair.BTC_USD),
        "Currency Pair must be USD/BTC!!!");

    BitstampOrder bitstampOrder;
    if (limitOrder.getType() == BID) {
      bitstampOrder = buyBitStampOrder(limitOrder.getTradableAmount(), limitOrder.getLimitPrice());
    } else {
      bitstampOrder = sellBitstampOrder(limitOrder.getTradableAmount(), limitOrder.getLimitPrice());
    }
    if (bitstampOrder.getErrorMessage() != null) {
      throw new ExchangeException(bitstampOrder.getErrorMessage());
    }

    return Integer.toString(bitstampOrder.getId());
  }
  public BitfinexOrderStatusResponse placeBitfinexLimitOrder(
      LimitOrder limitOrder, BitfinexOrderType bitfinexOrderType, boolean hidden)
      throws IOException {

    String pair = BitfinexUtils.toPairString(limitOrder.getCurrencyPair());
    String type = limitOrder.getType().equals(Order.OrderType.BID) ? "buy" : "sell";
    String orderType = bitfinexOrderType.toString();

    BitfinexNewOrderRequest request;
    if (hidden) {
      request =
          new BitfinexNewHiddenOrderRequest(
              String.valueOf(exchange.getNonceFactory().createValue()),
              pair,
              limitOrder.getTradableAmount(),
              limitOrder.getLimitPrice(),
              "bitfinex",
              type,
              orderType);
    } else {
      request =
          new BitfinexNewOrderRequest(
              String.valueOf(exchange.getNonceFactory().createValue()),
              pair,
              limitOrder.getTradableAmount(),
              limitOrder.getLimitPrice(),
              "bitfinex",
              type,
              orderType);
    }

    try {
      BitfinexOrderStatusResponse newOrder =
          bitfinex.newOrder(apiKey, payloadCreator, signatureCreator, request);
      return newOrder;
    } catch (BitfinexException e) {
      throw new ExchangeException(e.getMessage());
    }
  }