Пример #1
0
    public static void Go()
    {
      var ctList = SI.Strategy.CTDs.Generator.Go();

      var listOfMissing = new List<MonthYear>();

      foreach (var v in ctList)
      {
        if (v.CT2 == null || v.CT3 == null || v.CT5 == null || v.CT7 == null || v.CT10 == null || v.CT30 == null)
          if (!listOfMissing.Contains(v.RefundingMonth))
          {
            Logger.Debug(string.Format("Missing bonds for {0}", v.RefundingMonth), typeof(UpdateCTBondData));
            listOfMissing.Add(v.RefundingMonth);
          }
      }
      System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3;

      try
      {
        var cred = ServiceHelpers.GetCredentials();

        using (var dc = SymmetryDataSource.ReadOnly())
        {
          using (var dsClient = new ExtractionServiceClient())
          {
            var isins = new Dictionary<string, ValidatedInstrument>();

            foreach (var v in listOfMissing)
            {
              var request = new SearchInstrumentsRequest
              {
                CredentialsHeader = cred,
                request = new InstrumentSearchRequestGovCorp
                {
                  IdentifierType = "ISN",
                  IdentifierSearchValue = "US9128*",
                  PreferredIdentifierType = "ISN",
                  IsGovernmentGroup = true,
                  IssueDatePrimaryValue = new DateTime(v.Year, v.Month, 3),
                  IssueDateSecondaryValue = new DateTime(v.Year, v.Month, 25),
                  IssueDateComparisonOperator = "FROM",
                }
              };

              var response = dsClient.SearchInstruments(request);

              Array.ForEach(response.SearchInstrumentsResult.Instruments.Select(x => x.IdentifierValue).Distinct().ToArray(), (x) => Logger.Debug(x, typeof(UpdateCTBondData)));

              foreach (var validatedInstrument in response.SearchInstrumentsResult.Instruments)
              {
                var isin = validatedInstrument.IdentifierValue;

                if (isins.ContainsKey(isin))
                {
                  if (validatedInstrument.Source.Equals("TWB"))
                    isins[isin] = validatedInstrument;
                  continue;
                }

                var fi = FIHelpers.GetFIBySymmetryCode(isin, dc, Symmetry.Core.ThrowBehavior.DontThrow);

                if (fi == null)
                  isins.Add(isin, validatedInstrument);
              }
            }

            if (isins.Count == 0)
              return;

            {
              var request = new ExtractRequest
              {
                CredentialsHeader = cred,
                request = new InstrumentExtractionRequestTermsAndConditions
                {
                  Instruments = isins.ToList().Select(x => x.Value).ToArray(),
                  OutputFields = Enum.GetNames(typeof(FieldsToReturn))
                    .Select(x => typeof(FieldsToReturn).GetField(x.ToString()))
                    .Select(x => x.GetCustomAttribute<RSSFieldAttribute>().FieldName).ToArray()
                }
              };

              var response = dsClient.Extract(request);

              var pivoted = ExtractionUtility.PivotExtractionResult(response.ExtractResult.Columns, response.ExtractResult.RowCount, response.ExtractResult.Messages);

              StringBuilder b = new StringBuilder();
              b.AppendLine(ServiceHelpers.ToCsvLine(pivoted.ColumnNames));
              foreach (var row in pivoted.Rows)
              {
                b.AppendLine(ServiceHelpers.ToCsvLine(row));
              }

              var path = @"e:\temp\missingBonds.csv";
              FileInfo i = new FileInfo(path);

              StreamWriter writer = i.CreateText();
              writer.Write(b.ToString());
              writer.Close();
            }

          }
        }
      }
      catch (Exception ex_)
      {
        Logger.Error("blast", typeof(UpdateCTBondData), ex_);
      }
    }
    protected override ReutersDSS.Service.ValidatedInstrument[] getValidatedInstruments(Data.SymmetryEntities dc_, ReutersDSS.Service.ExtractionServiceClient dsClient_, ReutersDSS.Service.CredentialsHeader credentials_)
    {
      // get the config document

      var config = BondDiscoveryConfig.GetInstance();

      if (config == null || config.Countries == null)
      {
        Symmetry.Core.SLog.log.Fatal("Could not load BondDiscoveryConfig instance");
        return null;
      }


      var isinToValidatedInstrument = new Dictionary<string, ValidatedInstrument>();

      foreach(var countryItem in config.Countries)
      {
        foreach(var subGroupItem in countryItem.Items)
        {
          // build up request
          var request = new SearchInstrumentsRequest
          {
            CredentialsHeader = credentials_,
            request = new InstrumentSearchRequestGovCorp
            {
              IdentifierType = "ISN",
              IdentifierSearchValue = subGroupItem.SearchString ?? "*",
              PreferredIdentifierType = "ISN",
              IsGovernmentGroup = true,
              CountryType=countryItem.CountryCode,

              IssueDatePrimaryValue = DateTime.Today.Add(-m_lookBackPeriodForSearch),
              IssueDateSecondaryValue = DateTime.Today.Add(m_lookBackPeriodForSearch),
              IssueDateComparisonOperator = "FROM",

              SubGroupType = subGroupItem.AssetSubGroup
            }
          };

          SearchInstrumentsResponse response;

          // do it
          try
          {
            response = dsClient_.SearchInstruments(request);
          }
          catch
          {
            response = null;
          }

          if (response == null || response.SearchInstrumentsResult == null || response.SearchInstrumentsResult.Instruments == null)
            continue;

          // go through each ValidatedInstrument pulling out ISINs,
          // as there are multiple brokers, isin may appear more than once

          foreach (var validatedInstrument in response.SearchInstrumentsResult.Instruments)
          {
            var isin = validatedInstrument.IdentifierValue;

            if (isinToValidatedInstrument.ContainsKey(isin))
            {
              // even if we know about it already, prefer tradeweb as a source
              if(validatedInstrument.Source.Equals("TWB"))
                isinToValidatedInstrument[isin]=validatedInstrument;

              continue;
            }

            // do we know about it already?
            var fi = FIHelpers.GetFIBySymmetryCode(isin,dc_,ThrowBehavior.DontThrow);

            // if we don't then want to include it in our list of bonds to add to the database
            if (fi == null)
            {
              SLog.log.Debug(string.Format("New bond to add: ISIN = {0}", isin));
              isinToValidatedInstrument.Add(isin, validatedInstrument);
            }
          }
        }
      }

      return isinToValidatedInstrument.Select(x => x.Value).ToArray();
    }
    protected override ReutersDSS.Service.ValidatedInstrument[] getValidatedInstruments(Data.SymmetryEntities dc_, ReutersDSS.Service.ExtractionServiceClient dsClient_, ReutersDSS.Service.CredentialsHeader credentials_)
    {
      var isinToValidatedInstrument = new Dictionary<string, ValidatedInstrument>();

      foreach (var isn in m_isins)
      {
        // do we know about it already?
        var fi = FIHelpers.GetFIBySymmetryCode(isn, dc_, ThrowBehavior.DontThrow);

        if (fi != null)
        {
          SLog.log.Debug(string.Format("Bond with Isin={0} already exists in database", isn));
          continue;
        }

        var request = new SearchInstrumentsRequest
        {
          CredentialsHeader = credentials_,
          request = new InstrumentSearchRequestGovCorp
          {
            IdentifierType = "ISN",
            IdentifierSearchValue = string.Format("{0}", isn),
            PreferredIdentifierType = "ISN",
          }
        };

        SearchInstrumentsResponse response;

        // do it
        try
        {
          response = dsClient_.SearchInstruments(request);
        }
        catch
        {
          response = null;
        }

        if (response == null || response.SearchInstrumentsResult == null || response.SearchInstrumentsResult.Instruments == null)
          continue;

        // go through each ValidatedInstrument pulling out ISINs,
        // as there are multiple brokers, isin may appear more than once

        foreach (var validatedInstrument in response.SearchInstrumentsResult.Instruments)
        {
          var isin = validatedInstrument.IdentifierValue;

          if (isinToValidatedInstrument.ContainsKey(isin))
          {
            // even if we know about it already, prefer tradeweb as a source
            if (validatedInstrument.Source.Equals("TWB"))
              isinToValidatedInstrument[isin] = validatedInstrument;

            continue;
          }


          SLog.log.Debug(string.Format("New bond to add: ISIN = {0}", isin));
          isinToValidatedInstrument.Add(isin, validatedInstrument);
        }
      }
      return isinToValidatedInstrument.Select(x => x.Value).ToArray();
    }