Esempio n. 1
0
    public async Task PopulateData(CarbonClient cc_)
    {
      var data = await cc_.GetStaticDataAsync(identifier: Identifier);

      if (data == null || data.Count == 0) return;

      foreach (var kvp in data[0].Properties)
      {
        switch (kvp.Key)
        {
          case "desc":
            Description = kvp.Value.AsString();
            break;
          case "firstTradeDt":
            FirstTrade = DateTime.ParseExact(kvp.Value.AsString(), "yyyyMMdd", CultureInfo.InvariantCulture);
            break;
          case "lastTradeDt":
            LastTrade = DateTime.ParseExact(kvp.Value.AsString(), "yyyyMMdd", CultureInfo.InvariantCulture);
            break;
          case "firstNoticeDt":
            FirstNotice = DateTime.ParseExact(kvp.Value.AsString(), "yyyyMMdd", CultureInfo.InvariantCulture);
            break;
          case "expirationDt":
            Expiration = DateTime.ParseExact(kvp.Value.AsString(), "yyyyMMdd", CultureInfo.InvariantCulture);
            break;
          case "lastDeliveryDt":
            LastDelivery = DateTime.ParseExact(kvp.Value.AsString(), "yyyyMMdd", CultureInfo.InvariantCulture);
            break;
        }
      }
    }
    public async Task populateData(CarbonClient cc_)
    {
      var data =
        await
          cc_.GetStaticDataAsync(
            identifier: Identifier,
            type: "futures_chains",
            options: new Options {IdentifierType = IdentifierType});

      if (data == null || data.Count==0 ) return;

      if (data[0].Properties != null)
      {
        foreach (var item in data[0].Properties)
        {
          switch (item.Key)
          {
            case "desc":
              Description = item.Value.AsString();
              break;
            case "exch":
              Exchange = item.Value.AsString();
              break;
            case "bbgStart":
              BbgStart = item.Value.AsString();
              break;
            case "bbgSuffix":
              BbgEnd = item.Value.AsString();
              break;
            case "ricChain":
              RicChain = item.Value.AsString();
              break;
          }
        }
      }

      if (data[0].Series != null)
      {
        m_contracts =
          (from item in data[0].Series where item.ContainsKey("ident") select new CarbonFuture(item["ident"].AsString()))
            .ToList();
      }
    }
Esempio n. 3
0
    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);
        }

        foreach (var setup in dblSetups)
        {
          var dblVal = s.Properties.GetDouble(setup.Item1);
          if (dblVal.HasValue)
            setup.Item2(bs, dblVal.Value);
        }
      }

      var histPrices =
        await cc_.GetTimeSeriesAsync(m_bonds.Keys, Market.CarbonCloseSnapCollection(), DateTime.Today.AddMonths(-2));

      foreach (var v in histPrices.Where(x=>x.Series!=null))
      {
        var isin = v.Identifier;

        Bond bs;
        if (m_bonds.TryGetValue(isin, out bs) == false)
          continue;

        var px = new SortedDictionary<DateTime, double>();

        foreach (var obj in v.Series.Where(x=>x.ContainsKey("close") && x.ContainsKey("date")))
        {
          var strVal = obj.GetString("date");
          DateTime dt;
          double? dblVal;

          if (DateTime.TryParseExact(strVal, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)
            && (dblVal = obj.GetDouble("close")).HasValue)
            px[dt] = dblVal.Value;
        }

        if (px.Count > 0)
          bs.HistoricPrices = new DatedDataCollectionGen<double>(px.Keys.ToArray(), px.Values.ToArray());


        Logger.Debug(v.Series.ToString(), typeof (BondMarket));
      }


      m_priceSub = cc_.SubscribeToMarketData(m_bonds.Keys.ToList(),handlePriceCallback);
    }