Реализация Java клиента к интерфейсу Информационного-статистического сервера Московской Биржи
Следующая генерация библиотеки moex
- Большая часть кода (99%) сгенерирована с помощью библиотеки Javapoet
- Запросы конструируются через цепочку вызовов методов (Fluent API), например:
var history = client
.iss()
.history()
.engines()
.engine("stock")
.markets()
.market("shares")
.boards()
.board("TQBR")
.securities()
.security("sber")
.format().json() // Выбираем формат JSON
.get(Map.of("from", "2020-01-03", "till", "2020-10-03")); // Задаем параметры и выполняем запрос
import ru.exdata.moex.IssClientBuilder;
var client = IssClientBuilder.builder().build()
Согласно официальной документации, формат в котором необходимо получить данные, указывается в конце основной части URL через точку и поддерживаются XML, CSV, JSON, HTML.
Клиент, предоставляет способ выбрать нужный формат следующим образом:
// str - объект класса String
var str = issClient.iss().index().format().asIs().get();
// json - объект класса Response
var json = issClient.iss().index().format().json().get();
// xml - объект класса String
var xml = issClient.iss().index().format().xml().get();
// csv - объект класса String
var csv = issClient.iss().index().format().csv().get();
// html - объект класса String
var html = issClient.iss().index().format().html().get();
Рассмотрим работу библиотеки на примере запроса получения истории по одной бумаге на фондовом рынке
Параметры передаются в метод get
, как экземпляр объекта класса, реализующего интерфейс java.lang.Map<K,V>
var request = client
.iss()
.history()
.engines()
.engine("stock")
.markets()
.market("shares")
.securities()
.security("MOEX")
.format()
.json();
// Экземпляр объекта класса Response
var response = request.get(Map.of("from", "2022-10-10", "till", "2022-10-14"));
Как следует из документации MOEX ISS
Для некоторых запросов также доступен специальный блок данных "cursor", указывающий текущую позицию отдаваемый данных относительно всего объёма данных, доступных по этому запросу.
Поэтому, для навигации по страницам, нужно использовать объект Qursor,
получить который можно с помощью метода qursor
у объекта класса Response
.
response
.cursor()
.filter(Cursor::hasNext)
.map(cursor -> request.get(Map.of(
"start", String.valueOf(cursor.nextIndex()),
"from", "2020-01-03",
"till", "2022-10-03"
)));
- /iss/analyticalproducts/curves/securities
- /iss/analyticalproducts/curves/securities/[security]
- /iss/analyticalproducts/futoi/securities
- /iss/analyticalproducts/futoi/securities/[security]
- /iss/analyticalproducts/netflow2/securities
- /iss/analyticalproducts/netflow2/securities/[security]
- /iss/archives/engines/[engine]/markets/[market]/[datatype]/[period]
- /iss/archives/engines/[engine]/markets/[market]/[datatype]/years
- /iss/archives/engines/[engine]/markets/[market]/[datatype]/years/[year]/months
- /iss/engines
- /iss/engines/[engine]
- /iss/engines/[engine]/markets
- /iss/engines/[engine]/markets/[market]
- /iss/engines/[engine]/markets/[market]/boardgroups
- /iss/engines/[engine]/markets/[market]/boardgroups/[boardgroup]
- /iss/engines/[engine]/markets/[market]/boardgroups/[boardgroup]/orderbook
- /iss/engines/[engine]/markets/[market]/boardgroups/[boardgroup]/securities
- /iss/engines/[engine]/markets/[market]/boardgroups/[boardgroup]/securities/[security]
- /iss/engines/[engine]/markets/[market]/boardgroups/[boardgroup]/securities/[security]/candleborders
- /iss/engines/[engine]/markets/[market]/boardgroups/[boardgroup]/securities/[security]/candles
- /iss/engines/[engine]/markets/[market]/boardgroups/[boardgroup]/securities/[security]/orderbook
- /iss/engines/[engine]/markets/[market]/boardgroups/[boardgroup]/securities/[security]/trades
- /iss/engines/[engine]/markets/[market]/boardgroups/[boardgroup]/trades
- /iss/engines/[engine]/markets/[market]/boards
- /iss/engines/[engine]/markets/[market]/boards/[board]
- /iss/engines/[engine]/markets/[market]/boards/[board]/orderbook
- /iss/engines/[engine]/markets/[market]/boards/[board]/securities
- /iss/engines/[engine]/markets/[market]/boards/[board]/securities/[security]
- /iss/engines/[engine]/markets/[market]/boards/[board]/securities/[security]/candleborders
- /iss/engines/[engine]/markets/[market]/boards/[board]/securities/[security]/candles
- /iss/engines/[engine]/markets/[market]/boards/[board]/securities/[security]/orderbook
- /iss/engines/[engine]/markets/[market]/boards/[board]/securities/[security]/trades
- /iss/engines/[engine]/markets/[market]/boards/[board]/trades
- /iss/engines/[engine]/markets/[market]/orderbook
- /iss/engines/[engine]/markets/[market]/secstats
- /iss/engines/[engine]/markets/[market]/securities
- /iss/engines/[engine]/markets/[market]/securities/[security]
- /iss/engines/[engine]/markets/[market]/securities/[security]/candleborders
- /iss/engines/[engine]/markets/[market]/securities/[security]/candles
- /iss/engines/[engine]/markets/[market]/securities/[security]/orderbook
- /iss/engines/[engine]/markets/[market]/securities/[security]/trades
- /iss/engines/[engine]/markets/[market]/trades
- /iss/engines/[engine]/markets/[market]/turnovers
- /iss/engines/[engine]/markets/zcyc
- /iss/engines/[engine]/turnovers
- /iss/engines/[engine]/zcyc
- /iss/events
- /iss/events/[event_id]
- /iss/history/engines/[engine]/markets/[market]/boardgroups/[boardgroup]/dates
- /iss/history/engines/[engine]/markets/[market]/boardgroups/[boardgroup]/listing
- /iss/history/engines/[engine]/markets/[market]/boardgroups/[boardgroup]/securities
- /iss/history/engines/[engine]/markets/[market]/boardgroups/[boardgroup]/securities
- /iss/history/engines/[engine]/markets/[market]/boardgroups/[boardgroup]/securities/[security]
- /iss/history/engines/[engine]/markets/[market]/boardgroups/[boardgroup]/securities/[security]
- /iss/history/engines/[engine]/markets/[market]/boardgroups/[boardgroup]/securities/[security]/dates
- /iss/history/engines/[engine]/markets/[market]/boardgroups/[boardgroup]/yields
- /iss/history/engines/[engine]/markets/[market]/boardgroups/[boardgroup]/yields/[security]
- /iss/history/engines/[engine]/markets/[market]/boards/[board]/dates
- /iss/history/engines/[engine]/markets/[market]/boards/[board]/listing
- /iss/history/engines/[engine]/markets/[market]/boards/[board]/securities
- /iss/history/engines/[engine]/markets/[market]/boards/[board]/securities/[security]
- /iss/history/engines/[engine]/markets/[market]/boards/[board]/securities/[security]/dates
- /iss/history/engines/[engine]/markets/[market]/boards/[board]/yields
- /iss/history/engines/[engine]/markets/[market]/boards/[board]/yields/[security]
- /iss/history/engines/[engine]/markets/[market]/dates
- /iss/history/engines/[engine]/markets/[market]/listing
- /iss/history/engines/[engine]/markets/[market]/securities
- /iss/history/engines/[engine]/markets/[market]/securities/[security]
- /iss/history/engines/[engine]/markets/[market]/securities/[security]/dates
- /iss/history/engines/[engine]/markets/[market]/session/[session]/boardgroups/[boardgroup]/securities
- /iss/history/engines/[engine]/markets/[market]/sessions
- /iss/history/engines/[engine]/markets/[market]/sessions/[session]/boardgroups/[boardgroup]/securities/[security]
- /iss/history/engines/[engine]/markets/[market]/sessions/[session]/boards/[board]/securities
- /iss/history/engines/[engine]/markets/[market]/sessions/[session]/boards/[board]/securities/[security]
- /iss/history/engines/[engine]/markets/[market]/sessions/[session]/securities
- /iss/history/engines/[engine]/markets/[market]/sessions/[session]/securities/[security]
- /iss/history/engines/[engine]/markets/[market]/yields
- /iss/history/engines/[engine]/markets/[market]/yields/[security]
- /iss/history/engines/stock/markets/shares/securities/changeover
- /iss/history/engines/stock/totals/boards
- /iss/history/engines/stock/totals/boards/[board]/securities
- /iss/history/engines/stock/totals/boards/[board]/securities/[security]
- /iss/history/engines/stock/totals/securities
- /iss/history/engines/stock/zcyc
- /iss/history/otc/providers/nsd/markets
- /iss/history/otc/providers/nsd/markets/[market]/daily
- /iss/history/otc/providers/nsd/markets/[market]/monthly
- /iss/index
- /iss/rms/engines/[engine]/objects/irr
- /iss/rms/engines/[engine]/objects/irr/filters
- /iss/securities
- /iss/securities/[security]
- /iss/securities/[security]/aggregates
- /iss/securities/[security]/indices
- /iss/securitygroups
- /iss/securitygroups/[securitygroup]
- /iss/securitygroups/[securitygroup]/collections
- /iss/securitygroups/[securitygroup]/collections/[collection]
- /iss/securitygroups/[securitygroup]/collections/[collection]/securities
- /iss/securitytypes
- /iss/securitytypes/[securitytype]
- /iss/sitenews
- /iss/sitenews/[news_id]
- /iss/statistics/engines/[engine]/derivatives/[report_name]
- /iss/statistics/engines/[engine]/markets/[market]
- /iss/statistics/engines/[engine]/markets/[market]/securities
- /iss/statistics/engines/[engine]/markets/[market]/securities/[security]
- /iss/statistics/engines/[engine]/monthly/[report_name]
- /iss/statistics/engines/currency/markets/fixing
- /iss/statistics/engines/currency/markets/fixing/[security]
- /iss/statistics/engines/currency/markets/selt/rates
- /iss/statistics/engines/futures/markets/indicativerates/securities
- /iss/statistics/engines/futures/markets/indicativerates/securities/[security]
- /iss/statistics/engines/futures/markets/options/assets
- /iss/statistics/engines/futures/markets/options/assets/[asset]
- /iss/statistics/engines/futures/markets/options/assets/[asset]/openpositions
- /iss/statistics/engines/futures/markets/options/assets/[asset]/optionboard
- /iss/statistics/engines/futures/markets/options/assets/[asset]/turnovers
- /iss/statistics/engines/futures/markets/options/assets/[asset]/volumes
- /iss/statistics/engines/state/markets/repo/cboper
- /iss/statistics/engines/state/markets/repo/dealers
- /iss/statistics/engines/state/markets/repo/mirp
- /iss/statistics/engines/state/rates
- /iss/statistics/engines/state/rates/columns
- /iss/statistics/engines/stock/capitalization
- /iss/statistics/engines/stock/currentprices
- /iss/statistics/engines/stock/deviationcoeffs
- /iss/statistics/engines/stock/markets/bonds/aggregates
- /iss/statistics/engines/stock/markets/bonds/aggregates/columns
- /iss/statistics/engines/stock/markets/index/analytics
- /iss/statistics/engines/stock/markets/index/analytics/[indexid]
- /iss/statistics/engines/stock/markets/index/analytics/[indexid]/tickers
- /iss/statistics/engines/stock/markets/index/analytics/[indexid]/tickers/[ticker]
- /iss/statistics/engines/stock/markets/index/analytics/columns
- /iss/statistics/engines/stock/markets/index/bulletins
- /iss/statistics/engines/stock/markets/index/rusfar
- /iss/statistics/engines/stock/markets/shares/correlations
- /iss/statistics/engines/stock/quotedsecurities
- /iss/statistics/engines/stock/securitieslisting
- /iss/statistics/engines/stock/splits
- /iss/statistics/engines/stock/splits/[security]
- /iss/turnovers
- /iss/turnovers/columns
Всего 143 метода
<dependency>
<groupId>ru.ex-data</groupId>
<artifactId>moex2</artifactId>
<version>1.0.0</version>
</dependency>
implementation 'ru.ex-data:moex2:1.0.0'
Сказать "Спасибо" можно тут donationalerts