use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.
the class dydxStreamingService method getRawWebsocketTransactions.
/**
* Creates an observable of a channel using the baseChannelName and currencyPair. For example,
* subscribing to the trades channel for WETH/USDC will create a new channel "trades-WETH-USDC".
*
* @param currencyPair any currency pair supported by dydx
* @param baseChannelName e.g. "orderbook", "v3_orderbook", etc.
* @return
*/
public Observable<dydxWebSocketTransaction> getRawWebsocketTransactions(CurrencyPair currencyPair, String baseChannelName) {
final ObjectMapper mapper = StreamingObjectMapperHelper.getObjectMapper();
String currencyPairChannelName = String.format("%s-%s", baseChannelName, currencyPair.toString().replace('/', '-'));
return subscribeChannel(currencyPairChannelName, currencyPair).map(msg -> {
switch(baseChannelName) {
case V1_ORDERBOOK:
case V3_ORDERBOOK:
return handleOrderbookMessage(currencyPairChannelName, objectMapper, msg);
}
return mapper.readValue(msg.toString(), dydxWebSocketTransaction.class);
}).filter(t -> currencyPair.equals(new CurrencyPair(t.getId()))).filter(t -> baseChannelName.equals(t.getChannel()));
}
use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.
the class FtxStreamingAdapters method adaptOrders.
public static Order adaptOrders(JsonNode jsonNode) {
JsonNode data = jsonNode.get("data");
LimitOrder.Builder order = new LimitOrder.Builder("buy".equals(data.get("side").asText()) ? Order.OrderType.BID : Order.OrderType.ASK, new CurrencyPair(data.get("market").asText())).id(data.get("id").asText()).timestamp(Date.from(Instant.now())).limitPrice(data.get("price").decimalValue()).originalAmount(data.get("size").decimalValue()).userReference(data.get("clientId").asText()).remainingAmount(data.get("remainingSize").decimalValue()).averagePrice(data.get("avgFillPrice").decimalValue()).orderStatus(Order.OrderStatus.valueOf(data.get("status").asText().toUpperCase()));
if (data.get("ioc").asBoolean())
order.flag(FtxOrderFlags.IOC);
if (data.get("postOnly").asBoolean())
order.flag(FtxOrderFlags.POST_ONLY);
if (data.get("reduceOnly").asBoolean())
order.flag(FtxOrderFlags.REDUCE_ONLY);
return order.build();
}
use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.
the class FtxStreamingMarketDataService method getOrderBook.
@Override
public Observable<OrderBook> getOrderBook(CurrencyPair currencyPair, Object... args) {
OrderBook orderBook = new OrderBook(null, Lists.newArrayList(), Lists.newArrayList());
String channelName = "orderbook:" + FtxAdapters.adaptCurrencyPairToFtxMarket(currencyPair);
return service.subscribeChannel(channelName).map(res -> {
try {
return FtxStreamingAdapters.adaptOrderbookMessage(orderBook, currencyPair, res);
} catch (IllegalStateException e) {
LOG.warn("Resubscribing {} channel after adapter error {}", currencyPair, e.getMessage());
orderBook.getBids().clear();
orderBook.getAsks().clear();
// Resubscribe to the channel
this.service.sendMessage(service.getUnsubscribeMessage(channelName, args));
this.service.sendMessage(service.getSubscribeMessage(channelName, args));
return new OrderBook(null, Lists.newArrayList(), Lists.newArrayList(), false);
}
}).filter(ob -> ob.getBids().size() > 0 && ob.getAsks().size() > 0);
}
use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.
the class CoinmateStreamingTradeService method getOrderChanges.
@Override
public Observable<Order> getOrderChanges(CurrencyPair currencyPair, Object... args) {
String channelName = "private-open_orders-" + coinmateStreamingService.getUserId() + "-" + CoinmateStreamingAdapter.getChannelPostfix(currencyPair);
ObjectReader reader = StreamingObjectMapperHelper.getObjectMapper().readerFor(CoinmateWebsocketOpenOrder.class);
return coinmateStreamingService.subscribeChannel(channelName, true).map((message) -> {
JsonNode payload = message.get("payload");
List<CoinmateWebsocketOpenOrder> websocketOpenOrders;
if (payload.isArray()) {
websocketOpenOrders = Arrays.asList(reader.readValue(payload, CoinmateWebsocketOpenOrder[].class));
} else {
websocketOpenOrders = Collections.singletonList(reader.readValue(payload, CoinmateWebsocketOpenOrder.class));
}
return CoinmateStreamingAdapter.adaptWebsocketOpenOrders(websocketOpenOrders, currencyPair);
}).concatMapIterable(OpenOrders::getAllOpenOrders);
}
use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.
the class CoinmateStreamingTradeService method getUserTrades.
@Override
public Observable<UserTrade> getUserTrades(CurrencyPair currencyPair, Object... args) {
String channelName = "private-user-trades-" + coinmateStreamingService.getUserId() + "-" + CoinmateStreamingAdapter.getChannelPostfix(currencyPair);
ObjectReader reader = StreamingObjectMapperHelper.getObjectMapper().readerFor(new TypeReference<List<CoinmateWebSocketUserTrade>>() {
});
return coinmateStreamingService.subscribeChannel(channelName, true).map((message) -> {
List<CoinmateWebSocketUserTrade> webSocketUserTrades = reader.readValue(message.get("payload"));
return CoinmateStreamingAdapter.adaptWebSocketUserTrades(webSocketUserTrades, currencyPair);
}).concatMapIterable(UserTrades::getUserTrades);
}
Aggregations