本文整理汇总了C#中CarbonClient.GetTimeSeriesAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CarbonClient.GetTimeSeriesAsync方法的具体用法?C# CarbonClient.GetTimeSeriesAsync怎么用?C# CarbonClient.GetTimeSeriesAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CarbonClient
的用法示例。
在下文中一共展示了CarbonClient.GetTimeSeriesAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldGetMinuteDataFromCarbon
public void ShouldGetMinuteDataFromCarbon()
{
using (var carbonClient = new CarbonClient("PRD"))
{
var atTime = new TimeSpan(0, 14, 15);
var options = new TimeSeriesOptions { AtTime = atTime };
// specify explicitly UTC time
var start = new DateTime(2012, 4, 1, 0, 0, 0, DateTimeKind.Utc);
var end = new DateTime(2016, 3, 1, 0, 0, 0, DateTimeKind.Utc);
DateTime now = DateTime.Now;
var intra = carbonClient.GetTimeSeriesAsync("FVH6 Comdty", "intra", start, end, options).Result;
//var intra = carbonClient.GetTimeSeriesAsync(new[]{"FVU6 Comdty","FVM6 Comdty","FVH6 Comdty","FVZ15 Comdty","FVU15 Comdty","FVM15 Comdty","FVH15 Comdty"}, "intra", start, end, options).Result;
Console.WriteLine(string.Format("get time series intra taken {0}s", (DateTime.Now - now).TotalSeconds));
now = DateTime.Now;
intra = carbonClient.GetTimeSeriesAsync("FVZ15 Comdty", "intra", start, end, options).Result;
//intra = carbonClient.GetTimeSeriesAsync(new[] { "FVU6 Comdty", "FVM6 Comdty", "FVH6 Comdty", "FVZ15 Comdty", "FVU15 Comdty", "FVM15 Comdty", "FVH15 Comdty" }, "intra", start, end, options).Result;
Console.WriteLine(string.Format("get time series intra taken {0}s", (DateTime.Now - now).TotalSeconds));
now = DateTime.Now;
intra = carbonClient.GetTimeSeriesAsync("FVH6 Comdty", "intra", start, end, options).Result;
Console.WriteLine(string.Format("get time series intra taken {0}s", (DateTime.Now - now).TotalSeconds));
foreach (var row in intra)
{
var ticker = row.Identifier;
foreach (var series in row.Series)
{
// these are nullable and only present if data was provided
var bid = series.GetDouble("highBid");
var ask = series.GetDouble("highAsk");
var time = series.GetDateTime("timeStamp");
}
}
}
}
示例2: populate
private async Task populate(CarbonClient cc_)
{
await populateDates(cc_);
// at the moment, carbon can't give me the list of cmt bonds for 'today' so need to get as of yesterday
var bonds =
await
cc_.GetTimeSeriesAsync(Market.CarbonName(), "cmt-bonds", Yesterday.AsOf);
//var blah =
// await cc_.GetTimeSeriesAsync("US7YT=TWEB", "Snap", null, null, new TimeSeriesOptions {IdentifierType = "RIC"});
if (!bonds.Any())
{
Logger.Error(
string.Format("Did not get any response from carbon asking for cmt-bonds for market {0}", Market.CarbonName()),
typeof (BondMarket));
return;
}
MessagePackObject mpo;
if (bonds[0].Series[0].TryGetValue("cmtBonds", out mpo) == false || !mpo.IsList)
return;
var bondDict = new Dictionary<string, Bond>();
foreach (var v in mpo.AsList())
{
var dict = v.AsDictionary();
var bond = new Bond
{
OwningMarket = this,
};
foreach (var key in dict.Keys)
{
switch (key.AsString())
{
case "isin":
bond.Isin = dict[key].AsString();
break;
case "term":
bond.Term = dict[key].AsDouble();
break;
case "aswyylambda":
bond.ASWyyLambda = dict[key].AsDouble();
break;
case "yieldlamda":
bond.YieldLambda = dict[key].AsDouble();
break;
case "zspreadlambda":
bond.ZSpreadLambda = dict[key].AsDouble();
break;
}
}
if (!string.IsNullOrEmpty(bond.Isin))
{
bondDict[bond.Isin] = bond;
}
}
m_bonds = bondDict;
// need to get some more static data about the bonds
var dateSetups = new[]
{
new Tuple<string, Action<Bond, DateTime>>("maturityDt", (bs, date) => bs.Maturity = date),
new Tuple<string, Action<Bond, DateTime>>("issueDt", (bs, date) => bs.IssueDate= date),
new Tuple<string, Action<Bond, DateTime>>("firstCpnDt", (bs, date) => bs.FirstCouponDate= date),
new Tuple<string, Action<Bond, DateTime>>("effectiveDt", (bs, date) => bs.EffectiveDate= date),
};
var dblSetups = new[]
{
new Tuple<string, Action<Bond, double>>("cpnRate", (bs, dbl) => bs.Coupon = dbl),
};
var statics = await cc_.GetStaticDataAsync(m_bonds.Keys, "static-bond");
foreach (var s in statics)
{
var isin = s.Identifier;
Bond bs;
if (m_bonds.TryGetValue(isin, out bs) == false)
continue;
DateTime dt;
foreach (var setup in dateSetups)
{
var strVal = s.Properties.GetString(setup.Item1);
if (DateTime.TryParseExact(strVal, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
setup.Item2(bs, dt);
}
//.........这里部分代码省略.........
示例3: getFromCarbon
private static async Task getFromCarbon(IEnumerable<string> possibleIdentifiers_, IDictionary<RelativeDate, Line> values_, RDDateIndex[] dateIndexes_, DisplayTimeZone zone_, DayField valueField_, DayField volumeField_, CarbonClient cc_)
{
var startDate = dateIndexes_.Select(x => x.Date).Min().AddDays(-3d);
var endDate = dateIndexes_.Select(x => x.Date).Max().AddDays(1d);
var result = await cc_.GetTimeSeriesAsync(possibleIdentifiers_, "intra", startDate, endDate);
if (result == null)
{
Logger.Info(
string.Format("Could not get results back from carbon for tickers=[{0}], with startdate={1} and enddate={2}",
string.Join(",", possibleIdentifiers_),
startDate.ToString("dd-MMM-yyyy"),
endDate.ToString("dd-MMM-yyyy")), typeof (CarbonHelper));
return;
}
foreach (var id in possibleIdentifiers_)
{
var set = result.FirstOrDefault(x => x.Identifier.Equals(id));
if (set == null) continue;
foreach (var row in set.Series)
{
// need to have timestamp and price in order to be a value row...
if (
!row.ContainsKey(CarbonFields.TimeStamp)
|| !row.ContainsKey(CarbonFields.CloseAsk)
|| !row.ContainsKey(CarbonFields.CloseBid))
continue;
var tsGMTstr = row.GetString(CarbonFields.TimeStamp);
DateTime tsGMT;
if (!DateTime.TryParseExact(tsGMTstr, "yyyyMMdd HHmmss.fff", CultureInfo.InvariantCulture,DateTimeStyles.None, out tsGMT))
continue;
// convert gmt to the timezone that we're interested in
var tsTZ = tsGMT.ToTZfromGMT(zone_);
// create a relative date object so we can check if we need this line
var rd = new RelativeDate(dateIndexes_, tsTZ, zone_);
if (rd.Index == RelativeDate.INVALID_INDEX)
continue;
var closeBid = row.GetDouble(CarbonFields.CloseBid);
var closeAsk = row.GetDouble(CarbonFields.CloseAsk);
if (!closeBid.HasValue || !closeAsk.HasValue || closeBid.Value.IsZero() || closeAsk.Value.IsZero())
continue;
var closeMid = (closeBid.Value + closeAsk.Value)/2d;
if (!values_.ContainsKey(rd))
values_[rd] = new Line { GMTDateTime = tsGMT.ToString(Line.MongoDateFormat) };
double volume = 0d;
if (row.ContainsKey(CarbonFields.Volume))
{
var vol = row.GetDouble(CarbonFields.Volume);
volume = vol ?? 0d;
}
values_[rd].SetValue(valueField_, closeMid);
values_[rd].SetValue(volumeField_, volume);
}
// if one of the tickers returned values for the given start/end date, then we don't need to consider the next one
break;
}
}