A web service that offers access via an interface for reference data and data about corporate actions with three versions of interrelations
Accrued interests for bonds
{ "type": "array", "items": { "$ref": "#/definitions/AccIntr" }, "definitions": { "AccIntr": { "type": "object", "properties": { "security_id": { "title": "Идентификатор ценной бумаги", "description": "Идентификатор ценной бумаги", "minimum": -2147483648, "maximum": 2147483647, "type": "integer" }, "isin": { "title": "ISIN", "description": "ISIN", "maxLength": 64, "type": "string" }, "code_nsd": { "title": "Код НРД", "description": "Код НРД", "maxLength": 64, "type": "string" }, "accintr": { "title": "Значение НКД", "description": "Значение НКД", "type": "array", "items": { "$ref": "#/definitions/AccruedInterestFull" } }, "_p": { "minimum": -2147483648, "maximum": 2147483647, "type": "array", "items": { "type": "integer" } }, "_at": { "title": "Дата обновления", "description": "Дата обновления", "type": "string" }, "_at2": { "title": "Дата обновления (с учетом вложенных объектов)", "description": "Дата обновления (с учетом вложенных объектов)", "type": "string" } }, "required": [ "security_id", "isin", "code_nsd", "_at", "_at2" ] }, "AccruedInterestFull": { "type": "object", "properties": { "id": { "title": "Id", "description": "Идентификатор", "minimum": -2147483648, "maximum": 2147483647, "type": "integer" }, "date": { "title": "Дата расчета НКД", "description": "Дата расчета НКД", "type": "string" }, "value": { "title": "Значение НКД на дату", "description": "Значение НКД на дату", "type": "number" } }, "required": [ "id", "date" ] } } }
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; } }