gpt4 book ai didi

c# - 在 C# 中提取分钟股票数据

转载 作者:太空宇宙 更新时间:2023-11-03 13:13:10 25 4
gpt4 key购买 nike

使用下面的函数,我正在尝试下载“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);
}


}
}
}

最佳答案

那在你的 url 字符串中:

intervaltype=DAILY

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

关于c# - 在 C# 中提取分钟股票数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27583130/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com