从C#代码访问输出

从C#代码访问输出,c#,C#,我在VS2013中用C#运行这段代码,我从这里得到:。代码应该从我的TD Ameritrade 401k帐户收集数据。代码运行正常,但下面代码输出的数据保存在哪里?如何访问它 namespace TDAmeritrade.Samples { using System; using TDAmeritrade; class Program { static void Main() { // Initialize

我在VS2013中用C#运行这段代码,我从这里得到:。代码应该从我的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);   
}

至于保存到文件,没有任何地方。然而,您正在用股票报价填写
报价
错误
获取这些报价时遇到的任何错误,
符号
我假设有一个
列表
符号匹配
*GOO*
,并且
价格
与七天前到昨天的历史价格相匹配。然而,一旦程序完成,它们就不在范围之内,必须再次检索

要保存它们,您需要将它们保存到一个文件或创建一个数据库来存放信息。

在新的API中,“Quotes”和“Quote”响应是一个回调。如果需要流式处理,则需要使用更复杂的函数并发送异步回调。
而且:

它正在被保存。。。在变量中?谢谢matti,我不知道如何访问变量。有没有办法保存为csv?谢谢,所以没有直接的方法从C#访问数据?你的图书馆会允许的。有没有办法让其他软件(如python)抓取数据以绘制图表?将响应作为JSON保存到文本文档并从python中读取是一个可行的解决方案?将其导入python的理想方式是什么?嗨,Aydin,我最近安装了python.Net。这样行吗?我不知道如何使用java。问题是我不知道给定价目表的对象结构。。。如果存在嵌套对象,导出为CSV格式可能会产生问题。。。相反,我建议您将响应保存为JSON格式,并使用python读取响应。稍后我将更新我的答案,告诉您如何将从api检索到的响应保存到硬盘。至于从python中再次阅读,您必须创建一个新问题,python开发人员应该能够回答这个问题address@jessica为您更新它,希望它能引导您走向正确的方向。谢谢JR。您认为我可以将这些数据加载到Python中进行绘图吗,等等?我能想到的将信息传递给Python的唯一方法是以某种方式保存信息,然后让Python访问存储的信息。如果您试图访问此应用程序使用的内存(我甚至认为这是不可能的),您将得到一个异常。