Search in sources :

Example 1 with CoinmateWebsocketOpenOrder

use of info.bitrich.xchangestream.coinmate.v2.dto.CoinmateWebsocketOpenOrder 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);
}
Also used : Arrays(java.util.Arrays) CoinmateWebsocketOpenOrder(info.bitrich.xchangestream.coinmate.v2.dto.CoinmateWebsocketOpenOrder) UserTrades(org.knowm.xchange.dto.trade.UserTrades) UserTrade(org.knowm.xchange.dto.trade.UserTrade) StreamingObjectMapperHelper(info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) CoinmateWebSocketUserTrade(info.bitrich.xchangestream.coinmate.v2.dto.CoinmateWebSocketUserTrade) Order(org.knowm.xchange.dto.Order) List(java.util.List) JsonNode(com.fasterxml.jackson.databind.JsonNode) Observable(io.reactivex.Observable) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) TypeReference(com.fasterxml.jackson.core.type.TypeReference) StreamingTradeService(info.bitrich.xchangestream.core.StreamingTradeService) Collections(java.util.Collections) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) CoinmateWebsocketOpenOrder(info.bitrich.xchangestream.coinmate.v2.dto.CoinmateWebsocketOpenOrder) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) JsonNode(com.fasterxml.jackson.databind.JsonNode) List(java.util.List) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders)

Aggregations

TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 CoinmateWebSocketUserTrade (info.bitrich.xchangestream.coinmate.v2.dto.CoinmateWebSocketUserTrade)1 CoinmateWebsocketOpenOrder (info.bitrich.xchangestream.coinmate.v2.dto.CoinmateWebsocketOpenOrder)1 StreamingTradeService (info.bitrich.xchangestream.core.StreamingTradeService)1 StreamingObjectMapperHelper (info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper)1 Observable (io.reactivex.Observable)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)1 Order (org.knowm.xchange.dto.Order)1 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)1 UserTrade (org.knowm.xchange.dto.trade.UserTrade)1 UserTrades (org.knowm.xchange.dto.trade.UserTrades)1