[英]Accessing Output From C# Code
我正在VS2013中的C#中运行此代码,该代码是从http://tda.codeplex.com/获得的 。 该代码应该从我的TD Ameritrade 401k帐户收集数据。 代码运行正常,但是下面代码输出的数据保存在哪里? 如何访问?
namespace TDAmeritrade.Samples
{
using System;
using TDAmeritrade;
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("jessicasusername", "jessicaspassword");
// 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(-1));
}
}
}
更新:将此代码放在下面 :
PM> Install-Package Newtonsoft.Json
// Change the file path to wherever you wish to save the results
const string SaveFileToLocation = @"C:\Users\jessica\Desktop\json_data";
string json = JsonConvert.SerializeObject(prices, Formatting.Indented);
using (StreamWriter writer = new StreamWriter(SaveFileToLocation))
{
writer.Write(json);
}
它并没有在任何地方保存数据,上述所有代码所做的就是检索指定的符号并将响应存储为变量名的prices
var prices = client.GetHistoricalPrices("GOOG, AAPL", StartDate: DateTime.Today.AddDays(-7), EndDate: DateTime.Today.AddDays(-1));
如果您想要一种快速简便的方法来将检索到的数据显示到控制台窗口,则可以使用我开发的库,该库托管在NuGet上。
PM> Install-Package DebugUtilities
编辑
要将结果导出到文本文件,首先需要使用NuGet软件包管理器安装另一个软件包。
PM> Install-Package Newtonsoft.Json
安装完上述库后,可以使用下面的代码保存到所需的任何位置。
// Change the file path to wherever you wish to save the results
const string SaveFileToLocation = @"C:\Dev\test.json";
string json = JsonConvert.SerializeObject(prices, Formatting.Indented);
using (StreamWriter writer = new StreamWriter(SaveFileToLocation))
{
writer.Write(json);
}
至于保存到文件,无处。 然而,你正在填补quotes
与股票行情, errors
在获得这些报价中遇到的任何错误, symbols
与我假设一个List<string>
符号匹配的*GOO*
,并且prices
通过事先与历史价格由七天昨天。 但是,一旦程序完成,这些将超出范围,必须再次进行检索。
要保存它们,您要么需要将它们保存到文件中,要么创建数据库来容纳信息。
在新的API中,“ Quotes”和“ Quote”响应是单个回调。 如果要进行流传输,则需要使用更复杂的https://developer.tdameritrade.com/content/streaming-data并发送异步回调。 和: https : //developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest/Synchronous_and_Asynchronous_Requests
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.