C# 在C语言中提取股票分钟数据#
使用下面的功能,我试图下载“谷歌”的分钟股票数据。使用下面的代码,我将数据加载到c#中,然后将其导出到csv中,每天都会出现,我希望数据是在一天之内。有人能看出我做错了什么吗C# 在C语言中提取股票分钟数据#,c#,C#,使用下面的功能,我试图下载“谷歌”的分钟股票数据。使用下面的代码,我将数据加载到c#中,然后将其导出到csv中,每天都会出现,我希望数据是在一天之内。有人能看出我做错了什么吗 public OHLCQuoteCollection GetHistoricalPrices(string symbol, DateTime StartDate = new DateTime(), DateTime EndDate = new DateTime()) { var url = ServiceURL +
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);
}
}
}
}
公共OHLCQuoteCollection GetHistoricalPrices(字符串符号,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”);
返回InvokeWebRequest(url);
}
名称空间TDAmeritrade.Samples
{
使用制度;
利用贸易;
使用Newtonsoft.Json;
使用System.IO;
班级计划
{
静态void Main()
{
//初始化TD Ameritrade客户端,必要时提供其他配置信息
var client=new TDAClient();
//使用您的用户ID和密码登录TD Ameritrade网站
client.LogIn(“杰西卡用户名”、“杰西卡密码”);
//现在,“client.User”属性包含有关当前登录用户的所有信息
var accountName=client.User.Account.DisplayName;
//获取股票报价快照。
var quotes=client.GetQuotes(“GOOG,AAPL,$SPX.X,DUMMY”);
//“quotes.Error”包含尚未找到的符号列表
var errors=quotes.errors;
//查找与搜索字符串匹配的符号
变量符号=client.FindSymbols(“GOO”);
//获取历史价格
var prices=client.GetHistoricalPrices(“GOOG,AAPL”,起始日期:DateTime.Today.AddDays(-7),结束日期:DateTime.Today.AddDays);
//将“价格”输出打印到csv文件中
const string SaveFileToLocation=@“C:\Users\jessicannstrada\Desktop\json\u data\myfile.csv”;
字符串json=JsonConvert.SerializedObject(价格、格式、缩进);
使用(StreamWriter writer=newstreamwriter(SaveFileToLocation))
{
Write.Write(json);
}
}
}
}
在您的
url
字符串中:
间隔类型=每日
将此更改为您需要的任何内容。嘿,dymanoid!那么“prices”变量中的任何内容是否也会对数据的频率产生影响呢?namley这部分是“StartDate:DateTime.Today.AddDays(-7),EndDate:DateTime.Today.AddDays”。更改其中任何一部分是否会改变频率,或者只是URL?我想您需要更好地了解web请求和json内容是如何工作的。您将web请求作为url发送到服务器,服务器会响应您提供请求的数据。因此,这些数据取决于您通过url字符串请求的内容。因此url是关键——它包含服务器的“命令”:“我需要这个”。您应该仔细构建url字符串,以指定服务器需要哪些数据。