-
Notifications
You must be signed in to change notification settings - Fork 37
SSE Streaming Example
Victor Lee edited this page Jan 14, 2021
·
7 revisions
To use SSE streaming (only included with paid IEX subscription plans)
- Note that both
IEXCloudClient
andSSEClient
areIDisposable
, so they should both be wrapped inusing()
statements
using IEXSharp;
using IEXSharp.Helper;
using IEXSharp.Model.CoreData.StockPrices.Request;
using System;
using System.Threading.Tasks;
namespace IEXSharpTestConsole
{
class Program
{
static void Main(string[] args)
{
using (var iexCloudClient = new IEXCloudClient("publishableToken", "secretToken",
signRequest: false, useSandBox: true))
using (var sseClient = iexCloudClient.StockPrices.QuoteStream(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 += (s, quoteList) =>
{
foreach (var quote in quoteList)
{
Console.WriteLine(quote.ToString());
}
};
Task T = sseClient.StartAsync(); // get task w/o awaiting so that it does not block
Console.WriteLine("example work"); // do some work
Console.WriteLine("hit enter to finish");
Console.ReadLine(); // now block until ready to stop streaming
sseClient.Close(); // now finished, so stop streaming
}
}
}
}