在C#中提取分钟库存数据

时间:2014-12-20 18:32:55

标签: c#

使用下面的功能,我正在尝试下载" Googl"的分钟库存数据。使用下面的代码,我将数据加载到c#然后将其导出到csv每天出来,我希望数据在日内。谁能看到我做错了什么?

public OHLCQuoteCollection GetHistoricalPrices(string symbol, DateTime StartDate = new DateTime(), DateTime EndDate = new DateTime())
{
    var url = ServiceURL + "PriceHistory?source=" + Uri.EscapeDataString(AppKey) + "&requestidentifiertype=SYMBOL&requestvalue=" + Uri.EscapeDataString(symbol) +
        "&intervaltype=DAILY&intervalduration=1&startdate=" + StartDate.ToString("yyyyMMdd") + "&enddate=" + EndDate.ToString("yyyyMMdd");

    return InvokeWebRequest<OHLCQuoteCollection>(url);
}



namespace TDAmeritrade.Samples
{
    using System;
    using TDAmeritrade;
    using Newtonsoft.Json;
    using System.IO;

    class Program
    {

        static void Main()
        {
            // Initialize TD Ameritrade client, provide additional config info if needed
            var client = new TDAClient();

            // Log in to the TD Ameritrade website with your user ID and password
            client.LogIn("jessiausername", "jessicapassword");

            // Now 'client.User' property contains all the information about currently logged in user
            var accountName = client.User.Account.DisplayName;

            // Get stock quotes snapshot.
            var quotes = client.GetQuotes("GOOG, AAPL, $SPX.X, DUMMY");

            // 'quotes.Error' contains a list of symbols which have not been found
            var errors = quotes.Errors;

            // Find symbols matching the search string
            var symbols = client.FindSymbols("GOO");

            // Get historical prices
            var prices = client.GetHistoricalPrices("GOOG, AAPL", StartDate: DateTime.Today.AddDays(-7), EndDate: DateTime.Today.AddDays);

            //Print output of "prices" into a csv file

            const string SaveFileToLocation = @"C:\Users\JessicaAnnStrada\Desktop\json_data\myfile.csv";
            string json = JsonConvert.SerializeObject(prices, Formatting.Indented);
            using (StreamWriter writer = new StreamWriter(SaveFileToLocation))
            {
                writer.Write(json);
            }


        }
    }
}

1 个答案:

答案 0 :(得分:1)

那是在你的url字符串中:

  

intervaltype = DAILY

将此更改为您需要的任何内容。