use of org.knowm.xchange.exmo.dto.trade.ExmoUserTrades 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.exmo.dto.trade.ExmoUserTrades in project XChange by knowm.
the class ExmoTradeService method getOrder.
@Override
public /**
* Warning: this make multiple api requests (one per parameter) so may result in you exceeding
* your api limits
*/
Collection<Order> getOrder(OrderQueryParams... orderQueryParams) throws IOException {
List<Order> results = new ArrayList<>();
for (OrderQueryParams orderQueryParam : orderQueryParams) {
String orderId = orderQueryParam.getOrderId();
Order.OrderType type = null;
CurrencyPair currencyPair = null;
String id = null;
Date timestamp = null;
BigDecimal totalValue = BigDecimal.ZERO;
BigDecimal cumulativeAmount = BigDecimal.ZERO;
BigDecimal fee = BigDecimal.ZERO;
Order.OrderStatus status = Order.OrderStatus.UNKNOWN;
ExmoUserTrades exmoUserTrades = userTrades(orderId);
if (exmoUserTrades == null)
continue;
BigDecimal originalAmount = exmoUserTrades.getOriginalAmount();
for (UserTrade userTrade : exmoUserTrades.getUserTrades()) {
type = userTrade.getType();
currencyPair = userTrade.getCurrencyPair();
id = userTrade.getOrderId();
if (timestamp == null)
timestamp = userTrade.getTimestamp();
if (timestamp.getTime() < userTrade.getTimestamp().getTime())
timestamp = userTrade.getTimestamp();
BigDecimal amountForFill = userTrade.getOriginalAmount();
BigDecimal priceForFill = userTrade.getPrice();
BigDecimal value = amountForFill.multiply(priceForFill);
cumulativeAmount = cumulativeAmount.add(amountForFill);
totalValue = totalValue.add(value);
}
BigDecimal averagePrice = totalValue.divide(cumulativeAmount, 8, RoundingMode.HALF_UP);
Order order = new MarketOrder(type, originalAmount, currencyPair, id, timestamp, averagePrice, cumulativeAmount, fee, status);
results.add(order);
}
return results;
}
Aggregations