use of org.knowm.xchange.service.trade.params.TradeHistoryParamInstrument 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);
}
Aggregations