Search in sources :

Example 1 with GeminiNewOrderRequest

use of org.knowm.xchange.gemini.v1.dto.trade.GeminiNewOrderRequest 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)

Aggregations

ArrayList (java.util.ArrayList)1 IOrderFlags (org.knowm.xchange.dto.Order.IOrderFlags)1 GeminiException (org.knowm.xchange.gemini.v1.dto.GeminiException)1 GeminiNewOrderRequest (org.knowm.xchange.gemini.v1.dto.trade.GeminiNewOrderRequest)1 GeminiOrderStatusResponse (org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse)1