Skip to content

Documentation

Konstantin Novik edited this page Sep 21, 2023 · 6 revisions

MoexImporter

MoexImporter Objects

class MoexImporter()

Class MoexImporter implements https-queries to MOEX ISS API. You should to create at least one instance to work with other objects in the package. \
Base methods allow to get generic information about available engines and markets, request securities lists and quotes. \
Quotes requests are wrapped in the MoexSecurity class to improve convenience.

__init__

def __init__(
        header={
            'user-agent':
            'Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0',
        },
        loadinfo=False)

Class constructor initializes base variables and load information about engines and markets if flag _loadinfo is True

Parameters

header : dict, optional
HTTP-header for all requests to MOEX ISS API.
loadinfo: boolean, optional
If True, engines and markets lists are requested from MOEX ISS. You may get this information later with methods getEngines and getMarkets.

getEngines

def getEngines()

Returns the list of engines.

Returns

array_like List of engines.

getMarkets

def getMarkets(engine)

Returns the list of markets.

Parameters

engine: str The engine string identifier to get markets list.

Returns

array_like List of markets for the specific engine.

getSecurity

def getSecurity(seccode)

Returns the specific data for the security.

Parameters

seccode: str
Security ticker.

Returns

array_like
List of specific data for seccode.

searchForSecurity

def searchForSecurity(secpart)

Returns the list of all securities with the specific secpart of the name or ticker.

Parameters

secpart: str
Part of the security name or ticker.

Returns

array_like
List of securities.

searchForSecurityTraded

def searchForSecurityTraded(secpart)

Returns the list of traded securities with the specific secpart of the name or ticker.

Parameters

secpart: str
Part of the security name or ticker.

Returns

array_like
List of securities.

searchForSecurityNonTraded

def searchForSecurityNonTraded(secpart)

Returns the list of non-traded securities with the specific secpart of the name or ticker.

Parameters

secpart: str
Part of the security name or ticker.

Returns

array_like
List of securities.

getSecuritiesAll

def getSecuritiesAll()

Returns the list of all securities.

Returns

array_like List of securities.

getSecuritiesAllTraded

def getSecuritiesAllTraded()

Returns the list of traded securities.

Returns

array_like List of securities.

getSecuritiesAllNonTraded

def getSecuritiesAllNonTraded()

Returns the list of non-traded securities.

Returns

array_like List of securities.

getBondsAll

def getBondsAll()

Returns the list of all local bonds.

Returns

array_like List of securities.

getBondsAllTraded

def getBondsAllTraded()

Returns the list of all traded local bonds.

Returns

array_like List of securities.

getBondsAllNonTraded

def getBondsAllNonTraded()

Returns the list of all non-traded local bonds.

Returns

array_like List of securities.

getSharesAll

def getSharesAll()

Returns the list of all local shares.

Returns

array_like List of securities.

getSharesAllTraded

def getSharesAllTraded()

Returns the list of all traded local shares.

Returns

array_like List of securities.

getSharesAllNonTraded

def getSharesAllNonTraded()

Returns the list of all non-traded local shares.

Returns

array_like List of securities.

getHistoryQuotes

def getHistoryQuotes(engine, market, board, seccode, dtfrom, dttill, tsession,
                     start)

Returns quotes for the specific security.

Parameters

engine: str Specify engine for quotes. market: str Specify market for quotes. board: str Specify board for quotes. seccode: str Security ticker. dtfrom: date Left bound of daterange for quotes. dttill: date Right bound of daterange for quotes. tsession: MoexSessions Specify trading session for quotes. start: int Specify cursor for query. MOEX ISS returns only limited number of quotes per request. You have to shift the cursor to get the next portion.

Returns

array_like List of quotes.

getCandles

def getCandles(engine, market, board, seccode, dtfrom, dttill, start,
               candleperiod)

Returns candles for the specific security.

Parameters

engine: str Specify engine for quotes. market: str Specify market for quotes. board: str Specify board for quotes. seccode: str Security ticker. dtfrom: date Left bound of daterange for quotes. dttill: date Right bound of daterange for quotes. start: int Specify cursor for query. MOEX ISS returns only limited number of quotes per request. You have to shift the cursor to get the next portion. candleperiod: MoexCandlePeriods Period for candle.

Returns

array_like List of quotes.

MoexSecurity

MoexSecurity Objects

class MoexSecurity()

Class MoexSecurity implements methods to store and request security-specific information.

Instance of MoexImporter should be created before.

__init__

def __init__(seccode, mi)

Class constructor initializes base variables and loads security-specific information from MOEX ISS.

