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());
}
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);
}
}
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()));
}
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());
}
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()));
}
Aggregations