C# 使用C语言创建实时股票报价#
我正在创建一个实时股票报价应用程序,它使用IEXAPI()获取实时信息。我想知道是否有比我现在拥有的更好的方法来投票这个URLC# 使用C语言创建实时股票报价#,c#,polling,stocks,C#,Polling,Stocks,我正在创建一个实时股票报价应用程序,它使用IEXAPI()获取实时信息。我想知道是否有比我现在拥有的更好的方法来投票这个URL 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
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));
}
}
}
}
}
你可能想看看他们是否有一个你可以订阅和观看的实时报价提要 当你不知道是否有什么变化的时候,继续询问特定股票的报价是非常低效的
你会在什么都没变的时候问,在事情变了的时候不必要地拖延。这不是一个确切的问题,对你来说也是如此。但有一件事我想指出的是,这是一个很好的方法,可以让你的网络充斥着流量,让API主机恼火。在两个请求之间没有任何延迟,所以您将把这件事做得非常好。可能需要在请求之间至少延迟几秒钟。
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; }
}