Parameters

seccode: str Security ticker from MOEX. mi: MoexImporter The object of MoexImporter that was created before. You can't use the class without this object.

getHistoryQuotesAsDataFrame

def getHistoryQuotesAsDataFrame(dtfrom,
                                dttill,
                                board=None,
                                ts=MoexSessions.MainSession)

Returns quotes for the security as a pandas dataframe.

Parameters

dtfrom: date The left bound of the range to request quotes. dttill: date The right bound of the range to request quotes. board: str, optional Request quotes for the specific board. The primary board is used if the parameter is ommited. You can check class attribute boards to get all available boards. ts: MoexSessions, optional Request quotes for the specific session. The main session is used if the parameter is ommited.

Returns

pd.DataFrame Quotes as pandas dataframe.
Columns:
'TRADEDATE' - date of the quote,
'OPEN' - open price,
'HIGH' - high price,
'LOW' - low price,
'CLOSE' - last price,
'YIELD' - yield to maturity, may be None for non-bonds,
'DURATION' - duration in days, may be None for non-bonds,
'VALUE' - trading value in rubles,
'QUANTITY' - trading value in securities.

getHistoryQuotesAsArray

def getHistoryQuotesAsArray(dtfrom,
                            dttill,
                            board=None,
                            ts=MoexSessions.MainSession)

Returns quotes for the security as an array of dicts.

Parameters

dtfrom: date The left bound of the range to request quotes. dttill: date The right bound of the range to request quotes. board: str, optional Request quotes for the specific board. The primary board is used if the parameter is ommited. You can check class attribute boards to get all available boards. ts: MoexSessions, optional Request quotes for the specific session. The main session is used if the parameter is ommited.

Returns

array_like Quotes as an array of dicts.
Dict keys:
'TRADEDATE' - date of the quote,
'OPEN' - open price,
'HIGH' - high price,
'LOW' - low price,
'CLOSE' - last price,
'YIELD' - yield to maturity, may be None for non-bonds,
'DURATION' - duration in days, may be None for non-bonds,
'VALUE' - trading value in rubles,
'QUANTITY' - trading value in securities.

getCandleQuotesAsDataFrame

def getCandleQuotesAsDataFrame(dtfrom,
                               dttill,
                               board=None,
                               interval=MoexCandlePeriods.Period1Day)

Returns candles for the security as a pandas dataframe.

Parameters

dtfrom: date
The left bound of the range to request quotes.
dttill: date
The right bound of the range to request quotes.
board: str, optional
Request quotes for the specific board. The primary board is used if the parameter is ommited. You can check class attribute boards to get all available boards.
interval: MoexCandlePeriods, optional
Request candles for the specified period. Default is 1 day.

Returns

pd.DataFrame Candles as pandas dataframe. Columns: 'begin' - begin time of the candle, 'end' - end time of the candle, 'open' - open price, 'high' - high price, 'low' - low price, 'close' - last price, 'value' - trading value in rubles, 'quantity' - trading value in securities.

getCandleQuotesAsArray

def getCandleQuotesAsArray(dtfrom,
                           dttill,
                           board=None,
                           interval=MoexCandlePeriods.Period1Day)

Returns quotes for the security as an array of dicts.

Parameters

dtfrom: date The left bound of the range to request quotes. dttill: date The right bound of the range to request quotes. board: str, optional Request quotes for the specific board. The primary board is used if the parameter is ommited. You can check class attribute boards to get all available boards. interval: MoexCandlePeriods, optional Request candles for the specified period. Default is 1 day.

Returns

array_like Candles as an array of dicts. Dict keys: 'begin' - begin time of the candle, 'end' - end time of the candle, 'open' - open price, 'high' - high price, 'low' - low price, 'close' - last price, 'value' - trading value in rubles, 'quantity' - trading value in securities.

MoexCandlePeriods

MoexCandlePeriods Objects

class MoexCandlePeriods(IntEnum)

Enum of candle periods.

Period1Min

Period for 1 minute candles.

Period10Min

Period for 10 minutes candles.

Period1Hour

Period for 1 hour candles.

Period1Day

Period for 1 day candles.

Period1Week

Period for 1 week candles.

Period1Month

Period for 1 month candles.

Period1Quarter

Period for 1 quarter candles.

MoexSessions

MoexSessions Objects

class MoexSessions(IntEnum)

Enum for MOEX sessions. Not applicable to all instruments.

MorningSession

Morning trading session.

MainSession

Main trading session.

EveningSession

Evening tradning session.

TotalSessions

Data for all sessions.

Clone this wiki locally