Learn R Programming

⚠️There's a newer version (0.3.0) of this package.Take me there.

moexer

Moscow Exchange (MOEX) provides a REST interface to its Informational and Statistical Server (ISS), see https://fs.moex.com/files/8888.

moexer is a thin wrapper around the REST interface. It allows to quickly fetch e.g. price candles for a particular security, obtain its profile information and so on. The data is returned as tibbles, making it easy to subsequently process and analyse it.

Installation

You can install the released version of moexer from CRAN with:

install.packages("moexer")

or the latest version from github:

devtools::install_github("x1o/moexer")

Example

Suppose you want to download monthly candles from Jan 1, 2020 until the present day for the Sberbank common shares.

library(moexer)
library(dplyr)

Each security on MOEX has an ID, e.g. a 4-letter ticker symbol for a share (“LKOH”) or an ISIN for a bond (“RU000A0JXPU3”).

Find the corresponding security ID:

search_security(query = 'Sberbank') |> 
    slice_head(n = 10) |> 
    select(secid, name, is_traded, type, primary_boardid)
secidnameis_tradedtypeprimary_boardid
SBERСбербанк России ПАО ао1common_shareTQBR
SBERPСбербанк России ПАО ап1preferred_shareTQBR
RU000A103WV8Сбербанк ПАО 001Р-SBER331exchange_bondTQCB
RU000A102RS6Сбербанк ПАО 001Р-SBER241exchange_bondTQCB
RU000A101QW2Сбербанк ПАО 001Р-SBER161exchange_bondTQCB
RU000A101C89Сбербанк ПАО 001Р-SBER151exchange_bondTQCB
RU000A102CU4Сбербанк ПАО 001Р-SBER191exchange_bondTQCB
RU000A1025U5Сбербанк ПАО 001Р-SBER171exchange_bondTQCB
RU000A103YM3Сбербанк ПАО 002Р-green011exchange_bondTQCB
RU000A0ZZ117Сбербанк ПАО БО 001Р-06R1exchange_bondTQCB

We can verify that SBER is indeed the symbol we were looking for and check the profile information:

sber_info <- get_security_info(secid = 'SBER')
sber_info$description |> 
    select(name, title, value)
nametitlevalue
SECIDКод ценной бумагиSBER
NAMEПолное наименованиеСбербанк России ПАО ао
SHORTNAMEКраткое наименованиеСбербанк
ISINISIN кодRU0009029540
REGNUMBERНомер государственной регистрации10301481B
ISSUESIZEОбъем выпуска21586948000
FACEVALUEНоминальная стоимость3
FACEUNITВалюта номиналаSUR
ISSUEDATEДата начала торгов2007-07-20
LATNAMEАнглийское наименованиеSberbank
LISTLEVELУровень листинга1
ISQUALIFIEDINVESTORSБумаги для квалифицированных инвесторов0
MORNINGSESSIONДопуск к утренней дополнительной торговой сессии1
EVENINGSESSIONДопуск к вечерней дополнительной торговой сессии1
TYPENAMEВид/категория ценной бумагиАкция обыкновенная
GROUPКод типа инструментаstock_shares
TYPEТип бумагиcommon_share
GROUPNAMEТипа инструментаАкции
EMITTER_IDКод эмитента1199
sber_info$boards |> 
    slice_head(n = 10) |> 
    select(secid, boardid, title, is_traded, history_from, history_till, currencyid)
secidboardidtitleis_tradedhistory_fromhistory_tillcurrencyid
SBERTQBRТ+: Акции и ДР - безадрес.12013-03-252023-01-03RUB
SBEREQBRОсновной режим: А1-Акции и паи - безадрес.02011-11-212013-08-30RUB
SBERSPEQПоставка по СК (акции)12018-06-292022-12-16RUB
SBERSMALТ+: Неполные лоты (акции) - безадрес.12011-11-212023-01-03RUB
SBERTQDPКрупные пакеты - Акции - безадрес.1NANARUB
SBEREQDPКрупные пакеты - Акции - безадрес.02011-12-122019-03-01RUB
SBERRPMOРЕПО-М - адрес.12019-04-222023-01-03RUB
SBERPTEQРПС с ЦК: Акции и ДР - адрес.12013-03-262023-01-03RUB
SBERMXBDMOEX Board02015-08-032023-01-04NA
SBERCLMRClassica - безадрес.02012-02-132015-07-31RUB

Fetch the SBER candles:

get_candles(secid = 'SBER', from = '2020-01-01', till = '2022-01-01', interval = 'monthly') |> 
    head()
secidopenclosehighlowvaluevolumebeginend
SBER255.99252.20270.80251.401940323919707471375202020-01-012020-01-31
SBER251.80233.36259.77231.002295156869759198227902020-02-012020-02-28
SBER238.93187.21241.00172.1558517868668130017366602020-03-012020-03-31
SBER183.20197.25205.44182.0033962647220817682227002020-04-012020-04-30
SBER195.68200.50205.00183.3326282747169813590452302020-05-012020-05-29
SBER203.10203.22223.15200.7532042416157615222683702020-06-012020-06-30

get_candles() is vectorised over secid, so it is possible to, say, fetch candles for both the common and the preferred shares. The returned object has class MoexCandles for which there’s an appropriate plot() method:

get_candles(
    secid = c('SBER', 'SBERP'), 
    from = '2020-01-01', 
    till = '2022-01-01', 
    interval = 'monthly'
) |> 
    plot()

Copy Link

Version

Install

install.packages('moexer')

Monthly Downloads

47

Version

0.2.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Dmitry Zotikov

Last Published

January 5th, 2023

Functions in moexer (0.2.0)

search_security

Search for a Single Security
get_candles

Get Candles for a Set of Securities
plot.MoexCandles

Plot Candles
get_security_info

Get a Security's Info
get_candle_borders

Get Possible Candle from-till Values for a Security
query_iss

Submit a REST Query to ISS
get_candle_durations

Get Candle Durations-Intervals Mapping