当前位置: 首页>>代码示例>>C#>>正文


C# CarbonClient.GetTimeSeriesAsync方法代码示例

本文整理汇总了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");
                    }
                }

            }

        }
开发者ID:heimanhon,项目名称:researchwork,代码行数:39,代码来源:CarbonFunctionsTests.cs

示例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);
        }
//.........这里部分代码省略.........
开发者ID:heimanhon,项目名称:researchwork,代码行数:101,代码来源:BondMarket.cs

示例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;
      }
    }
开发者ID:heimanhon,项目名称:researchwork,代码行数:75,代码来源:CarbonHelper.cs


注:本文中的CarbonClient.GetTimeSeriesAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。