2 回答
TA贡献1877条经验 获得超6个赞
从下面的代码中,您将能够在现有的勾选列表中添加结果列表,并且它还允许您将列表放置在您选择的位置。
public static List<RootObject> minuteAggregateList = new List<RootObject>();
public void historicalMinuteAggData(string symbol)
{
int daysCount = 0;
for(int i=1; i<=20; i++)
{
DateTime date = DateTime.Now.Date.AddDays(-i);
if (date.DayOfWeek != DayOfWeek.Saturday && date.DayOfWeek != DayOfWeek.Sunday)
{
daysCount++;
var startUnixTime = (date.Add(new TimeSpan(13, 30, 00)).Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
var endUnixTime = (date.Add(new TimeSpan(20, 00, 00)).Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
using (var reader = new StreamReader(new WebClient().OpenRead(string.Format("API For Fetch Data"))))
{
var x = reader.ReadLine();
RootObject data = JsonConvert.DeserializeObject<RootObject>(x);
if (chk != null)
{
minuteAggregateList.Single(q => q.ticker == symbol).results.InsertRange(0, data.results);
}
else
minuteAggregateList.Add(data);
}
}
if (daysCount == 7)
break;
}
}
TA贡献1794条经验 获得超7个赞
在将数据添加到列表之前,需要检查相同的代码值。
public static List<RootObject> minuteAggregateList = new List<RootObject>();
public void historicalMinuteAggData(string symbol)
{
int daysCount = 0;
for(int i=1; i<=20; i++)
{
DateTime date = DateTime.Now.Date.AddDays(-i);
if (date.DayOfWeek != DayOfWeek.Saturday && date.DayOfWeek != DayOfWeek.Sunday)
{
daysCount++;
var startUnixTime = (date.Add(new TimeSpan(13, 30, 00)).Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
var endUnixTime = (date.Add(new TimeSpan(20, 00, 00)).Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
using (var reader = new StreamReader(new WebClient().OpenRead(string.Format("API For Fetch Data"))))
{
var x = reader.ReadLine();
RootObject data = JsonConvert.DeserializeObject<RootObject>(x);
if(minuteAggregateList.Any(node => node.ticker == data.ticker))
{
minuteAggregateList.Where(node => node.ticker == data.ticker)
.Select(val => {
val.results.AddRange(data.results);
return val;
}).ToList();
}
else
{
minuteAggregateList.Add(data);
}
}
}
if (daysCount == 7)
break;
}
}
要将数据添加到匹配列表,首先需要选择匹配的代码(即使用Where())。而不是在Select()添加结果数据之后。之后,需要使用 . 将更改应用于现有列表ToList()。
- 2 回答
- 0 关注
- 114 浏览
添加回答
举报