use of org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan in project XChange by knowm.
the class YoBitTradeService method getTradeHistory.
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
Integer count = 1000;
if (params instanceof TradeHistoryParamLimit) {
count = ((TradeHistoryParamLimit) params).getLimit();
}
Long offset = 0L;
if (params instanceof TradeHistoryParamOffset) {
offset = ((TradeHistoryParamOffset) params).getOffset();
}
String market = null;
if (params instanceof TradeHistoryParamCurrencyPair) {
CurrencyPair currencyPair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
market = YoBitAdapters.adaptCcyPairToUrlFormat(currencyPair);
}
Long fromTransactionId = null;
Long endTransactionId = null;
if (params instanceof TradeHistoryParamsIdSpan) {
TradeHistoryParamsIdSpan tradeHistoryParamsIdSpan = (TradeHistoryParamsIdSpan) params;
String startId = tradeHistoryParamsIdSpan.getStartId();
if (startId != null)
fromTransactionId = Long.valueOf(startId);
String endId = tradeHistoryParamsIdSpan.getEndId();
if (endId != null)
endTransactionId = Long.valueOf(endId);
}
String order = "DESC";
if (params instanceof TradeHistoryParamsSorted) {
order = ((TradeHistoryParamsSorted) params).getOrder().equals(TradeHistoryParamsSorted.Order.desc) ? "DESC" : "ASC";
}
Long fromTimestamp = null;
Long toTimestamp = null;
if (params instanceof TradeHistoryParamsTimeSpan) {
TradeHistoryParamsTimeSpan tradeHistoryParamsTimeSpan = (TradeHistoryParamsTimeSpan) params;
Date startTime = tradeHistoryParamsTimeSpan.getStartTime();
if (startTime != null)
fromTimestamp = DateUtils.toUnixTimeNullSafe(startTime);
Date endTime = tradeHistoryParamsTimeSpan.getEndTime();
if (endTime != null)
toTimestamp = DateUtils.toUnixTimeNullSafe(endTime);
}
BaseYoBitResponse response = tradeHistory(count, offset, market, fromTransactionId, endTransactionId, order, fromTimestamp, toTimestamp);
List<UserTrade> trades = new ArrayList<>();
if (response.returnData != null) {
for (Object key : response.returnData.keySet()) {
Map tradeData = (Map) response.returnData.get(key);
trades.add(YoBitAdapters.adaptUserTrade(key, tradeData));
}
}
return new UserTrades(trades, Trades.TradeSortType.SortByTimestamp);
}
use of org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan in project XChange by knowm.
the class BTCMarketsTradeService method getTradeHistory.
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
Integer limit = 200;
if (params instanceof TradeHistoryParamPaging) {
limit = ((TradeHistoryParamPaging) params).getPageLength();
}
String after = null;
if (params instanceof TradeHistoryParamsIdSpan) {
TradeHistoryParamsIdSpan tradeHistoryParamsIdSpan = (TradeHistoryParamsIdSpan) params;
after = tradeHistoryParamsIdSpan.getStartId();
}
String before = null;
if (params instanceof TradeHistoryParamsIdSpan) {
TradeHistoryParamsIdSpan tradeHistoryParamsIdSpan = (TradeHistoryParamsIdSpan) params;
before = tradeHistoryParamsIdSpan.getEndId();
}
CurrencyPair cp = null;
if (params instanceof TradeHistoryParamCurrencyPair) {
CurrencyPair paramsCp = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
if (paramsCp != null) {
cp = paramsCp;
}
}
List<BTCMarketsTradeHistoryResponse> response = getBTCMarketsUserTransactions(cp, before, after, limit);
return BTCMarketsAdapters.adaptTradeHistory(response);
}
use of org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan in project XChange by knowm.
the class MercadoBitcoinTradeService method getTradeHistory.
/**
* @param params Required parameter types: {@link TradeHistoryParamCurrencyPair}. Supported types:
* {@link TradeHistoryParamsIdSpan}, {@link TradeHistoryParamsTimeSpan}.
*/
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
CurrencyPair pair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
String fromId = null;
String toId = null;
if (params instanceof TradeHistoryParamsIdSpan) {
TradeHistoryParamsIdSpan paramsIdSpan = (TradeHistoryParamsIdSpan) params;
fromId = paramsIdSpan.getStartId();
toId = paramsIdSpan.getEndId();
}
Long fromDate = null;
Long toDate = null;
if (params instanceof TradeHistoryParamsTimeSpan) {
TradeHistoryParamsTimeSpan paramsTimeSpan = (TradeHistoryParamsTimeSpan) params;
fromDate = toUnixTimeNullSafe(paramsTimeSpan.getStartTime());
toDate = toUnixTimeNullSafe(paramsTimeSpan.getEndTime());
}
MercadoBitcoinBaseTradeApiResult<MercadoBitcoinUserOrders> orders = getMercadoBitcoinUserOrders(MercadoBitcoinAdapters.adaptCurrencyPair(pair), null, /* all */
null, fromId, toId, fromDate, toDate);
return MercadoBitcoinAdapters.toUserTrades(pair, orders);
}
use of org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan in project XChange by knowm.
the class TheRockTradeService method getTradeHistory.
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
if (!(params instanceof TradeHistoryParamCurrencyPair)) {
throw new ExchangeException("TheRock API recquires " + TradeHistoryParamCurrencyPair.class);
}
TradeHistoryParamCurrencyPair pairParams = (TradeHistoryParamCurrencyPair) params;
// get all trades starting from a specific trade_id
Long sinceTradeId = null;
if (params instanceof TradeHistoryParamsIdSpan) {
TradeHistoryParamsIdSpan trId = (TradeHistoryParamsIdSpan) params;
try {
sinceTradeId = Long.valueOf(trId.getStartId());
} catch (Throwable ignored) {
}
}
Date after = null;
Date before = null;
if (params instanceof TradeHistoryParamsTimeSpan) {
TradeHistoryParamsTimeSpan time = (TradeHistoryParamsTimeSpan) params;
after = time.getStartTime();
before = time.getEndTime();
}
int pageLength = 200;
int page = 0;
if (params instanceof TradeHistoryParamPaging) {
TradeHistoryParamPaging tradeHistoryParamPaging = (TradeHistoryParamPaging) params;
pageLength = tradeHistoryParamPaging.getPageLength();
page = tradeHistoryParamPaging.getPageNumber();
}
return TheRockAdapters.adaptUserTrades(getTheRockUserTrades(pairParams.getCurrencyPair(), sinceTradeId, after, before, pageLength, page), pairParams.getCurrencyPair());
}
use of org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan 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