use of org.knowm.xchange.service.trade.params.TradeHistoryParamOffset 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.TradeHistoryParamOffset in project XChange by knowm.
the class ExmoTradeService method getTradeHistory.
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
Integer limit = 10000;
Long offset = 0L;
List<CurrencyPair> currencyPairs = new ArrayList<>();
if (params instanceof ExmoTradeHistoryParams) {
ExmoTradeHistoryParams exmoTradeHistoryParams = (ExmoTradeHistoryParams) params;
currencyPairs.addAll(exmoTradeHistoryParams.getCurrencyPairs());
} else if (params instanceof TradeHistoryParamCurrencyPair) {
TradeHistoryParamCurrencyPair tradeHistoryParamCurrencyPair = (TradeHistoryParamCurrencyPair) params;
currencyPairs.add(tradeHistoryParamCurrencyPair.getCurrencyPair());
}
if (params instanceof TradeHistoryParamLimit) {
limit = ((TradeHistoryParamLimit) params).getLimit();
}
if (params instanceof TradeHistoryParamOffset) {
offset = ((TradeHistoryParamOffset) params).getOffset();
}
List<UserTrade> trades = trades(limit, offset, currencyPairs);
return new UserTrades(trades, Trades.TradeSortType.SortByTimestamp);
}
use of org.knowm.xchange.service.trade.params.TradeHistoryParamOffset in project XChange by knowm.
the class HitbtcTradeService method getTradeHistory.
/**
* Required parameters: {@link TradeHistoryParamPaging} {@link TradeHistoryParamCurrencyPair}
*/
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
Integer limit = 1000;
long offset = 0;
if (params instanceof TradeHistoryParamLimit) {
limit = ((TradeHistoryParamLimit) params).getLimit();
}
if (params instanceof TradeHistoryParamOffset) {
TradeHistoryParamOffset tradeHistoryParamOffset = (TradeHistoryParamOffset) params;
offset = tradeHistoryParamOffset.getOffset();
}
String symbol = null;
if (params instanceof TradeHistoryParamCurrencyPair) {
CurrencyPair pair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
symbol = HitbtcAdapters.adaptCurrencyPair(pair);
}
List<HitbtcOwnTrade> tradeHistoryRaw = getTradeHistoryRaw(symbol, limit, offset);
return HitbtcAdapters.adaptTradeHistory(tradeHistoryRaw);
}
use of org.knowm.xchange.service.trade.params.TradeHistoryParamOffset in project XChange by knowm.
the class HitbtcAccountService method getFundingHistory.
@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
List<HitbtcTransaction> transactions;
String currencyCode = null;
Integer limit = 1000;
Integer offset = 0;
if (params instanceof TradeHistoryParamCurrency) {
Currency currency = ((TradeHistoryParamCurrency) params).getCurrency();
currencyCode = currency != null ? currency.getCurrencyCode() : null;
}
if (params instanceof TradeHistoryParamLimit) {
limit = ((TradeHistoryParamLimit) params).getLimit();
}
if (params instanceof TradeHistoryParamOffset) {
offset = ((TradeHistoryParamOffset) params).getOffset().intValue();
}
transactions = getTransactions(currencyCode, limit, offset);
List<FundingRecord> records = new ArrayList<>();
for (HitbtcTransaction transaction : transactions) {
records.add(HitbtcAdapters.adapt(transaction));
}
return records;
}
use of org.knowm.xchange.service.trade.params.TradeHistoryParamOffset in project XChange by knowm.
the class LivecoinAccountService method getFundingHistory.
@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
try {
Date start = new Date(0);
Date end = new Date();
if (params instanceof TradeHistoryParamsTimeSpan) {
TradeHistoryParamsTimeSpan tradeHistoryParamsTimeSpan = (TradeHistoryParamsTimeSpan) params;
start = tradeHistoryParamsTimeSpan.getStartTime();
end = tradeHistoryParamsTimeSpan.getEndTime();
}
Long offset = 0L;
if (params instanceof TradeHistoryParamOffset) {
offset = ((TradeHistoryParamOffset) params).getOffset();
}
Integer limit = 100;
if (params instanceof TradeHistoryParamLimit) {
limit = ((TradeHistoryParamLimit) params).getLimit();
}
List<Map> fundingRaw = funding(start, end, limit, offset);
return fundingRaw.stream().map(LivecoinAdapters::adaptFundingRecord).collect(Collectors.toList());
} catch (LivecoinException e) {
throw LivecoinErrorAdapter.adapt(e);
}
}
Aggregations