예제 #1
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
    }
  }
  @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());
  }
예제 #3
0
 @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();
 }
예제 #4
0
  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());
  }
  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());
    }
  }
예제 #6
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);
      }
    }
  }