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