Search in sources :

Example 1 with IOrderFlags

use of org.knowm.xchange.dto.Order.IOrderFlags 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 2 with IOrderFlags

use of org.knowm.xchange.dto.Order.IOrderFlags in project XChange by knowm.

the class KucoinAdapters method adaptOrder.

/**
 * Returns {@code Object} instead of the Lombok builder in order to avoid a Lombok limitation with
 * Javadoc.
 */
private static Object adaptOrder(Order order) {
    OrderCreateApiRequest.OrderCreateApiRequestBuilder request = OrderCreateApiRequest.builder();
    boolean hasClientId = false;
    for (IOrderFlags flag : order.getOrderFlags()) {
        if (flag instanceof KucoinOrderFlags) {
            request.clientOid(((KucoinOrderFlags) flag).getClientId());
            hasClientId = true;
        } else if (flag instanceof TimeInForce) {
            request.timeInForce(((TimeInForce) flag).name());
        }
    }
    if (!hasClientId) {
        request.clientOid(UUID.randomUUID().toString());
    }
    return request.symbol(adaptCurrencyPair((CurrencyPair) order.getInstrument())).size(order.getOriginalAmount()).side(adaptSide(order.getType()));
}
Also used : IOrderFlags(org.knowm.xchange.dto.Order.IOrderFlags) KucoinOrderFlags(org.knowm.xchange.kucoin.KucoinTradeService.KucoinOrderFlags) OrderCreateApiRequest(org.knowm.xchange.kucoin.dto.request.OrderCreateApiRequest) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 3 with IOrderFlags

use of org.knowm.xchange.dto.Order.IOrderFlags in project XChange by knowm.

the class KrakenBaseServiceTest method testDelimitSetOrderFlags.

@Test
public void testDelimitSetOrderFlags() {
    ExchangeSpecification specification = new ExchangeSpecification(KrakenExchange.class);
    specification.setShouldLoadRemoteMetaData(false);
    Exchange exchange = ExchangeFactory.INSTANCE.createExchange(specification);
    KrakenBaseService service = new KrakenBaseService(exchange);
    assertThat(service.delimitSet(null)).isNull();
    Set<IOrderFlags> flags = new HashSet<>();
    assertThat(service.delimitSet(flags)).isNull();
    flags.add(KrakenOrderFlags.NOMPP);
    assertThat(service.delimitSet(flags)).isEqualTo(KrakenOrderFlags.NOMPP.toString());
    // this flag should not be added to the string
    flags.add(OtherExchangeFlags.OTHER);
    assertThat(service.delimitSet(flags)).isEqualTo(KrakenOrderFlags.NOMPP.toString());
    flags.remove(OtherExchangeFlags.OTHER);
    flags.add(KrakenOrderFlags.VIQC);
    flags.add(KrakenOrderFlags.FCIQ);
    // flags should now contain NOMPP, VIQC and FCIQ
    Collection<String> flagsAsStrings = Arrays.asList(service.delimitSet(flags).split(","));
    assertThat(flagsAsStrings.size()).isEqualTo(3);
    assertThat(flagsAsStrings.size()).isEqualTo(flags.size());
    for (IOrderFlags flag : flags) {
        assertThat(flagsAsStrings).contains(flag.toString());
    }
}
Also used : KrakenExchange(org.knowm.xchange.kraken.KrakenExchange) Exchange(org.knowm.xchange.Exchange) IOrderFlags(org.knowm.xchange.dto.Order.IOrderFlags) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

IOrderFlags (org.knowm.xchange.dto.Order.IOrderFlags)3 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 Exchange (org.knowm.xchange.Exchange)1 ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)1 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)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 KrakenExchange (org.knowm.xchange.kraken.KrakenExchange)1 KucoinOrderFlags (org.knowm.xchange.kucoin.KucoinTradeService.KucoinOrderFlags)1 OrderCreateApiRequest (org.knowm.xchange.kucoin.dto.request.OrderCreateApiRequest)1