Search in sources :

Example 1 with BitstampOrder

use of org.knowm.xchange.bitstamp.dto.trade.BitstampOrder in project XChange by knowm.

the class BitstampTradeService method getOpenOrders.

@Override
public OpenOrders getOpenOrders(OpenOrdersParams params) throws ExchangeException, IOException {
    BitstampOrder[] openOrders = getBitstampOpenOrders();
    List<LimitOrder> limitOrders = new ArrayList<>(openOrders.length);
    for (BitstampOrder bitstampOrder : openOrders) {
        OrderType orderType = bitstampOrder.getType() == 0 ? OrderType.BID : OrderType.ASK;
        String id = Long.toString(bitstampOrder.getId());
        BigDecimal price = bitstampOrder.getPrice();
        limitOrders.add(new LimitOrder(orderType, bitstampOrder.getAmount(), new BitstampV2.Pair(bitstampOrder.getCurrencyPair()).pair, id, bitstampOrder.getDatetime(), price, // avgPrice
        null, // cumAmount
        null, // fee
        null, Order.OrderStatus.NEW));
    }
    return new OpenOrders(limitOrders);
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) BitstampV2(org.knowm.xchange.bitstamp.BitstampV2) BitstampOrder(org.knowm.xchange.bitstamp.dto.trade.BitstampOrder) ArrayList(java.util.ArrayList) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) BigDecimal(java.math.BigDecimal)

Example 2 with BitstampOrder

use of org.knowm.xchange.bitstamp.dto.trade.BitstampOrder in project XChange by knowm.

the class BitstampTradeService method placeMarketOrder.

@Override
public String placeMarketOrder(MarketOrder order) throws IOException, BitstampException {
    BitstampAuthenticatedV2.Side side = order.getType().equals(BID) ? BitstampAuthenticatedV2.Side.buy : BitstampAuthenticatedV2.Side.sell;
    BitstampOrder bitstampOrder = placeBitstampMarketOrder(order.getCurrencyPair(), side, order.getOriginalAmount());
    if (bitstampOrder.getErrorMessage() != null) {
        throw new ExchangeException(bitstampOrder.getErrorMessage());
    }
    return Long.toString(bitstampOrder.getId());
}
Also used : BitstampOrder(org.knowm.xchange.bitstamp.dto.trade.BitstampOrder) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) BitstampAuthenticatedV2(org.knowm.xchange.bitstamp.BitstampAuthenticatedV2)

Example 3 with BitstampOrder

use of org.knowm.xchange.bitstamp.dto.trade.BitstampOrder in project XChange by knowm.

the class BitstampTradeDemo method raw.

private static void raw(BitstampTradeServiceRaw tradeService) throws IOException {
    printRawOpenOrders(tradeService);
    // place a limit buy order
    BitstampOrder order = tradeService.placeBitstampOrder(CurrencyPair.BTC_USD, Side.sell, new BigDecimal(".001"), new BigDecimal("1000.00"));
    System.out.println("BitstampOrder return value: " + order);
    printRawOpenOrders(tradeService);
    // Cancel the added order
    boolean cancelResult = tradeService.cancelBitstampOrder(order.getId());
    System.out.println("Canceling returned " + cancelResult);
    printRawOpenOrders(tradeService);
}
Also used : BitstampOrder(org.knowm.xchange.bitstamp.dto.trade.BitstampOrder) BigDecimal(java.math.BigDecimal)

Example 4 with BitstampOrder

use of org.knowm.xchange.bitstamp.dto.trade.BitstampOrder in project XChange by knowm.

the class BitstampTradeService method placeLimitOrder.

@Override
public String placeLimitOrder(LimitOrder order) throws IOException, BitstampException {
    BitstampAuthenticatedV2.Side side = order.getType().equals(BID) ? BitstampAuthenticatedV2.Side.buy : BitstampAuthenticatedV2.Side.sell;
    BitstampOrder bitstampOrder = placeBitstampOrder(order.getCurrencyPair(), side, order.getOriginalAmount(), order.getLimitPrice());
    if (bitstampOrder.getErrorMessage() != null) {
        throw new ExchangeException(bitstampOrder.getErrorMessage());
    }
    return Long.toString(bitstampOrder.getId());
}
Also used : BitstampOrder(org.knowm.xchange.bitstamp.dto.trade.BitstampOrder) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) BitstampAuthenticatedV2(org.knowm.xchange.bitstamp.BitstampAuthenticatedV2)

Example 5 with BitstampOrder

use of org.knowm.xchange.bitstamp.dto.trade.BitstampOrder in project XChange by knowm.

the class BitstampTradeDemo method printRawOpenOrders.

private static void printRawOpenOrders(BitstampTradeServiceRaw tradeService) throws IOException {
    BitstampOrder[] openOrders = tradeService.getBitstampOpenOrders(CurrencyPair.BTC_USD);
    System.out.println("Open Orders: " + openOrders.length);
    for (BitstampOrder order : openOrders) {
        System.out.println(order.toString());
    }
}
Also used : BitstampOrder(org.knowm.xchange.bitstamp.dto.trade.BitstampOrder)

Aggregations

BitstampOrder (org.knowm.xchange.bitstamp.dto.trade.BitstampOrder)5 BigDecimal (java.math.BigDecimal)2 BitstampAuthenticatedV2 (org.knowm.xchange.bitstamp.BitstampAuthenticatedV2)2 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)2 ArrayList (java.util.ArrayList)1 BitstampV2 (org.knowm.xchange.bitstamp.BitstampV2)1 OrderType (org.knowm.xchange.dto.Order.OrderType)1 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)1 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)1