Search in sources :

Example 1 with TradeHistoryParamInstrument

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);
}
Also used : TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) DeribitExchange(org.knowm.xchange.deribit.v2.DeribitExchange) TradeHistoryParamsIdSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan) Date(java.util.Date) TradeHistoryParamInstrument(org.knowm.xchange.service.trade.params.TradeHistoryParamInstrument) Kind(org.knowm.xchange.deribit.v2.dto.Kind) OpenOrdersParamInstrument(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamInstrument) DefaultOpenOrdersParamInstrument(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamInstrument) TradeHistoryParamInstrument(org.knowm.xchange.service.trade.params.TradeHistoryParamInstrument) Instrument(org.knowm.xchange.instrument.Instrument) TradeHistoryParamsSorted(org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted) NotYetImplementedForExchangeException(org.knowm.xchange.exceptions.NotYetImplementedForExchangeException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Aggregations

Date (java.util.Date)1 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)1 DeribitExchange (org.knowm.xchange.deribit.v2.DeribitExchange)1 Kind (org.knowm.xchange.deribit.v2.dto.Kind)1 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)1 NotYetImplementedForExchangeException (org.knowm.xchange.exceptions.NotYetImplementedForExchangeException)1 Instrument (org.knowm.xchange.instrument.Instrument)1 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)1 TradeHistoryParamInstrument (org.knowm.xchange.service.trade.params.TradeHistoryParamInstrument)1 TradeHistoryParamLimit (org.knowm.xchange.service.trade.params.TradeHistoryParamLimit)1 TradeHistoryParamsIdSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan)1 TradeHistoryParamsSorted (org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted)1 TradeHistoryParamsTimeSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan)1 DefaultOpenOrdersParamInstrument (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamInstrument)1 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)1 OpenOrdersParamInstrument (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamInstrument)1