use of org.knowm.xchange.instrument.Instrument in project XChange by knowm.
the class OkexTradeService method getOrder.
public Order getOrder(OrderQueryParams orderQueryParams) throws IOException {
Order result = null;
if (orderQueryParams instanceof OrderQueryParamInstrument) {
Instrument instrument = ((OrderQueryParamInstrument) orderQueryParams).getInstrument();
String orderId = orderQueryParams.getOrderId();
List<OkexOrderDetails> orderResults = getOkexOrder(OkexAdapters.adaptInstrumentId(instrument), orderId).getData();
if (!orderResults.isEmpty()) {
result = OkexAdapters.adaptOrder(orderResults.get(0));
}
} else {
throw new IOException("OrderQueryParams must implement OrderQueryParamInstrument interface.");
}
return result;
}
use of org.knowm.xchange.instrument.Instrument in project XChange by knowm.
the class InstrumentDeserializer method deserialize.
@Override
public Instrument deserialize(JsonParser jsonParser, final DeserializationContext ctxt) throws IOException {
final ObjectCodec oc = jsonParser.getCodec();
final JsonNode node = oc.readTree(jsonParser);
final String instrumentString = node.asText();
long count = instrumentString.chars().filter(ch -> ch == '/').count();
// CurrencyPair (Base/Counter) i.e. BTC/USD
if (count == 1)
return new CurrencyPair(instrumentString);
// Futures/Swaps (Base/Counter/Prompt) i.e. BTC/USD/200925
if (count == 2)
return new FuturesContract(instrumentString);
// Options (Base/Counter/Prompt/StrikePrice/Put?Call) i.e. BTC/USD/200925/8956.67/P
if (count == 4)
return new OptionsContract(instrumentString);
else
return null;
}
use of org.knowm.xchange.instrument.Instrument in project XChange by knowm.
the class DeribitTradeService method getTradeHistory.
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
String instrumentName = null;
if (params instanceof TradeHistoryParamInstrument) {
Instrument instrument = ((TradeHistoryParamInstrument) params).getInstrument();
if (instrument != null) {
instrumentName = DeribitAdapters.adaptInstrumentName(instrument);
}
}
String currency = null;
// not implemented
Kind kind = null;
if (params instanceof TradeHistoryParamCurrencyPair) {
CurrencyPair currencyPair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
if (currencyPair != null) {
currency = currencyPair.base.getCurrencyCode();
}
}
Date startTime = null;
Date endTime = null;
if (params instanceof TradeHistoryParamsTimeSpan) {
startTime = ((TradeHistoryParamsTimeSpan) params).getStartTime();
endTime = ((TradeHistoryParamsTimeSpan) params).getEndTime();
}
String startId = null;
String endId = null;
if (params instanceof TradeHistoryParamsIdSpan) {
startId = ((TradeHistoryParamsIdSpan) params).getStartId();
endId = ((TradeHistoryParamsIdSpan) params).getEndId();
}
Integer limit = null;
if (params instanceof TradeHistoryParamLimit) {
limit = ((TradeHistoryParamLimit) params).getLimit();
}
String sorting = null;
if (params instanceof TradeHistoryParamsSorted) {
TradeHistoryParamsSorted.Order order = ((TradeHistoryParamsSorted) params).getOrder();
sorting = order == TradeHistoryParamsSorted.Order.asc ? "asc" : order == TradeHistoryParamsSorted.Order.desc ? "desc" : null;
}
Boolean includeOld = null;
if (params instanceof DeribitTradeHistoryParamsOld) {
includeOld = ((DeribitTradeHistoryParamsOld) params).isIncludeOld();
}
org.knowm.xchange.deribit.v2.dto.trade.UserTrades userTrades = null;
if (startTime != null && endTime != null) {
if (instrumentName != null) {
userTrades = super.getUserTradesByInstrumentAndTime(instrumentName, startTime, endTime, limit, includeOld, sorting);
} else if (currency != null) {
userTrades = super.getUserTradesByCurrencyAndTime(currency, kind, startTime, endTime, limit, includeOld, sorting);
}
} else {
if (instrumentName != null) {
Integer startSeq = startId != null ? Integer.valueOf(startId) : null;
Integer endSeq = endId != null ? Integer.valueOf(endId) : null;
userTrades = super.getUserTradesByInstrument(instrumentName, startSeq, endSeq, limit, includeOld, sorting);
} else if (currency != null) {
userTrades = super.getUserTradesByCurrency(currency, kind, startId, endId, limit, includeOld, sorting);
}
}
if (userTrades == null) {
throw new ExchangeException("You should specify either instrument or currency pair");
}
return DeribitAdapters.adaptUserTrades(userTrades);
}
use of org.knowm.xchange.instrument.Instrument in project XChange by knowm.
the class DeribitTradeService method getOpenOrders.
@Override
public OpenOrders getOpenOrders(OpenOrdersParams params) throws IOException {
List<org.knowm.xchange.deribit.v2.dto.trade.Order> openOrders;
if (params instanceof OpenOrdersParamCurrencyPair) {
OpenOrdersParamCurrencyPair pairParams = (OpenOrdersParamCurrencyPair) params;
CurrencyPair pair = pairParams.getCurrencyPair();
openOrders = super.getOpenOrdersByCurrency(pair.base.getCurrencyCode(), null, null);
} else if (params instanceof OpenOrdersParamInstrument) {
OpenOrdersParamInstrument instrumentParams = (OpenOrdersParamInstrument) params;
Instrument instrument = instrumentParams.getInstrument();
openOrders = super.getOpenOrdersByInstrument(DeribitAdapters.adaptInstrumentName(instrument), null);
} else {
openOrders = openOrders();
}
return DeribitAdapters.adaptOpenOrders(openOrders);
}
use of org.knowm.xchange.instrument.Instrument in project XChange by knowm.
the class DeribitAdapters method adaptOrderBook.
public static OrderBook adaptOrderBook(DeribitOrderBook deribitOrderBook) {
Instrument instrument = adaptInstrument(deribitOrderBook.getInstrumentName());
List<LimitOrder> bids = adaptOrdersList(deribitOrderBook.getBids(), Order.OrderType.BID, instrument);
List<LimitOrder> asks = adaptOrdersList(deribitOrderBook.getAsks(), Order.OrderType.ASK, instrument);
return new OrderBook(deribitOrderBook.getTimestamp(), asks, bids);
}
Aggregations