Ценовой центр НРД

Ценовой центр НРД – это автоматизированная система оценки справедливых цен облигаций и других финансовых инструментов, рассчитанных по Методике НРД

GetAssetholders

Отчет о доле инвестиций различных инвесторов в ОФЗ, рассчитанной с использованием данных об остатках на счетах в НРД

Скачать описание

-
Название Тип Описание Обяз.
Выберите нужные вам поля (раскрыть все)
date string Да
asset_type string Да
method string Да
calculation_currency string Да
nominee object Да
total_share_pct number Да
total_share_cash number Да
nominee_and_banks object Да
total_share_pct number Да
total_share_cash number Да
details [array] Да
date string Да
isin string Да
nsd_code string Да
nominee object Да
share_pct number Да
share_cash number Да
nominee_and_banks object Да
share_pct number Да
share_cash number Да
Скачать

{
  "type": "array",
  "items": [
    {
      "type": "object",
      "properties": {
        "date": {
          "type": "string"
        },
        "asset_type": {
          "type": "string"
        },
        "method": {
          "type": "string"
        },
        "calculation_currency": {
          "type": "string"
        },
        "nominee": {
          "type": "object",
          "properties": {
            "total_share_pct": {
              "type": "number"
            },
            "total_share_cash": {
              "type": "number"
            }
          },
          "required": [
            "total_share_pct",
            "total_share_cash"
          ]
        },
        "nominee_and_banks": {
          "type": "object",
          "properties": {
            "total_share_pct": {
              "type": "number"
            },
            "total_share_cash": {
              "type": "number"
            }
          },
          "required": [
            "total_share_pct",
            "total_share_cash"
          ]
        },
        "details": {
          "type": "array",
          "items": [
            {
              "type": "object",
              "properties": {
                "date": {
                  "type": "string"
                },
                "isin": {
                  "type": "string"
                },
                "nsd_code": {
                  "type": "string"
                },
                "nominee": {
                  "type": "object",
                  "properties": {
                    "share_pct": {
                      "type": "number"
                    },
                    "share_cash": {
                      "type": "number"
                    }
                  },
                  "required": [
                    "share_pct",
                    "share_cash"
                  ]
                },
                "nominee_and_banks": {
                  "type": "object",
                  "properties": {
                    "share_pct": {
                      "type": "number"
                    },
                    "share_cash": {
                      "type": "number"
                    }
                  },
                  "required": [
                    "share_pct",
                    "share_cash"
                  ]
                }
              },
              "required": [
                "date",
                "isin",
                "nsd_code",
                "nominee",
                "nominee_and_banks"
              ]
            }
          ]
        }
      },
      "required": [
        "date",
        "asset_type",
        "method",
        "calculation_currency",
        "nominee",
        "nominee_and_banks",
        "details"
      ]
    }
  ]
}

URL


            
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using Newtonsoft.Json.Linq;
using ClosedXML.Excel;

namespace ApiSample
{
    class Program
    {
        public const string ApiUrl = "http://172.23.24.198:5000/securities?limit=100";
        public static HashSet<string> SetOfIsins = new HashSet<string>(new[] { "RU0007202057", "RU0007202545", "RU0007201018", "RU0007202032" });
        public const string FileName = "coupons.xlsx";

        static void Main(string[] args)
        {
            Console.WriteLine("Загрузка данных...");
            var wc = new WebClient() { Encoding = Encoding.UTF8, };
            var json = wc.DownloadString(ApiUrl);

            var bonds = JArray.Parse(json);
            var filteredBonds = bonds.Where(b => SetOfIsins.Contains((string)b["isin"])).ToList();

            Console.WriteLine("Формирование Excel...");
            GenerateExcel(filteredBonds);
            Console.WriteLine("Готово!");
        }

        private static void GenerateExcel(List<JToken> input)
        {
            var workbook = new XLWorkbook();
            workbook.Use1904DateSystem = true;
            var ws = workbook.Worksheets.Add("Coupons info");

            ws.Column(1).Width = 16;
            ws.Column(2).Width = 70;
            ws.Column(3).Width = 50;
            ws.Column(4).Width = 35;
            ws.Column(5).Width = 16;

            var columns = new[] { "ISIN", "Название", "Эмитент", "Корпоративное действие", "Дата" };
            foreach (var j in Enumerable.Range(0, columns.Length))
            {
                ws.Cell(1, j + 1).Value = columns[j];
                ws.Cell(1, j + 1).Style.Fill.BackgroundColor = XLColor.FromTheme(XLThemeColor.Accent6);
            }

            var data = new List<List<JToken>>();
            foreach (var bond in input) {
                var corpActions = bond["corp_actions"]?.ToArray();
                if (corpActions == null || corpActions.Length == 0)
                continue;

            foreach (var c in corpActions)
                try
                {
                    data.Add(new List<JToken>() { bond["isin"], bond["name_full"], bond["issuer"]["name_full"],
                        c["corp_action_type"]["name"], c["action_date_plan"] });
                } catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    continue;
                }
            }

            for (int i = 0; i < data.Count; i++)
                for (int j = 0; j < columns.Length; j++)
                {
                    ws.Cell(i + 2, j + 1).SetValue<string>(Convert.ToString(data[i][j]));
                    ws.Cell(i + 2, j + 1).Style.Fill.BackgroundColor = i % 2 == 0 ? XLColor.FromTheme(XLThemeColor.Accent6, 0.5) : XLColor.FromTheme(XLThemeColor.Accent6, 0.8);
                }

            ws.RangeUsed().SetAutoFilter();

            workbook.SaveAs(FileName);
            System.Diagnostics.Process.Start(FileName);
        }
    }
}
            
        
            
package ru.nsd.example;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.json.JSONArray;
import org.json.JSONObject;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
import java.io.FileOutputStream;
import java.io.IOException;

public class RestClientExample {

    private static final String NSD_DATA_HOST = "http://172.23.24.198:5000";
    private static final String METHOD_NAME = "securities";
    private static final String RESULT_EXCEL_PATH = "C:/Temp/securities100.xls";

    public static void main(String[] args) {
        saveExcel(getFirstHundredSecurities());
    }

    private static JSONArray getFirstHundredSecurities() {
        Client client = Client.create(new DefaultClientConfig());
        WebResource webResource = client.resource(UriBuilder.fromUri(NSD_DATA_HOST).build());
        String jsonData = webResource.path(METHOD_NAME).queryParam("limit", "100")
        .accept(MediaType.APPLICATION_JSON_TYPE).get(String.class);
        return new JSONArray(jsonData);
    }

    private static void saveExcel(JSONArray securities) {
        try {
            FileOutputStream stream = new FileOutputStream(RESULT_EXCEL_PATH);
            HSSFWorkbook workbook = generateExcel(securities);
            workbook.write(stream);
            stream.close();
        } catch (IOException ex) {
            System.out.println(ex);
        }
    }

    private static HSSFWorkbook generateExcel(JSONArray securities) {
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet();
        int rownum = 1;

        HSSFRow headRow = sheet.createRow(rownum++);
        headRow.createCell(0).setCellValue("ISIN");
        headRow.createCell(1).setCellValue("Полное наименование");

        for (Object obj : securities) {
            JSONObject json = (JSONObject) obj;
            HSSFRow row = sheet.createRow(rownum++);
            row.createCell(0).setCellValue(json.optString("isin"));
            row.createCell(1).setCellValue(json.optString("name_full"));
        }

        return workbook;
    }
}