Search in sources :

Example 1 with GeminiOrderStatusResponse

use of org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse in project XChange by knowm.

the class GeminiTradeService method placeLimitOrder.

@Override
public String placeLimitOrder(LimitOrder limitOrder) throws IOException {
    GeminiOrderStatusResponse newOrder = placeGeminiLimitOrder(limitOrder, GeminiOrderType.LIMIT);
    // of this order. Make these available to the application if it has provided a GeminiLimitOrder.
    if (limitOrder instanceof GeminiLimitOrder) {
        GeminiLimitOrder raw = (GeminiLimitOrder) limitOrder;
        raw.setResponse(newOrder);
    }
    return String.valueOf(newOrder.getId());
}
Also used : GeminiOrderStatusResponse(org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse) GeminiLimitOrder(org.knowm.xchange.gemini.v1.dto.trade.GeminiLimitOrder)

Example 2 with GeminiOrderStatusResponse

use of org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse in project XChange by knowm.

the class GeminiTradeServiceRaw method placeGeminiLimitOrder.

public GeminiOrderStatusResponse placeGeminiLimitOrder(LimitOrder limitOrder, GeminiOrderType GeminiOrderType) throws IOException {
    String pair = GeminiUtils.toPairString(limitOrder.getCurrencyPair());
    String type = limitOrder.getType().equals(Order.OrderType.BID) ? "buy" : "sell";
    String orderType = GeminiOrderType.toString();
    Set<IOrderFlags> flags = limitOrder.getOrderFlags();
    Object[] options;
    if (flags.isEmpty()) {
        options = null;
    } else {
        ArrayList<String> list = new ArrayList<String>();
        if (flags.contains(GeminiOrderFlags.IMMEDIATE_OR_CANCEL)) {
            list.add("immediate-or-cancel");
        }
        if (flags.contains(GeminiOrderFlags.POST_ONLY)) {
            list.add("maker-or-cancel");
        }
        if (flags.contains(GeminiOrderFlags.FILL_OR_KILL)) {
            list.add("fill-or-kill");
        }
        if (flags.contains(GeminiOrderFlags.AUCTION_ONLY)) {
            list.add("auction-only");
        }
        if (flags.contains(GeminiOrderFlags.INDICATION_OF_INTEREST)) {
            list.add("indication-of-interest");
        }
        options = list.toArray();
    }
    GeminiNewOrderRequest request = new GeminiNewOrderRequest(String.valueOf(exchange.getNonceFactory().createValue()), limitOrder.getUserReference(), pair, limitOrder.getOriginalAmount(), limitOrder.getLimitPrice(), "Gemini", type, orderType, options);
    try {
        GeminiOrderStatusResponse newOrder = gemini.newOrder(apiKey, payloadCreator, signatureCreator, request);
        return newOrder;
    } catch (GeminiException e) {
        throw handleException(e);
    }
}
Also used : IOrderFlags(org.knowm.xchange.dto.Order.IOrderFlags) ArrayList(java.util.ArrayList) GeminiOrderStatusResponse(org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse) GeminiException(org.knowm.xchange.gemini.v1.dto.GeminiException) GeminiNewOrderRequest(org.knowm.xchange.gemini.v1.dto.trade.GeminiNewOrderRequest)

Example 3 with GeminiOrderStatusResponse

use of org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse in project XChange by knowm.

the class GeminiAdaptersTest method testAdaptLimitOrderFilled.

@Test
public void testAdaptLimitOrderFilled() throws IOException {
    // Read in the JSON from the example resources
    InputStream is = GeminiAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/gemini/v1/order/example-limit-order-status.json");
    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    GeminiOrderStatusResponse geminiOrderStatusResponse = mapper.readValue(is, GeminiOrderStatusResponse.class);
    Order order = GeminiAdapters.adaptOrder(geminiOrderStatusResponse);
    assertThat(order.getId()).isEqualTo("44375901");
    assertThat(order.getAveragePrice()).isEqualTo(new BigDecimal("400.00"));
    assertThat(order.getCumulativeAmount()).isEqualTo(new BigDecimal("3"));
    assertThat(order.getCurrencyPair()).isEqualTo(CurrencyPair.BTC_USD);
    assertThat(order.getStatus()).isEqualTo(Order.OrderStatus.FILLED);
    assertThat(LimitOrder.class.isAssignableFrom(order.getClass()));
}
Also used : Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) InputStream(java.io.InputStream) GeminiOrderStatusResponse(org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) GeminiWalletJSONTest(org.knowm.xchange.gemini.v1.dto.account.GeminiWalletJSONTest)

