2014-12-20 4 views
2

아래 기능을 사용하여 "Googl"에 대한 분 주식 데이터를 다운로드하려고합니다. 아래의 코드를 사용하여 C#으로 데이터를로드하고 CSV로 내보내는 것은 매일 발생하며 데이터는 인트라 - 데이가되고 싶습니다. 누구든지 내가 뭘 잘못하고 있는지 알 수 있니? 당신의 url 문자열의C#에서 분량의 주식 데이터를 추출하는 중

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

:

intervaltype 당신이 필요로하는 무엇을 = 매일

변경이.

+0

안녕 dymanoid! 따라서 "prices"변수의 내용도 데이터의 빈도에 영향을 미칩니다.이 부분은 "StartDate : DateTime.Today.AddDays (-7), EndDate : DateTime.Today.AddDays"입니다. 해당 부분을 변경하면 빈도가 변경되거나 URL 만 변경됩니까? – jessica

+0

웹 요청과 JSON 작업이 어떻게 작동하는지 더 잘 이해해야한다고 생각합니다. 웹 요청을 url로 서버에 보내면 요청 된 데이터를 제공하는 서버가 응답합니다. 따라서이 데이터는 URL 문자열을 통해 요청한 내용에 따라 다릅니다. 따라서 URL은 핵심 요소입니다. 서버에 "명령"이 포함되어 있습니다 : "나는 정확히 이것을 필요로합니다". 서버에 필요한 데이터를 지정하려면 URL 문자열을 신중하게 작성해야합니다. – dymanoid

관련 문제