Skip to content

SSE Streaming Example

Victor Lee edited this page May 23, 2020 · 7 revisions

To use SSE streaming (only included with paid IEX subscription plans)

Note that both IEXCloudClient and SSEClient are IDisposable, so they should both be wrapped in using() statements

using (var iexCloudClient = new IEXCloudClient("publishableToken", "secretToken", 
	signRequest: false, useSandBox: false))
using (var sseClient = iexCloudClient.StockPrices.SubscribeStockQuotesUS(symbols: 
	new string[] { "spy", "aapl" }, UTP: false, interval: StockQuoteSSEInterval.OneSecond))
{
	sseClient.Error += (s, e) =>
	{
		Console.WriteLine("Error Occurred. Details: {0}", e.Exception.Message);
	};
	sseClient.MessageReceived += m =>
	{
		Console.WriteLine(m.ToString());
	};
	Task T = sseClient.StartAsync(); // get task w/o awaiting so that it does not block
	Console.WriteLine("example work"); // do some work
	Console.ReadLine("hit enter to finish"); // now block until ready to stop streaming
	sseClient.Close(); // now finished, so stop streaming
}
Clone this wiki locally