use of org.knowm.xchange.dto.trade.UserTrade 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.dto.trade.UserTrade in project XChange by knowm.
the class ExmoTradeServiceRaw method trades.
public List<UserTrade> trades(Integer limit, Long offset, Collection<CurrencyPair> currencyPairs) {
List<String> markets = new ArrayList<>();
for (CurrencyPair currencyPair : currencyPairs) {
markets.add(ExmoAdapters.format(currencyPair));
}
Map<String, List<Map<String, String>>> map = exmo.userTrades(signatureCreator, apiKey, exchange.getNonceFactory(), join(markets, ","), offset, limit);
List<UserTrade> trades = new ArrayList<>();
for (String market : map.keySet()) {
for (Map<String, String> tradeDatum : map.get(market)) {
trades.add(ExmoAdapters.adaptTrade(tradeDatum, adaptMarket(market)));
}
}
Collections.sort(trades, (o1, o2) -> o2.getTimestamp().compareTo(o1.getTimestamp()));
return trades;
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class ExmoTradeServiceRaw method userTrades.
public ExmoUserTrades userTrades(String orderId) {
Map<String, Object> map = exmo.orderTrades(signatureCreator, apiKey, exchange.getNonceFactory(), orderId);
List<UserTrade> userTrades = new ArrayList<>();
Boolean result = (Boolean) map.get("result");
if (result != null && !result)
return null;
BigDecimal originalAmount = new BigDecimal(map.get("out_amount").toString());
for (Map<String, Object> tradeDatum : (List<Map<String, Object>>) map.get("trades")) {
CurrencyPair market = adaptMarket(tradeDatum.get("pair").toString());
Map<String, String> bodge = new HashMap<>();
for (String key : tradeDatum.keySet()) {
bodge.put(key, tradeDatum.get(key).toString());
}
userTrades.add(ExmoAdapters.adaptTrade(bodge, market));
}
return new ExmoUserTrades(originalAmount, userTrades);
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class LunoTradeService method getTradeHistory.
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws ExchangeException, IOException {
if (!(params instanceof TradeHistoryParamCurrencyPair)) {
throw new ExchangeException("THe currency pair is mandatory in order to get user trades.");
}
CurrencyPair currencyPair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
Long since = null;
if (params instanceof TradeHistoryParamsTimeSpan) {
since = ((TradeHistoryParamsTimeSpan) params).getStartTime().getTime();
}
Integer limit = null;
if (params instanceof TradeHistoryParamLimit) {
limit = ((TradeHistoryParamLimit) params).getLimit();
}
LunoUserTrades lunoTrades = lunoAPI.listTrades(LunoUtil.toLunoPair(currencyPair), since, limit);
List<UserTrade> trades = new ArrayList<>();
for (org.knowm.xchange.luno.dto.trade.LunoUserTrades.UserTrade t : lunoTrades.getTrades()) {
final CurrencyPair pair = LunoUtil.fromLunoPair(t.pair);
// currently there is no trade id!
final String tradeId = null;
final BigDecimal feeAmount;
final Currency feeCurrency;
if (t.feeBase.compareTo(BigDecimal.ZERO) > 0) {
feeAmount = t.feeBase;
feeCurrency = pair.base;
} else {
feeAmount = t.feeCounter;
feeCurrency = pair.counter;
}
trades.add(new UserTrade.Builder().type(t.buy ? OrderType.BID : OrderType.ASK).originalAmount(t.volume).currencyPair(pair).price(t.price).timestamp(t.getTimestamp()).id(tradeId).orderId(t.orderId).feeAmount(feeAmount).feeCurrency(feeCurrency).build());
}
return new UserTrades(trades, TradeSortType.SortByTimestamp);
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class TheRockAdapters method adaptUserTrades.
public static UserTrades adaptUserTrades(TheRockUserTrades trades, CurrencyPair currencyPair) {
List<UserTrade> tradesList = new ArrayList<>(trades.getCount());
long lastTradeId = 0;
for (int i = 0; i < trades.getCount(); i++) {
TheRockUserTrade trade = trades.getTrades()[i];
long tradeId = trade.getId();
if (tradeId > lastTradeId)
lastTradeId = tradeId;
tradesList.add(adaptUserTrade(trade, currencyPair));
}
return new UserTrades(tradesList, lastTradeId, Trades.TradeSortType.SortByID);
}
Aggregations