Example 4 with GeminiOrderStatusResponse

use of org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse in project XChange by knowm.

the class GeminiAdaptersTest method testAdaptOrderResponseContainingTradesToOrder.

@Test
public void testAdaptOrderResponseContainingTradesToOrder() throws IOException {
    InputStream resourceAsStream = GeminiAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/gemini/v1/order/example-get-order-data-trades-included.json");
    GeminiOrderStatusResponse response = new ObjectMapper().readValue(resourceAsStream, GeminiOrderStatusResponse.class);
    Order order = GeminiAdapters.adaptOrder(response);
    assertEquals("54516439535", order.getId());
    assertEquals("TESTID0", order.getUserReference());
    assertEquals(new Date(1629872367328L), order.getTimestamp());
    assertEquals(CurrencyPair.ETH_USD, order.getInstrument());
    assertEquals(OrderType.ASK, order.getType());
    assertEquals(new BigDecimal("0.001"), order.getOriginalAmount());
    assertEquals(new BigDecimal("3206.00"), order.getAveragePrice());
    assertEquals(new BigDecimal("0.001"), order.getCumulativeAmount());
    assertEquals(new BigDecimal("0.000"), order.getRemainingAmount());
    assertEquals(new BigDecimal("0.003206"), order.getFee());
    assertEquals(Order.OrderStatus.FILLED, order.getStatus());
}
Also used : Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) InputStream(java.io.InputStream) GeminiOrderStatusResponse(org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) GeminiWalletJSONTest(org.knowm.xchange.gemini.v1.dto.account.GeminiWalletJSONTest)

Example 5 with GeminiOrderStatusResponse

use of org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse in project XChange by knowm.

the class GeminiAdaptersTest method testAdaptLimitOrderPartiallyFilled.

@Test
public void testAdaptLimitOrderPartiallyFilled() throws IOException {
    // Read in the JSON from the example resources
    InputStream is = GeminiAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/gemini/v1/order/limit-order-partially-filled.json");
    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    GeminiOrderStatusResponse geminiOrderStatusResponse = mapper.readValue(is, GeminiOrderStatusResponse.class);
    Order order = GeminiAdapters.adaptOrder(geminiOrderStatusResponse);
    assertThat(order.getId()).isEqualTo("44375901");
    assertThat(order.getAveragePrice()).isEqualTo(new BigDecimal("400.00"));
    assertThat(order.getCumulativeAmount()).isEqualTo(new BigDecimal("1"));
    assertThat(order.getCurrencyPair()).isEqualTo(CurrencyPair.BTC_USD);
    assertThat(order.getStatus()).isEqualTo(Order.OrderStatus.PARTIALLY_FILLED);
    assertThat(LimitOrder.class.isAssignableFrom(order.getClass()));
}
Also used : Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) InputStream(java.io.InputStream) GeminiOrderStatusResponse(org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) GeminiWalletJSONTest(org.knowm.xchange.gemini.v1.dto.account.GeminiWalletJSONTest)

Aggregations

GeminiOrderStatusResponse (org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse)12 BigDecimal (java.math.BigDecimal)10 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)9 Test (org.junit.Test)7 Order (org.knowm.xchange.dto.Order)7 GeminiWalletJSONTest (org.knowm.xchange.gemini.v1.dto.account.GeminiWalletJSONTest)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 InputStream (java.io.InputStream)5 Date (java.util.Date)4 OrderType (org.knowm.xchange.dto.Order.OrderType)4 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)3 ArrayList (java.util.ArrayList)2 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)2 OrderStatus (org.knowm.xchange.dto.Order.OrderStatus)2 IOrderFlags (org.knowm.xchange.dto.Order.IOrderFlags)1 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)1 NotYetImplementedForExchangeException (org.knowm.xchange.exceptions.NotYetImplementedForExchangeException)1 GeminiException (org.knowm.xchange.gemini.v1.dto.GeminiException)1 GeminiLimitOrder (org.knowm.xchange.gemini.v1.dto.trade.GeminiLimitOrder)1 GeminiNewOrderRequest (org.knowm.xchange.gemini.v1.dto.trade.GeminiNewOrderRequest)1