Search in sources :

Example 6 with LimitOrder

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

the class CoinfloorOrderBookIntegration method fetchOrderBookTest.

@Test
public void fetchOrderBookTest() throws IOException {
    Exchange exchange = ExchangeFactory.INSTANCE.createExchange(CoinfloorExchange.class);
    MarketDataService service = exchange.getMarketDataService();
    OrderBook orderBook = service.getOrderBook(CurrencyPair.BTC_GBP);
    assertThat(orderBook.getBids()).isNotEmpty();
    assertThat(orderBook.getAsks()).isNotEmpty();
    LimitOrder order = orderBook.getBids().get(0);
    assertThat(order.getCurrencyPair()).isEqualTo(CurrencyPair.BTC_GBP);
    assertThat(order.getOriginalAmount()).isGreaterThan(BigDecimal.ZERO);
    assertThat(order.getLimitPrice()).isGreaterThan(BigDecimal.ZERO);
}
Also used : CoinfloorExchange(org.knowm.xchange.coinfloor.CoinfloorExchange) Exchange(org.knowm.xchange.Exchange) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) MarketDataService(org.knowm.xchange.service.marketdata.MarketDataService) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Test(org.junit.Test)

Example 7 with LimitOrder

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

the class CoingiTradeService method getOrder.

@Override
public Collection<Order> getOrder(String... orderIds) throws IOException {
    try {
        Collection<Order> orders = new ArrayList<>();
        for (String orderId : orderIds) {
            CoingiGetOrderRequest request = new CoingiGetOrderRequest().setOrderId(orderId);
            CoingiOrder coingiOrder;
            coingiOrder = getCoingiOrder(request);
            CurrencyPair currencyPair = CoingiAdapters.adaptCurrency(coingiOrder.getCurrencyPair());
            Date date = new Date(coingiOrder.getTimestamp() * 1000);
            Order order = new LimitOrder(coingiOrder.getType() == 0 ? Order.OrderType.BID : Order.OrderType.ASK, coingiOrder.getOriginalBaseAmount(), currencyPair, coingiOrder.getId(), date, coingiOrder.getPrice());
            order.setOrderStatus(CoingiAdapters.adaptOrderStatus(coingiOrder.getStatus()));
            orders.add(order);
        }
        return orders;
    } catch (CoingiException e) {
        throw CoingiErrorAdapter.adapt(e);
    }
}
Also used : CoingiOrder(org.knowm.xchange.coingi.dto.trade.CoingiOrder) Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) CoingiException(org.knowm.xchange.coingi.dto.CoingiException) CoingiGetOrderRequest(org.knowm.xchange.coingi.dto.trade.CoingiGetOrderRequest) ArrayList(java.util.ArrayList) CoingiOrder(org.knowm.xchange.coingi.dto.trade.CoingiOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Date(java.util.Date) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 8 with LimitOrder

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

the class MercadoBitcoinTradeDemo method generic.

private static void generic(TradeService tradeService) throws IOException, InterruptedException {
    printOpenOrders(tradeService);
    // place a limit buy order
    LimitOrder limitOrder = new LimitOrder((Order.OrderType.ASK), new BigDecimal("0.01"), CurrencyPair.BTC_BRL, "", null, new BigDecimal("9000.00"));
    String limitOrderReturnValue = tradeService.placeLimitOrder(limitOrder);
    System.out.println("Limit Order return value: " + limitOrderReturnValue);
    printOpenOrders(tradeService);
    // Cancel the added order
    boolean cancelResult = tradeService.cancelOrder(limitOrderReturnValue);
    System.out.println("Canceling returned " + cancelResult);
    printOpenOrders(tradeService);
}
Also used : LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal)

Example 9 with LimitOrder

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

the class KrakenCancelOrderDemo method raw.

private static void raw(Exchange krakenExchange) throws IOException {
    KrakenTradeServiceRaw tradeService = (KrakenTradeServiceRaw) krakenExchange.getTradeService();
    System.out.println("Open Orders: " + tradeService.getKrakenOpenOrders());
    // place a limit buy order
    LimitOrder limitOrder = new LimitOrder((OrderType.ASK), new BigDecimal(".01"), CurrencyPair.BTC_LTC, "", null, new BigDecimal("51.25"));
    KrakenOrderResponse limitOrderReturnValue = tradeService.placeKrakenLimitOrder(limitOrder);
    System.out.println("Limit Order return value: " + limitOrderReturnValue);
    Map<String, KrakenOrder> openOrders = tradeService.getKrakenOpenOrders();
    System.out.println("Open Orders: " + openOrders);
    // Cancel the added order
    List<String> transactionIds = limitOrderReturnValue.getTransactionIds();
    if (transactionIds != null && !transactionIds.isEmpty()) {
        KrakenCancelOrderResponse cancelResult = tradeService.cancelKrakenOrder(transactionIds.get(0));
        System.out.println("Canceling returned " + cancelResult);
        System.out.println("Open Orders: " + tradeService.getKrakenOpenOrders());
    }
}
Also used : KrakenTradeServiceRaw(org.knowm.xchange.kraken.service.KrakenTradeServiceRaw) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) KrakenOrderResponse(org.knowm.xchange.kraken.dto.trade.KrakenOrderResponse) KrakenOrder(org.knowm.xchange.kraken.dto.trade.KrakenOrder) KrakenCancelOrderResponse(org.knowm.xchange.kraken.dto.trade.results.KrakenCancelOrderResult.KrakenCancelOrderResponse) BigDecimal(java.math.BigDecimal)

Example 10 with LimitOrder

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

the class KrakenLimitOrderDemo method raw.

private static void raw(Exchange krakenExchange) throws IOException {
    KrakenTradeServiceRaw tradeService = (KrakenTradeServiceRaw) krakenExchange.getTradeService();
    OrderType orderType = (OrderType.ASK);
    BigDecimal tradeableAmount = new BigDecimal("0.01");
    BigDecimal price = new BigDecimal("65.25");
    LimitOrder limitOrder = new LimitOrder(orderType, tradeableAmount, CurrencyPair.BTC_LTC, "", null, price);
    KrakenOrderResponse orderResponse = tradeService.placeKrakenLimitOrder(limitOrder);
    System.out.println("Limit Order response: " + orderResponse);
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) KrakenTradeServiceRaw(org.knowm.xchange.kraken.service.KrakenTradeServiceRaw) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) KrakenOrderResponse(org.knowm.xchange.kraken.dto.trade.KrakenOrderResponse) BigDecimal(java.math.BigDecimal)

Aggregations

LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)337 BigDecimal (java.math.BigDecimal)188 Test (org.junit.Test)122 Date (java.util.Date)110 ArrayList (java.util.ArrayList)95 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)90 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)89 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)77 Order (org.knowm.xchange.dto.Order)50 OrderType (org.knowm.xchange.dto.Order.OrderType)39 Exchange (org.knowm.xchange.Exchange)31 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)29 List (java.util.List)28 TradeService (org.knowm.xchange.service.trade.TradeService)28 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)23 IOException (java.io.IOException)20 Collectors (java.util.stream.Collectors)20 MarketDataService (org.knowm.xchange.service.marketdata.MarketDataService)17 InputStream (java.io.InputStream)15 DefaultOpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)15