use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.
the class YoBitMarketDataService method getTrades.
public Trades getTrades(PublicTradesRequestParams params) throws IOException {
if (params instanceof MultiCurrencyPublicTradesDataRequestParams) {
MultiCurrencyPublicTradesDataRequestParams multiCurrencyPublicTradesDataRequestParams = (MultiCurrencyPublicTradesDataRequestParams) params;
YoBitTrades publicTrades = getPublicTrades(multiCurrencyPublicTradesDataRequestParams.currencyPairs);
List<Trade> all = new ArrayList<>();
Map<String, List<YoBitTrade>> tradesByCcyPair = publicTrades.getTrades();
for (String ccyPair : tradesByCcyPair.keySet()) {
CurrencyPair currencyPair = YoBitAdapters.adaptCurrencyPair(ccyPair);
List<Trade> trades = YoBitAdapters.adaptTrades(tradesByCcyPair.get(ccyPair), currencyPair).getTrades();
all.addAll(trades);
}
Collections.sort(all, new Comparator<Trade>() {
@Override
public int compare(Trade a, Trade b) {
return a.getTimestamp().compareTo(b.getTimestamp());
}
});
return new Trades(all, Trades.TradeSortType.SortByID);
}
throw new IllegalStateException("Don't understand " + params);
}
use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.
the class BTCTradeAdapters method adaptTrades.
public static Trades adaptTrades(BTCTradeTrade[] btcTradeTrades, CurrencyPair currencyPair) {
int length = btcTradeTrades.length;
List<Trade> trades = new ArrayList<>(length);
for (BTCTradeTrade btcTradeTrade : btcTradeTrades) {
trades.add(adaptTrade(btcTradeTrade, currencyPair));
}
long lastID = length > 0 ? btcTradeTrades[length - 1].getTid() : 0L;
return new Trades(trades, lastID, TradeSortType.SortByID);
}
use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.
the class BTCTradeAdaptersTest method testAdaptTradesBTCTradeTradeArrayCurrencyPair.
@Test
public void testAdaptTradesBTCTradeTradeArrayCurrencyPair() throws IOException {
BTCTradeTrade[] btcTradeTrades = mapper.readValue(getClass().getResource("dto/marketdata/trades.json"), BTCTradeTrade[].class);
Trades trades = BTCTradeAdapters.adaptTrades(btcTradeTrades, CurrencyPair.BTC_CNY);
List<Trade> tradeList = trades.getTrades();
assertEquals(new Date(1403397140L * 1000L), tradeList.get(0).getTimestamp());
assertEquals(new BigDecimal("3703"), tradeList.get(0).getPrice());
assertEquals(new BigDecimal("3.50000000000"), tradeList.get(0).getOriginalAmount());
assertEquals("2895575", tradeList.get(0).getId());
assertEquals(OrderType.BID, tradeList.get(0).getType());
assertEquals(new Date(1403397191L * 1000L), tradeList.get(1).getTimestamp());
assertEquals(new BigDecimal("3704"), tradeList.get(1).getPrice());
assertEquals(new BigDecimal("0.00200000000"), tradeList.get(1).getOriginalAmount());
assertEquals("2895576", tradeList.get(1).getId());
assertEquals(OrderType.BID, tradeList.get(1).getType());
assertEquals(new Date(1403428819L * 1000L), tradeList.get(tradeList.size() - 2).getTimestamp());
assertEquals(new BigDecimal("3740.01"), tradeList.get(tradeList.size() - 2).getPrice());
assertEquals(new BigDecimal("0.01000000000"), tradeList.get(tradeList.size() - 2).getOriginalAmount());
assertEquals("2896235", tradeList.get(tradeList.size() - 2).getId());
assertEquals(OrderType.ASK, tradeList.get(tradeList.size() - 2).getType());
assertEquals(new Date(1403428797L * 1000L), tradeList.get(tradeList.size() - 1).getTimestamp());
assertEquals(new BigDecimal("3752"), tradeList.get(tradeList.size() - 1).getPrice());
assertEquals(new BigDecimal("16.70000000000"), tradeList.get(tradeList.size() - 1).getOriginalAmount());
assertEquals("2896239", tradeList.get(tradeList.size() - 1).getId());
assertEquals(OrderType.BID, tradeList.get(tradeList.size() - 1).getType());
}
use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.
the class YoBitTradeDemo method main.
public static void main(String[] args) throws IOException {
Exchange yoBitExchange = ExchangeFactory.INSTANCE.createExchange(YoBitExchange.class);
// Interested in the public market data feed (no authentication)
MarketDataService marketDataService = yoBitExchange.getMarketDataService();
System.out.println("fetching data...");
Trades trades = marketDataService.getTrades(CurrencyPair.BTC_USD);
System.out.println("received data.");
for (Trade trade : trades.getTrades()) {
System.out.println(trade.getType() + " " + trade.getCurrencyPair() + " Price: " + trade.getPrice() + " Amount: " + trade.getOriginalAmount());
}
}
use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.
the class OkCoinStreamingMarketDataService method getTrades.
/**
* #### spot #### 4. ok_sub_spot_X_deals 订阅成交记录
*
* <p>#### future #### 5. ok_sub_futureusd_X_trade_Y 订阅合约交易信息 5. ok_sub_futureusd_X_trade_Y
* Subscribe Contract Trade Record
*
* @param currencyPair Currency pair of the trades
* @param args the first arg {@link FuturesContract}
* @return
*/
@Override
public Observable<Trade> getTrades(CurrencyPair currencyPair, Object... args) {
String channel = String.format("ok_sub_spot_%s_%s_deals", currencyPair.base.toString().toLowerCase(), currencyPair.counter.toString().toLowerCase());
if (args.length > 0) {
FuturesContract contract = (FuturesContract) args[0];
channel = String.format("ok_sub_future%s_%s_trade_%s", currencyPair.counter.toString().toLowerCase(), currencyPair.base.toString().toLowerCase(), contract.getName());
}
return service.subscribeChannel(channel).map(s -> {
String[][] trades = mapper.treeToValue(s.get("data"), String[][].class);
// I don't know how to parse this array of arrays in Jacson.
OkCoinWebSocketTrade[] okCoinTrades = new OkCoinWebSocketTrade[trades.length];
for (int i = 0; i < trades.length; ++i) {
OkCoinWebSocketTrade okCoinWebSocketTrade = new OkCoinWebSocketTrade(trades[i]);
okCoinTrades[i] = okCoinWebSocketTrade;
}
return OkCoinAdapters.adaptTrades(okCoinTrades, currencyPair);
}).flatMapIterable(Trades::getTrades);
}
Aggregations