繁体   English   中英

使用C#创建实时股票报价

[英]Creating Real-Time Stock Quotes Using C#

我正在创建一个使用IEX API( https://iextrading.com/developer/docs/ )的实时股票报价应用程序,以获取实时信息。 我想知道是否有比我目前更好的方法来轮询此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 (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));

                        }
                    }
                }
            }
        }

我目前所拥有的一切都很好,我只是想知道是否有更好/更有效的方法来做到这一点。

我的报价单

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; }
}

您可能想看看他们是否有实时报价供稿,您可以订阅并观看。

当您不知道是否有任何实际变化时,不断询问特定股票的报价效率非常低。

您会问什么都没有改变,而事情发生了不必要的延迟。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM