use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class CoinjarStreamingAdaptersTest method testAdaptUserTrade.
@Test
public void testAdaptUserTrade() {
CoinjarWebSocketUserTradeEvent.Payload.Fill fill = new CoinjarWebSocketUserTradeEvent.Payload.Fill("93.82", "2018-08-28T05:16:37.405702Z", 9130900, "0.01000000", "buy", "BTCAUD", "9382.00000000", 280117631, "taker");
CoinjarWebSocketUserTradeEvent.Payload payload = new CoinjarWebSocketUserTradeEvent.Payload(fill);
CoinjarWebSocketUserTradeEvent event = new CoinjarWebSocketUserTradeEvent("private", "private:fill", null, payload);
UserTrade userTrade = CoinjarStreamingAdapters.adaptUserTrade(event);
UserTrade expected = new UserTrade.Builder().id("9130900").orderId("280117631").currencyPair(CurrencyPair.BTC_AUD).originalAmount(new BigDecimal("0.01000000")).timestamp(Date.from(ZonedDateTime.parse("2018-08-28T05:16:37.405702Z").toInstant())).price(new BigDecimal("9382.00000000")).type(Order.OrderType.BID).build();
assertThat(userTrade).isEqualTo(expected);
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class KrakenStreamingTradeService method adaptKrakenUserTrade.
private List<UserTrade> adaptKrakenUserTrade(KrakenDtoUserTradeHolder[] ownTrades) {
List<UserTrade> result = new ArrayList<>();
for (KrakenDtoUserTradeHolder holder : ownTrades) {
for (Map.Entry<String, KrakenOwnTrade> entry : holder.entrySet()) {
String tradeId = entry.getKey();
KrakenOwnTrade dto = entry.getValue();
CurrencyPair currencyPair = new CurrencyPair(dto.pair);
result.add(new UserTrade.Builder().id(// The tradeId should be the key of the map, postxid can be null and is
tradeId).orderId(dto.ordertxid).currencyPair(currencyPair).timestamp(dto.time == null ? null : new Date((long) (dto.time * 1000L))).type(KrakenAdapters.adaptOrderType(KrakenType.fromString(dto.type))).price(dto.price).feeAmount(dto.fee).feeCurrency(currencyPair.counter).originalAmount(dto.vol).build());
}
}
return result;
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class LgoStreamingTradeServiceTest method it_handles_trades.
@Test
public void it_handles_trades() throws IOException, ParseException {
JsonNode snapshot = TestUtils.getJsonContent("/trade/user-trades-snapshot.json");
JsonNode update = TestUtils.getJsonContent("/trade/user-trades-update.json");
when(streamingService.subscribeChannel(anyString())).thenReturn(Observable.just(snapshot, update));
Observable<UserTrade> userTrades = service.getUserTrades(CurrencyPair.BTC_USD);
verify(streamingService).subscribeChannel("user-BTC-USD");
Date date = dateFormat.parse("2019-08-06T10:00:05.658Z");
ArrayList<UserTrade> trades = Lists.newArrayList(userTrades.blockingIterable());
assertThat(trades).hasSize(1);
assertThat(trades.get(0)).usingRecursiveComparison().isEqualTo(new UserTrade.Builder().type(Order.OrderType.ASK).originalAmount(new BigDecimal("0.50000000")).currencyPair(CurrencyPair.BTC_USD).price(new BigDecimal("955.3000")).timestamp(date).id("4441691").orderId("156508560418400001").feeAmount(new BigDecimal("0.2388")).feeCurrency(Currency.USD).build());
}
use of org.knowm.xchange.dto.trade.UserTrade 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;
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class GeminiAdapters method adaptTradeHistory.
public static UserTrades adaptTradeHistory(GeminiTradeResponse[] trades, String symbol) {
List<UserTrade> pastTrades = new ArrayList<>(trades.length);
CurrencyPair currencyPair = adaptCurrencyPair(symbol);
for (GeminiTradeResponse trade : trades) {
OrderType orderType = trade.getType().equalsIgnoreCase("buy") ? OrderType.BID : OrderType.ASK;
Date timestamp = convertBigDecimalTimestampToDate(trade.getTimestamp());
final BigDecimal fee = trade.getFeeAmount();
pastTrades.add(new UserTrade.Builder().type(orderType).originalAmount(trade.getAmount()).currencyPair(currencyPair).price(trade.getPrice()).timestamp(timestamp).id(trade.getTradeId()).orderId(trade.getOrderId()).feeAmount(fee).feeCurrency(Currency.getInstance(trade.getFeeCurrency())).build());
}
return new UserTrades(pastTrades, TradeSortType.SortByTimestamp);
}
Aggregations