Search in sources :

Example 11 with OpenOrders

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

the class CexIOAdapters method adaptOpenOrders.

public static OpenOrders adaptOpenOrders(List<CexIOOrder> cexIOOrderList) {
    List<LimitOrder> limitOrders = new ArrayList<>();
    for (CexIOOrder cexIOOrder : cexIOOrderList) {
        OrderType orderType = cexIOOrder.getType() == CexIOOrder.Type.buy ? OrderType.BID : OrderType.ASK;
        String id = Long.toString(cexIOOrder.getId());
        limitOrders.add(new LimitOrder(orderType, cexIOOrder.getAmount(), cexIOOrder.getAmount().subtract(cexIOOrder.getPending()), new CurrencyPair(cexIOOrder.getSymbol1(), cexIOOrder.getSymbol2()), id, DateUtils.fromMillisUtc(cexIOOrder.getTime()), cexIOOrder.getPrice()));
    }
    return new OpenOrders(limitOrders);
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) ArrayList(java.util.ArrayList) CexIOOrder(org.knowm.xchange.cexio.dto.trade.CexIOOrder) DateUtils.fromISODateString(org.knowm.xchange.utils.DateUtils.fromISODateString) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 12 with OpenOrders

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

the class GateioTradeDemo method generic.

private static void generic(TradeService tradeService) throws IOException, InterruptedException {
    LimitOrder limitOrder = new LimitOrder(OrderType.ASK, new BigDecimal("0.384"), CurrencyPair.LTC_BTC, "", null, new BigDecimal("0.0265"));
    String orderId = tradeService.placeLimitOrder(limitOrder);
    System.out.println(// Returned order id is currently broken for Gateio, rely on open orders instead//
    orderId);
    // for demo :(
    // wait for Gateio's back-end to propagate the order
    Thread.sleep(2000);
    OpenOrders openOrders = tradeService.getOpenOrders();
    System.out.println(openOrders);
    List<LimitOrder> openOrdersList = openOrders.getOpenOrders();
    if (!openOrdersList.isEmpty()) {
        String existingOrderId = openOrdersList.get(0).getId();
        boolean isCancelled = tradeService.cancelOrder(existingOrderId);
        System.out.println(isCancelled);
    }
    // wait for Gateio's back-end to propagate the cancelled order
    Thread.sleep(2000);
    openOrders = tradeService.getOpenOrders();
    System.out.println(openOrders);
    Thread.sleep(2000);
    Trades tradeHistory = tradeService.getTradeHistory(new DefaultTradeHistoryParamCurrencyPair(CurrencyPair.LTC_BTC));
    System.out.println(tradeHistory);
}
Also used : Trades(org.knowm.xchange.dto.marketdata.Trades) DefaultTradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) GateioOpenOrders(org.knowm.xchange.gateio.dto.trade.GateioOpenOrders) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) BigDecimal(java.math.BigDecimal)

Example 13 with OpenOrders

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

the class CoinbeneTradeDemo method generic.

public static void generic(Exchange exchange) throws IOException {
    CurrencyPair pair = CurrencyPair.BTC_USDT;
    TradeService tradeService = exchange.getTradeService();
    // Get open orders
    OpenOrders orders = tradeService.getOpenOrders(new DefaultOpenOrdersParamCurrencyPair(pair));
    LimitOrder order = orders.getOpenOrders().stream().collect(StreamUtils.singletonCollector());
    if (order != null) {
        System.out.println(order);
    }
}
Also used : CoinbeneTradeService(org.knowm.xchange.coinbene.service.CoinbeneTradeService) TradeService(org.knowm.xchange.service.trade.TradeService) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)

Example 14 with OpenOrders

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

the class TradeServiceIntegration method testCgetOpenOrdersByMarketTest.

@Test
public void testCgetOpenOrdersByMarketTest() throws Exception {
    DefaultOpenOrdersParamCurrencyPair currencyPair = new DefaultOpenOrdersParamCurrencyPair();
    currencyPair.setCurrencyPair(CurrencyPair.ETH_BTC);
    OpenOrders openOrders = tradeService.getOpenOrders(currencyPair);
    logger.info("Response: {}", openOrders);
}
Also used : OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) Test(org.junit.Test)

Example 15 with OpenOrders

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

the class BTCMarketsAdaptersTest method shouldAdaptOrders.

@Test
public void shouldAdaptOrders() throws IOException {
    final BTCMarketsOrders response = parse(BTCMarketsOrders.class);
    final OpenOrders openOrders = BTCMarketsAdapters.adaptOpenOrders(response);
    assertThat(openOrders.getOpenOrders()).hasSize(2);
    assertThat(openOrders.getOpenOrders().get(1).getId()).isEqualTo("4345675");
    assertThat(openOrders.getOpenOrders().get(1).getCurrencyPair()).isEqualTo(CurrencyPair.BTC_AUD);
    assertThat(openOrders.getOpenOrders().get(1).getType()).isEqualTo(Order.OrderType.ASK);
    assertThat(openOrders.getOpenOrders().get(1).getTimestamp().getTime()).isEqualTo(1378636912705L);
    assertThat(openOrders.getOpenOrders().get(1).getLimitPrice()).isEqualTo("130.00000000");
    assertThat(openOrders.getOpenOrders().get(1).getOriginalAmount()).isEqualTo("0.10000000");
    assertThat(openOrders.getOpenOrders().get(1).getCumulativeAmount()).isEqualTo(BigDecimal.valueOf(0.1));
    assertThat(openOrders.getOpenOrders().get(1).getAveragePrice()).isEqualTo(BigDecimal.valueOf(130.0));
    assertThat(openOrders.getOpenOrders().get(1).getFee()).isEqualTo(BigDecimal.valueOf(0.001));
    assertThat(openOrders.getOpenOrders().get(0).getUserReference()).isEqualTo("orderOne");
    assertThat(openOrders.getOpenOrders().get(1).getUserReference()).isNull();
}
Also used : BTCMarketsOrders(org.knowm.xchange.btcmarkets.dto.trade.BTCMarketsOrders) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) Test(org.junit.Test)

Aggregations

OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)117 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)79 Test (org.junit.Test)40 BigDecimal (java.math.BigDecimal)36 ArrayList (java.util.ArrayList)33 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)31 TradeService (org.knowm.xchange.service.trade.TradeService)26 Date (java.util.Date)23 Order (org.knowm.xchange.dto.Order)21 OrderType (org.knowm.xchange.dto.Order.OrderType)20 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)16 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)15 UserTrades (org.knowm.xchange.dto.trade.UserTrades)14 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)14 Exchange (org.knowm.xchange.Exchange)13 DefaultOpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)12 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)10 InputStream (java.io.InputStream)9 List (java.util.List)9 StopOrder (org.knowm.xchange.dto.trade.StopOrder)8