-
Notifications
You must be signed in to change notification settings - Fork 37
SSE Streaming Example
Victor Lee edited this page Jun 3, 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.QuotesStream(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
}