Creating Real-Time Stock Quotes Using C#
I'm creating a realtime stock quotes application that uses the IEX API (https://iextrading.com/developer/docs/) to get real time infomration. I'm wondering if there is a better way to poll this URL than what I currently have.
string Symbols = { "AAPL", "AMD" };
var Url = string.Format("https://api.iextrading.com/1.0/stock/market/batch?symbols={0}&types=quote", string.Join(",", Symbols));
using (var client = new HttpClient())
{
while (true)
{
using (var request = new HttpRequestMessage(HttpMethod.Get, Url))
{
using (var response = await client.SendAsync(request))
{
var stream = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
var r = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, Quote>>>(stream);
Console.WriteLine(JsonConvert.SerializeObject(r[Symbols[0]]["quote"].latestPrice));
}
}
}
}
}
What I currently have works fine, I'm just wondering if there is a better/more effecient way to do this.
My Quote Class
public class Quote
{
public string symbol { get; set; }
public string companyName { get; set; }
public string primaryExchange { get; set; }
public string sector { get; set; }
public string calculationPrice { get; set; }
public decimal? open { get; set; }
public decimal? openTime { get; set; }
public decimal? close { get; set; }
public decimal? closeTime { get; set; }
public decimal? high { get; set; }
public decimal? low { get; set; }
public decimal? latestPrice { get; set; }
public string latestSource { get; set; }
public string latestTime { get; set; }
public decimal? latestUpdate { get; set; }
public decimal? latestVolume { get; set; }
public decimal? iexRealtimePrice { get; set; }
public decimal? iexRealtimeSize { get; set; }
public decimal? iexLastUpdated { get; set; }
public decimal? delayedPrice { get; set; }
public decimal? delayedPriceTime { get; set; }
public decimal? extendedPrice { get; set; }
public decimal? extendedChange { get; set; }
public decimal? extendedChangePercent { get; set; }
public decimal? extendedPriceTime { get; set; }
public decimal? previousClose { get; set; }
public decimal? change { get; set; }
public decimal? changePercent { get; set; }
public decimal? iexMarketPercent { get; set; }
public decimal? iexVolume { get; set; }
public decimal? avgTotalVolume { get; set; }
public decimal? iexBidPrice { get; set; }
public decimal? iexBidSize { get; set; }
public decimal? iexAskPrice { get; set; }
public decimal? iexAskSize { get; set; }
public decimal? marketCap { get; set; }
public decimal? peRatio { get; set; }
public decimal? week52High { get; set; }
public decimal? week52Low { get; set; }
public decimal? ytdChange { get; set; }
}
c# polling stocks
add a comment |
I'm creating a realtime stock quotes application that uses the IEX API (https://iextrading.com/developer/docs/) to get real time infomration. I'm wondering if there is a better way to poll this URL than what I currently have.
string Symbols = { "AAPL", "AMD" };
var Url = string.Format("https://api.iextrading.com/1.0/stock/market/batch?symbols={0}&types=quote", string.Join(",", Symbols));
using (var client = new HttpClient())
{
while (true)
{
using (var request = new HttpRequestMessage(HttpMethod.Get, Url))
{
using (var response = await client.SendAsync(request))
{
var stream = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
var r = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, Quote>>>(stream);
Console.WriteLine(JsonConvert.SerializeObject(r[Symbols[0]]["quote"].latestPrice));
}
}
}
}
}
What I currently have works fine, I'm just wondering if there is a better/more effecient way to do this.
My Quote Class
public class Quote
{
public string symbol { get; set; }
public string companyName { get; set; }
public string primaryExchange { get; set; }
public string sector { get; set; }
public string calculationPrice { get; set; }
public decimal? open { get; set; }
public decimal? openTime { get; set; }
public decimal? close { get; set; }
public decimal? closeTime { get; set; }
public decimal? high { get; set; }
public decimal? low { get; set; }
public decimal? latestPrice { get; set; }
public string latestSource { get; set; }
public string latestTime { get; set; }
public decimal? latestUpdate { get; set; }
public decimal? latestVolume { get; set; }
public decimal? iexRealtimePrice { get; set; }
public decimal? iexRealtimeSize { get; set; }
public decimal? iexLastUpdated { get; set; }
public decimal? delayedPrice { get; set; }
public decimal? delayedPriceTime { get; set; }
public decimal? extendedPrice { get; set; }
public decimal? extendedChange { get; set; }
public decimal? extendedChangePercent { get; set; }
public decimal? extendedPriceTime { get; set; }
public decimal? previousClose { get; set; }
public decimal? change { get; set; }
public decimal? changePercent { get; set; }
public decimal? iexMarketPercent { get; set; }
public decimal? iexVolume { get; set; }
public decimal? avgTotalVolume { get; set; }
public decimal? iexBidPrice { get; set; }
public decimal? iexBidSize { get; set; }
public decimal? iexAskPrice { get; set; }
public decimal? iexAskSize { get; set; }
public decimal? marketCap { get; set; }
public decimal? peRatio { get; set; }
public decimal? week52High { get; set; }
public decimal? week52Low { get; set; }
public decimal? ytdChange { get; set; }
}
c# polling stocks
4
This isn't really the exact kind of question SO is for. But one thing I'd like to point out is this is a real good way to flood your network with traffic and piss off the API host. You don't have any delay in between requests so you are going to be plastering this thing pretty good. Probably want to put in at least a couple second delay between requests.
– Matti Price
Nov 13 '18 at 19:57
add a comment |
I'm creating a realtime stock quotes application that uses the IEX API (https://iextrading.com/developer/docs/) to get real time infomration. I'm wondering if there is a better way to poll this URL than what I currently have.
string Symbols = { "AAPL", "AMD" };
var Url = string.Format("https://api.iextrading.com/1.0/stock/market/batch?symbols={0}&types=quote", string.Join(",", Symbols));
using (var client = new HttpClient())
{
while (true)
{
using (var request = new HttpRequestMessage(HttpMethod.Get, Url))
{
using (var response = await client.SendAsync(request))
{
var stream = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
var r = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, Quote>>>(stream);
Console.WriteLine(JsonConvert.SerializeObject(r[Symbols[0]]["quote"].latestPrice));
}
}
}
}
}
What I currently have works fine, I'm just wondering if there is a better/more effecient way to do this.
My Quote Class
public class Quote
{
public string symbol { get; set; }
public string companyName { get; set; }
public string primaryExchange { get; set; }
public string sector { get; set; }
public string calculationPrice { get; set; }
public decimal? open { get; set; }
public decimal? openTime { get; set; }
public decimal? close { get; set; }
public decimal? closeTime { get; set; }
public decimal? high { get; set; }
public decimal? low { get; set; }
public decimal? latestPrice { get; set; }
public string latestSource { get; set; }
public string latestTime { get; set; }
public decimal? latestUpdate { get; set; }
public decimal? latestVolume { get; set; }
public decimal? iexRealtimePrice { get; set; }
public decimal? iexRealtimeSize { get; set; }
public decimal? iexLastUpdated { get; set; }
public decimal? delayedPrice { get; set; }
public decimal? delayedPriceTime { get; set; }
public decimal? extendedPrice { get; set; }
public decimal? extendedChange { get; set; }
public decimal? extendedChangePercent { get; set; }
public decimal? extendedPriceTime { get; set; }
public decimal? previousClose { get; set; }
public decimal? change { get; set; }
public decimal? changePercent { get; set; }
public decimal? iexMarketPercent { get; set; }
public decimal? iexVolume { get; set; }
public decimal? avgTotalVolume { get; set; }
public decimal? iexBidPrice { get; set; }
public decimal? iexBidSize { get; set; }
public decimal? iexAskPrice { get; set; }
public decimal? iexAskSize { get; set; }
public decimal? marketCap { get; set; }
public decimal? peRatio { get; set; }
public decimal? week52High { get; set; }
public decimal? week52Low { get; set; }
public decimal? ytdChange { get; set; }
}
c# polling stocks
I'm creating a realtime stock quotes application that uses the IEX API (https://iextrading.com/developer/docs/) to get real time infomration. I'm wondering if there is a better way to poll this URL than what I currently have.
string Symbols = { "AAPL", "AMD" };
var Url = string.Format("https://api.iextrading.com/1.0/stock/market/batch?symbols={0}&types=quote", string.Join(",", Symbols));
using (var client = new HttpClient())
{
while (true)
{
using (var request = new HttpRequestMessage(HttpMethod.Get, Url))
{
using (var response = await client.SendAsync(request))
{
var stream = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
var r = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, Quote>>>(stream);
Console.WriteLine(JsonConvert.SerializeObject(r[Symbols[0]]["quote"].latestPrice));
}
}
}
}
}
What I currently have works fine, I'm just wondering if there is a better/more effecient way to do this.
My Quote Class
public class Quote
{
public string symbol { get; set; }
public string companyName { get; set; }
public string primaryExchange { get; set; }
public string sector { get; set; }
public string calculationPrice { get; set; }
public decimal? open { get; set; }
public decimal? openTime { get; set; }
public decimal? close { get; set; }
public decimal? closeTime { get; set; }
public decimal? high { get; set; }
public decimal? low { get; set; }
public decimal? latestPrice { get; set; }
public string latestSource { get; set; }
public string latestTime { get; set; }
public decimal? latestUpdate { get; set; }
public decimal? latestVolume { get; set; }
public decimal? iexRealtimePrice { get; set; }
public decimal? iexRealtimeSize { get; set; }
public decimal? iexLastUpdated { get; set; }
public decimal? delayedPrice { get; set; }
public decimal? delayedPriceTime { get; set; }
public decimal? extendedPrice { get; set; }
public decimal? extendedChange { get; set; }
public decimal? extendedChangePercent { get; set; }
public decimal? extendedPriceTime { get; set; }
public decimal? previousClose { get; set; }
public decimal? change { get; set; }
public decimal? changePercent { get; set; }
public decimal? iexMarketPercent { get; set; }
public decimal? iexVolume { get; set; }
public decimal? avgTotalVolume { get; set; }
public decimal? iexBidPrice { get; set; }
public decimal? iexBidSize { get; set; }
public decimal? iexAskPrice { get; set; }
public decimal? iexAskSize { get; set; }
public decimal? marketCap { get; set; }
public decimal? peRatio { get; set; }
public decimal? week52High { get; set; }
public decimal? week52Low { get; set; }
public decimal? ytdChange { get; set; }
}
c# polling stocks
c# polling stocks
asked Nov 13 '18 at 19:55
BeLEEverBeLEEver
12618
12618
4
This isn't really the exact kind of question SO is for. But one thing I'd like to point out is this is a real good way to flood your network with traffic and piss off the API host. You don't have any delay in between requests so you are going to be plastering this thing pretty good. Probably want to put in at least a couple second delay between requests.
– Matti Price
Nov 13 '18 at 19:57
add a comment |
4
This isn't really the exact kind of question SO is for. But one thing I'd like to point out is this is a real good way to flood your network with traffic and piss off the API host. You don't have any delay in between requests so you are going to be plastering this thing pretty good. Probably want to put in at least a couple second delay between requests.
– Matti Price
Nov 13 '18 at 19:57
4
4
This isn't really the exact kind of question SO is for. But one thing I'd like to point out is this is a real good way to flood your network with traffic and piss off the API host. You don't have any delay in between requests so you are going to be plastering this thing pretty good. Probably want to put in at least a couple second delay between requests.
– Matti Price
Nov 13 '18 at 19:57
This isn't really the exact kind of question SO is for. But one thing I'd like to point out is this is a real good way to flood your network with traffic and piss off the API host. You don't have any delay in between requests so you are going to be plastering this thing pretty good. Probably want to put in at least a couple second delay between requests.
– Matti Price
Nov 13 '18 at 19:57
add a comment |
1 Answer
1
active
oldest
votes
You might want to see if they have a live quote feed you can just subscribe to and watch.
It's astonishingly inefficient to keep asking for quotes for specific stocks when you don't know if anything has actually changed.
You'll be asking when nothing has changed and delaying unnecessarily when things have changed.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288553%2fcreating-real-time-stock-quotes-using-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You might want to see if they have a live quote feed you can just subscribe to and watch.
It's astonishingly inefficient to keep asking for quotes for specific stocks when you don't know if anything has actually changed.
You'll be asking when nothing has changed and delaying unnecessarily when things have changed.
add a comment |
You might want to see if they have a live quote feed you can just subscribe to and watch.
It's astonishingly inefficient to keep asking for quotes for specific stocks when you don't know if anything has actually changed.
You'll be asking when nothing has changed and delaying unnecessarily when things have changed.
add a comment |
You might want to see if they have a live quote feed you can just subscribe to and watch.
It's astonishingly inefficient to keep asking for quotes for specific stocks when you don't know if anything has actually changed.
You'll be asking when nothing has changed and delaying unnecessarily when things have changed.
You might want to see if they have a live quote feed you can just subscribe to and watch.
It's astonishingly inefficient to keep asking for quotes for specific stocks when you don't know if anything has actually changed.
You'll be asking when nothing has changed and delaying unnecessarily when things have changed.
answered Nov 13 '18 at 19:59
Terry CarmenTerry Carmen
2,5391818
2,5391818
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288553%2fcreating-real-time-stock-quotes-using-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
This isn't really the exact kind of question SO is for. But one thing I'd like to point out is this is a real good way to flood your network with traffic and piss off the API host. You don't have any delay in between requests so you are going to be plastering this thing pretty good. Probably want to put in at least a couple second delay between requests.
– Matti Price
Nov 13 '18 at 19:57