public virtual async Task <CallResult <UpdateSubscription> > SubscribeToTickersAsync(Action <ParibuSocketTicker> onTickerData, Action <ParibuSocketPriceSeries> onPriceSeriesData) { var internalHandler = new Action <DataEvent <ParibuSocketResponse> >(data => { var json = JsonConvert.DeserializeObject <SocketPatch <SocketMerge <SocketTickers> > >(data.Data.Data); foreach (var ticker in json.Patch.Merge.Data) { if (ticker.Value.PriceSeries != null && ticker.Value.PriceSeries.Count() > 0) { onPriceSeriesData(new ParibuSocketPriceSeries { Symbol = ticker.Key, Prices = ticker.Value.PriceSeries, }); } else { ticker.Value.Symbol = ticker.Key; onTickerData(ticker.Value); } } }); var request = new ParibuSocketRequest <ParibuSocketSubscribeRequest> { Event = "pusher:subscribe", Data = new ParibuSocketSubscribeRequest { Auth = "", Channel = "prb-public" } }; return(await SubscribeAsync(request, null, false, internalHandler).ConfigureAwait(false)); }
public virtual async Task <CallResult <UpdateSubscription> > SubscribeToMarketDataAsync(string symbol, Action <ParibuSocketOrderBook> onOrderBookData, Action <ParibuSocketTrade> onTradeData) { var internalHandler = new Action <DataEvent <ParibuSocketResponse> >(data => { var patch = JsonConvert.DeserializeObject <SocketPatch <object> >(data.Data.Data); if (patch.Index == "orderBook") { var pob = new ParibuSocketOrderBook { Symbol = symbol }; var json = JsonConvert.DeserializeObject <SocketPatch <SocketMerge <SocketOrderBook> > >(data.Data.Data.Replace(",\"merge\":[],", ",\"merge\":{},")); if (json.Patch.Merge.Asks != null && json.Patch.Merge.Asks.Data != null && json.Patch.Merge.Asks.Data.Count > 0) { foreach (var ask in json.Patch.Merge.Asks.Data) { pob.AsksToAdd.Add(new ParibuSocketOrderBookEntry { Price = ask.Key, Amount = ask.Value }); } } if (json.Patch.Merge.Bids != null && json.Patch.Merge.Bids.Data != null && json.Patch.Merge.Bids.Data.Count > 0) { foreach (var bid in json.Patch.Merge.Bids.Data) { pob.BidsToAdd.Add(new ParibuSocketOrderBookEntry { Price = bid.Key, Amount = bid.Value }); } } if (json.Patch.Unset != null && json.Patch.Unset.Count() > 0) { foreach (var unset in json.Patch.Unset) { var unsetrow = unset.Split('/'); if (unsetrow.Length == 2) { if (unsetrow[0] == "buy") { pob.BidsToRemove.Add(new ParibuSocketOrderBookEntry { Price = unsetrow[1].ToDecimal(), Amount = 0.0m }); } if (unsetrow[0] == "sell") { pob.AsksToRemove.Add(new ParibuSocketOrderBookEntry { Price = unsetrow[1].ToDecimal(), Amount = 0.0m }); } } } } onOrderBookData(pob); } else if (patch.Index == "marketMatches") { var json = JsonConvert.DeserializeObject <SocketPatch <SocketMerge <IEnumerable <ParibuSocketTrade> > > >(data.Data.Data); foreach (var trade in json.Patch.Merge) { trade.Symbol = symbol; onTradeData(trade); } } }); var request = new ParibuSocketRequest <ParibuSocketSubscribeRequest> { Event = "pusher:subscribe", Data = new ParibuSocketSubscribeRequest { Auth = "", Channel = "prb-market-" + symbol.ToLower() } }; return(await SubscribeAsync(request, null, false, internalHandler).ConfigureAwait(false)); }