### Install Apimoex Library Source: https://github.com/wlm1ke/apimoex/blob/master/docs/build/html/_sources/getting_started.rst.txt This snippet shows the command to install the apimoex library using pip. It is a prerequisite for using the library's functionalities. ```bash $ pip install apimoex ``` -------------------------------- ### Retrieve Securities List using ISSClient Source: https://github.com/wlm1ke/apimoex/blob/master/docs/build/html/_sources/getting_started.rst.txt This Python example shows how to use the `ISSClient` from the apimoex library to retrieve a list of securities traded in a specific market (TQBR). It constructs the request URL and arguments, fetches the data, and displays the head, tail, and info of the resulting pandas DataFrame. This is useful for getting details like registration number, lot size, and short name for securities. ```python import requests import apimoex import pandas as pd request_url = ('https://iss.moex.com/iss/engines/stock/' 'markets/shares/boards/TQBR/securities.json') arguments = {'securities.columns': ('SECID,' 'REGNUMBER,' 'LOTSIZE,' 'SHORTNAME')} with requests.Session() as session: iss = apimoex.ISSClient(session, request_url, arguments) data = iss.get() df = pd.DataFrame(data['securities']) df.set_index('SECID', inplace=True) print(df.head(), '\n') print(df.tail(), '\n') df.info() ``` -------------------------------- ### Get Board Candle Borders (Python) Source: https://context7.com/wlm1ke/apimoex/llms.txt Retrieves a table of available date intervals for candle data of different sizes for a specific trading board and instrument. It requires a requests session and the instrument ticker. The output is a Pandas DataFrame showing the start and end dates for each interval. ```python import requests import apimoex import pandas as pd with requests.Session() as session: # Узнать доступные интервалы для свечей Газпрома borders = apimoex.get_board_candle_borders(session, 'GAZP') df = pd.DataFrame(borders) print(df) # Результат показывает доступные периоды для каждого интервала: # begin end interval # 0 2011-12-15 10:00:00 2024-01-11 18:49:59 1 # 1 2011-12-15 10:00:00 2024-01-11 18:40:59 10 # 2 2011-12-15 10:00:00 2024-01-11 18:00:59 60 # 3 2011-12-15 00:00:00 2024-01-11 00:00:00 24 # 4 2011-12-12 00:00:00 2024-01-08 00:00:00 7 # 5 2011-12-01 00:00:00 2024-01-01 00:00:00 31 # 6 2011-10-01 00:00:00 2024-01-01 00:00:00 4 # Коды интервалов: 1=минута, 10=10мин, 60=час, 24=день, 7=неделя, 31=месяц, 4=квартал ``` -------------------------------- ### Find Security Description (Python) Source: https://github.com/wlm1ke/apimoex/blob/master/docs/build/html/api.html Retrieves the specification details for a given financial instrument (security). This can be used, for example, to find the trading start date of a security. It returns a list of dictionaries convertible to a pandas DataFrame. ```python from apimoex import find_security_description from apimoex.session import Session session = Session() description = find_security_description(session, security='AAPL') print(description) ``` -------------------------------- ### ISSClient Initialization and Usage Source: https://github.com/wlm1ke/apimoex/blob/master/docs/api.md Demonstrates how to initialize the ISSClient with a session and URL, and how to retrieve data using the get and get_all methods. ```APIDOC ## ISSClient Class ### Description Client for MOEX ISS. Requires a `requests.Session` object. It supports fetching data for simple responses using the `get` method. For responses with multiple data blocks, it supports an iterable protocol for individual blocks or the `get_all` method for automatic collection. ### Parameters - **session** (requests.Session) - Required - The session object for making HTTP requests. - **url** (str) - Required - The URL for the MOEX ISS API endpoint. - **query** (dict[str, str | int] | None) - Optional - Additional query parameters for the request. ## get Method ### Description Loads data for simple responses. Supports fetching data starting from a specific element for paginated results. ### Method GET ### Endpoint [Dynamic based on client initialization] ### Parameters #### Query Parameters - **start** (int | None) - Optional - The index of the element to start loading data from. Used for fetching subsequent data blocks. If not provided, data is loaded from the beginning. ### Response #### Success Response (200) - **data** (dict[str, list[dict[str, str | int | float]]]) - A dictionary where keys correspond to data tables. Each table is a list of dictionaries, directly convertible to a pandas DataFrame. Auxiliary information is excluded. #### Response Example ```json { "marketdata": [ { "SECID": "SBER", "CLOSE": 150.50, "UPDATETIME": "2023-10-27 10:00:00" } ] } ``` ## get_all Method ### Description Collects all data blocks for requests whose responses are delivered in parts. ### Method GET ### Endpoint [Dynamic based on client initialization] ### Response #### Success Response (200) - **data** (dict[str, list[dict[str, str | int | float]]]) - Combined data from all blocks, excluding auxiliary information. Each key corresponds to a data table, which is a list of dictionaries. #### Response Example ```json { "marketdata": [ { "SECID": "SBER", "CLOSE": 150.50, "UPDATETIME": "2023-10-27 10:00:00" }, { "SECID": "GAZP", "CLOSE": 160.00, "UPDATETIME": "2023-10-27 10:00:00" } ] } ``` ``` -------------------------------- ### Get security description Source: https://context7.com/wlm1ke/apimoex/llms.txt Retrieves detailed specifications for a specific instrument, such as listing date, currency, and type. ```python import requests import apimoex import pandas as pd with requests.Session() as session: description = apimoex.find_security_description(session, 'GAZP') print(pd.DataFrame(description)) spec = apimoex.find_security_description(session, 'SBER', columns=('name', 'value')) spec_df = pd.DataFrame(spec).set_index('name') print(f"Дата начала торгов: {spec_df.loc['LISTDATE', 'value']}") ``` -------------------------------- ### GET /iss/reference/security_description Source: https://github.com/wlm1ke/apimoex/blob/master/docs/build/html/api.html Fetches the detailed specification for a specific security ticker. ```APIDOC ## GET /iss/reference/security_description ### Description Retrieves the specification for a given security, such as the start date of trading. ### Method GET ### Endpoint /iss/reference/security_description ### Parameters #### Query Parameters - **session** (Session) - Required - The active network session. - **security** (str) - Required - The ticker symbol. - **columns** (tuple) - Optional - Columns to retrieve. Defaults to ('name', 'title', 'value'). ### Response #### Success Response (200) - **list[dict]** - Specification details. ### Response Example [ {"name": "LISTINGDATE", "title": "Дата начала торгов", "value": "2007-06-20"} ] ``` -------------------------------- ### GET /iss/reference/placeholder Source: https://github.com/wlm1ke/apimoex/blob/master/docs/build/html/api.html Retrieves the list of available values for a specific placeholder used in MOEX API request URLs. ```APIDOC ## GET /iss/reference/placeholder ### Description Retrieves the list of available values for a specific placeholder (e.g., engines, markets, boards) used in MOEX API request URLs. ### Method GET ### Endpoint /iss/reference/{placeholder} ### Parameters #### Query Parameters - **session** (Session) - Required - The active network session. - **placeholder** (str) - Required - The name of the placeholder (e.g., 'engines', 'markets', 'boards'). ### Response #### Success Response (200) - **list[dict]** - A list of dictionaries containing the reference data, suitable for conversion to a pandas.DataFrame. ### Response Example [ {"id": "1", "name": "TQBR"}, {"id": "2", "name": "TQTD"} ] ``` -------------------------------- ### GET /iss/reference/index_tickers Source: https://github.com/wlm1ke/apimoex/blob/master/docs/build/html/api.html Retrieves the composition of a specific index for a given date. ```APIDOC ## GET /iss/reference/index_tickers ### Description Returns the list of securities included in a specific index for a given date. ### Method GET ### Endpoint /iss/reference/index_tickers ### Parameters #### Query Parameters - **session** (Session) - Required - The active network session. - **index** (str) - Required - Index name (e.g., 'IMOEX'). - **date** (str) - Optional - Date in YYYY-MM-DD format. - **market** (str) - Optional - Market name, defaults to 'index'. - **engine** (str) - Optional - Engine name, defaults to 'stock'. ### Response #### Success Response (200) - **list[dict]** - List of tickers in the index. ### Response Example [ {"ticker": "SBER", "from": "2023-01-01", "till": "2023-12-31"} ] ``` -------------------------------- ### GET /get_board_securities Source: https://context7.com/wlm1ke/apimoex/llms.txt Fetches a list of all instruments for a specific trading board with auxiliary information. ```APIDOC ## GET /get_board_securities ### Description Retrieves a list of securities or market data for a given trading board. ### Method GET ### Endpoint /get_board_securities ### Parameters #### Query Parameters - **table** (string) - Optional - Data table to retrieve (e.g., 'securities', 'marketdata') - **columns** (tuple) - Optional - Specific columns to return ### Response #### Success Response (200) - **data** (array) - List of objects containing security details or market data fields. #### Response Example [ {"SECID": "SBER", "SHORTNAME": "Сбербанк", "LOTSIZE": 10}, {"SECID": "GAZP", "SHORTNAME": "Газпром", "LOTSIZE": 10} ] ``` -------------------------------- ### List Securities with ISSClient in apimoex Source: https://github.com/wlm1ke/apimoex/blob/master/docs/getting_started.md Shows how to retrieve a list of securities traded in a specific market mode (TQBR) using the ISSClient from the apimoex library. This example fetches details like registration number, lot size, and short name for each security. It uses requests for session management and pandas for data handling. ```python import requests import apimoex import pandas as pd request_url = ('https://iss.moex.com/iss/engines/stock/' 'markets/shares/boards/TQBR/securities.json') arguments = {'securities.columns': ('SECID,' 'REGNUMBER,' 'LOTSIZE,' 'SHORTNAME')} with requests.Session() as session: iss = apimoex.ISSClient(session, request_url, arguments) data = iss.get() df = pd.DataFrame(data['securities']) df.set_index('SECID', inplace=True) print(df.head(), '\n') print(df.tail(), '\n') df.info() ``` -------------------------------- ### GET /iss/ (ISSClient) Source: https://github.com/wlm1ke/apimoex/blob/master/docs/build/html/api.html The ISSClient class allows for executing arbitrary requests to the MOEX ISS API. It supports fetching single blocks of data or aggregating all blocks for paginated responses. ```APIDOC ## GET /iss/ ### Description Executes a custom request to the MOEX ISS API using a requests.Session. It handles data retrieval and provides methods to fetch partial or full datasets. ### Method GET ### Endpoint /iss/ (Custom URL path based on MOEX ISS reference) ### Parameters #### Path Parameters - **url** (string) - Required - The base URL for the specific MOEX ISS endpoint. #### Query Parameters - **query** (dict) - Optional - Dictionary of parameters to pass to the request (e.g., columns, board, market, engine). ### Request Example { "url": "https://iss.moex.com/iss/history/engines/stock/markets/shares/boards/TQBR/securities/SBER.json", "query": { "from": "2023-01-01" } } ### Response #### Success Response (200) - **data** (dict) - A dictionary where each key corresponds to a table of data, formatted as a list of dictionaries suitable for pandas.DataFrame conversion. #### Response Example { "history": [ {"TRADEDATE": "2023-01-01", "CLOSE": 150.5}, {"TRADEDATE": "2023-01-02", "CLOSE": 151.2} ] } ``` -------------------------------- ### GET /get_market_candles Source: https://github.com/wlm1ke/apimoex/blob/master/docs/build/html/_sources/api.rst.txt Retrieves historical candle data (HLOCV) for a specific market. ```APIDOC ## GET /get_market_candles ### Description Retrieves historical candle data for a specific market and security using MOEX ISS candle codes. ### Method GET ### Endpoint /get_market_candles ### Parameters #### Query Parameters - **security** (string) - Required - Ticker symbol of the security - **interval** (int) - Required - Candle interval code (1, 10, 60, 24, 7, 31, 4) - **start** (string) - Optional - Start date (YYYY-MM-DD) ### Request Example { "security": "SBER", "interval": 24, "start": "2023-01-01" } ### Response #### Success Response (200) - **candles** (array) - List of candle objects containing open, high, low, close, and volume data. #### Response Example { "candles": [{"begin": "2023-01-01", "open": 100.0, "close": 105.0}] } ``` -------------------------------- ### GET /get_board_securities Source: https://github.com/wlm1ke/apimoex/blob/master/docs/api.md Retrieves a table of instruments with auxiliary information for a specific trading mode. ```APIDOC ## GET /get_board_securities ### Description Fetches security metadata including lot sizes and registration numbers for instruments in a specific trading board. ### Method GET ### Parameters #### Query Parameters - **table** (string) - Optional - Data table (securities or marketdata) - **columns** (tuple) - Optional - Columns to return - **board** (string) - Optional - Trading mode (default: TQBR) ### Response #### Success Response (200) - **list** (array) - List of dictionaries containing security details #### Response Example [{"SECID": "SBER", "LOTSIZE": 10, "SHORTNAME": "Сбербанк"}] ``` -------------------------------- ### GET /get_board_dates Source: https://context7.com/wlm1ke/apimoex/llms.txt Retrieves the range of dates available in the history for a specific market and trading board. ```APIDOC ## GET /get_board_dates ### Description Returns the start and end dates available for historical data on a specific trading board. ### Method GET ### Endpoint /get_board_dates ### Parameters #### Query Parameters - **board** (string) - Optional - Trading board identifier (default: 'TQBR') - **market** (string) - Optional - Market identifier (default: 'shares') - **engine** (string) - Optional - Engine identifier (default: 'stock') ### Response #### Success Response (200) - **from** (string) - Start date of available history - **till** (string) - End date of available history #### Response Example { "from": "2014-06-09", "till": "2024-01-11" } ``` -------------------------------- ### Get Board Candles (Python) Source: https://context7.com/wlm1ke/apimoex/llms.txt Fetches candle data (Open, High, Low, Close, Volume) for a specified instrument and trading board within a date range. Supports various intervals: minute, 10-minute, hour, day, week, month, and quarter. Requires a requests session, instrument ticker, interval, and optional start/end dates and columns. Returns a Pandas DataFrame. ```python import requests import apimoex import pandas as pd with requests.Session() as session: # Получить дневные свечи Сбербанка за 2023 год candles = apimoex.get_board_candles( session, 'SBER', interval=24, start='2023-01-01', end='2023-12-31' ) df = pd.DataFrame(candles) df['begin'] = pd.to_datetime(df['begin']) df.set_index('begin', inplace=True) print(df.head()) # Результат: # open close high low value volume # begin # 2023-01-03 00:00:00 136.00 138.31 139.10 135.01 8123456789 59876543 # Получить часовые свечи за последний месяц hourly = apimoex.get_board_candles( session, 'GAZP', interval=60, start='2024-01-01' ) df_hourly = pd.DataFrame(hourly) print(f"Количество часовых свечей: {len(df_hourly)}") # Получить минутные свечи для внутридневной торговли minute_candles = apimoex.get_board_candles( session, 'LKOH', interval=1, start='2024-01-10', end='2024-01-10', columns=('begin', 'open', 'close', 'high', 'low', 'volume') ) print(pd.DataFrame(minute_candles).head(20)) ``` -------------------------------- ### GET /iss/reference/securities Source: https://github.com/wlm1ke/apimoex/blob/master/docs/build/html/api.html Searches for financial instruments by partial code, name, ISIN, issuer ID, or registration number. ```APIDOC ## GET /iss/reference/securities ### Description Searches for instruments based on a search string. Useful for finding ticker symbols or historical identifiers. ### Method GET ### Endpoint /iss/reference/securities ### Parameters #### Query Parameters - **session** (Session) - Required - The active network session. - **string** (str) - Required - Search query (code, name, ISIN, etc.). - **columns** (tuple) - Optional - List of columns to retrieve. Defaults to ('secid', 'regnumber'). ### Response #### Success Response (200) - **list[dict]** - List of matching securities. ### Response Example [ {"secid": "SBER", "regnumber": "10301481B"} ] ``` -------------------------------- ### GET /market/candle_borders Source: https://context7.com/wlm1ke/apimoex/llms.txt Retrieves the available date ranges for candle data across all trading modes for a given market. ```APIDOC ## GET /market/candle_borders ### Description Fetches a table of available date intervals for candles of various sizes across all market trading modes. ### Method GET ### Parameters #### Query Parameters - **security** (string) - Required - The ticker symbol. - **market** (string) - Optional - The market type (default: 'shares'). ``` -------------------------------- ### Retrieve Trading Board Date Intervals Source: https://context7.com/wlm1ke/apimoex/llms.txt Fetches the start and end dates available for a specific market and trading board. It requires an active requests session and returns a dictionary containing the date range. ```python import requests import apimoex import pandas as pd with requests.Session() as session: dates = apimoex.get_board_dates(session) print(pd.DataFrame(dates)) bond_dates = apimoex.get_board_dates(session, board='TQCB', market='bonds') print(pd.DataFrame(bond_dates)) currency_dates = apimoex.get_board_dates(session, board='CETS', market='selt', engine='currency') print(pd.DataFrame(currency_dates)) ``` -------------------------------- ### GET /iss/engines/stock/markets/shares/boards/{board}/securities Source: https://github.com/wlm1ke/apimoex/blob/master/README.rst Retrieves a list of securities currently traded on a specific market board. ```APIDOC ## GET /iss/engines/stock/markets/shares/boards/{board}/securities ### Description Returns metadata for securities listed on a specific market board, such as registration numbers and lot sizes. ### Method GET ### Endpoint https://iss.moex.com/iss/engines/stock/markets/shares/boards/{board}/securities.json ### Parameters #### Path Parameters - **board** (string) - Required - The trading board identifier (e.g., TQBR). #### Query Parameters - **securities.columns** (string) - Optional - Comma-separated list of columns to return. ### Request Example import requests import apimoex request_url = 'https://iss.moex.com/iss/engines/stock/markets/shares/boards/TQBR/securities.json' arguments = {'securities.columns': 'SECID,REGNUMBER,LOTSIZE,SHORTNAME'} with requests.Session() as session: iss = apimoex.ISSClient(session, request_url, arguments) data = iss.get() ### Response #### Success Response (200) - **securities** (list) - A collection of security metadata objects. #### Response Example { "securities": [ { "SECID": "ABRD", "REGNUMBER": "1-02-12500-A", "LOTSIZE": 10, "SHORTNAME": "АбрауДюрсо" } ] } ``` -------------------------------- ### GET /market/candles Source: https://context7.com/wlm1ke/apimoex/llms.txt Retrieves HLOCV candle data for an instrument across the main market trading modes. ```APIDOC ## GET /market/candles ### Description Retrieves HLOCV candle data for an instrument on the market for the main trading mode over a specified date range. ### Method GET ### Parameters #### Query Parameters - **security** (string) - Required - Ticker symbol. - **interval** (integer) - Required - Time interval (1, 10, 60, 24, 7, 31, 4). ``` -------------------------------- ### GET /iss/history/engines/stock/markets/shares/boards/{board}/securities/{security}/candles Source: https://github.com/wlm1ke/apimoex/blob/master/README.rst Retrieves historical trading data for a specific security on the Moscow Exchange. ```APIDOC ## GET /iss/history/engines/stock/markets/shares/boards/{board}/securities/{security}/candles ### Description Fetches historical market data for a given security, typically used to analyze price trends over time. ### Method GET ### Endpoint https://iss.moex.com/iss/history/engines/stock/markets/shares/boards/{board}/securities/{security}/candles ### Parameters #### Path Parameters - **board** (string) - Required - The trading board identifier (e.g., TQBR). - **security** (string) - Required - The security ticker symbol (e.g., SNGSP). ### Request Example import requests import apimoex with requests.Session() as session: data = apimoex.get_board_history(session, 'SNGSP') ### Response #### Success Response (200) - **data** (list) - A list of dictionaries containing historical trading records. #### Response Example { "TRADEDATE": "2019-09-10", "BOARDID": "TQBR", "CLOSE": 35.250, "VOLUME": 45966000, "VALUE": 1605849000 } ``` -------------------------------- ### GET /board/candle_borders Source: https://context7.com/wlm1ke/apimoex/llms.txt Retrieves the available date ranges for candle data at different time intervals for a specific trading mode. ```APIDOC ## GET /board/candle_borders ### Description Returns a table of available date intervals for candles of various sizes in a specified trading mode. ### Method GET ### Parameters #### Query Parameters - **security** (string) - Required - The ticker symbol of the instrument (e.g., 'GAZP'). ### Response #### Success Response (200) - **begin** (datetime) - Start date of the available interval. - **end** (datetime) - End date of the available interval. - **interval** (integer) - The candle interval code (1=min, 60=hour, 24=day, etc.). ``` -------------------------------- ### Get Reference Data (Python) Source: https://github.com/wlm1ke/apimoex/blob/master/docs/build/html/api.html Retrieves a list of available placeholder values for API request URLs. This is a helper function for constructing other API calls. It returns a list of dictionaries convertible to a pandas DataFrame. ```python from apimoex import get_reference from apimoex.session import Session session = Session() boards_data = get_reference(session, placeholder='boards') print(boards_data) ``` -------------------------------- ### Get Market Candle Borders Source: https://github.com/wlm1ke/apimoex/blob/master/docs/api.md Retrieves a table of available date intervals for different candle sizes on the market for all trading modes. This is useful for understanding the historical data availability for various candle intervals. ```APIDOC ## GET /iss/engines/{engine}/markets/{market}/securities/{security}/candleborders ### Description Retrieves a table of available date intervals for different candle sizes on the market for all trading modes. ### Method GET ### Endpoint /iss/engines/{engine}/markets/{market}/securities/{security}/candleborders ### Parameters #### Query Parameters - **security** (str) - Required - Ticker of the security. - **market** (str) - Optional - Market name (default: 'shares'). - **engine** (str) - Optional - Engine name (default: 'stock'). ### Response #### Success Response (200) - **data** (list[dict[str, str | int | float]]) - A list of dictionaries representing candle border data, directly convertible to a pandas DataFrame. #### Response Example ```json [ { "interval": 1, "from": "2023-01-01", "till": "2023-12-31" } ] ``` ``` -------------------------------- ### GET /get_board_history Source: https://context7.com/wlm1ke/apimoex/llms.txt Retrieves historical trading data for a specific security within a defined board and date range. ```APIDOC ## GET /get_board_history ### Description Fetches historical price and volume data for a specific security on a specific board. ### Method GET ### Endpoint /get_board_history ### Parameters #### Query Parameters - **security** (string) - Required - Security ticker - **start** (string) - Optional - Start date (YYYY-MM-DD) - **end** (string) - Optional - End date (YYYY-MM-DD) - **columns** (tuple) - Optional - Columns to include in the response ### Response #### Success Response (200) - **data** (array) - List of historical records. #### Response Example [ {"TRADEDATE": "2023-01-01", "CLOSE": 150.5, "VOLUME": 100000} ] ``` -------------------------------- ### Get Board Candle Borders Source: https://github.com/wlm1ke/apimoex/blob/master/docs/api.md Retrieves a table of available date intervals for different candle sizes within a specified trading mode. This endpoint allows for more granular control over the trading environment for data retrieval. ```APIDOC ## GET /iss/engines/{engine}/markets/{market}/boards/{board}/securities/{security}/candleborders ### Description Retrieves a table of available date intervals for different candle sizes within a specified trading mode. ### Method GET ### Endpoint /iss/engines/{engine}/markets/{market}/boards/{board}/securities/{security}/candleborders ### Parameters #### Query Parameters - **security** (str) - Required - Ticker of the security. - **board** (str) - Optional - Trading mode (default: 'TQBR'). - **market** (str) - Optional - Market name (default: 'shares'). - **engine** (str) - Optional - Engine name (default: 'stock'). ### Response #### Success Response (200) - **data** (list[dict[str, str | int | float]]) - A list of dictionaries representing candle border data for a specific board, directly convertible to a pandas DataFrame. #### Response Example ```json [ { "interval": 10, "from": "2023-01-01", "till": "2023-12-31" } ] ``` ``` -------------------------------- ### GET /board/candles Source: https://context7.com/wlm1ke/apimoex/llms.txt Retrieves HLOCV candle data for a specific instrument in a specific trading mode for a given date range. ```APIDOC ## GET /board/candles ### Description Retrieves candle data in HLOCV format for a specific instrument and trading mode. ### Method GET ### Parameters #### Query Parameters - **security** (string) - Required - Ticker symbol. - **interval** (integer) - Required - Time interval (1, 10, 60, 24, 7, 31, 4). - **start** (string) - Optional - Start date (YYYY-MM-DD). - **end** (string) - Optional - End date (YYYY-MM-DD). ### Response #### Success Response (200) - **open, close, high, low, value, volume** (float/int) - OHLCV data points. ``` -------------------------------- ### Get Market Candles (Python) Source: https://context7.com/wlm1ke/apimoex/llms.txt Fetches candle data (Open, High, Low, Close, Volume) for a specified instrument across different trading modes within a market. It supports various intervals and can retrieve data for the entire history or a specified date range. Optional parameters include interval, start/end dates, and specific columns. Returns a Pandas DataFrame. ```python import requests import apimoex import pandas as pd with requests.Session() as session: # Получить недельные свечи Газпрома weekly = apimoex.get_market_candles( session, 'GAZP', interval=7, start='2023-01-01', end='2023-12-31' ) df = pd.DataFrame(weekly) df['begin'] = pd.to_datetime(df['begin']) print(df.head(10)) # Получить месячные свечи за всю историю monthly = apimoex.get_market_candles( session, 'SBER', interval=31 ) df_monthly = pd.DataFrame(monthly) df_monthly['begin'] = pd.to_datetime(df_monthly['begin']) df_monthly.set_index('begin', inplace=True) print(f"Месячная история с {df_monthly.index.min()} по {df_monthly.index.max()}") print(df_monthly.tail()) # Получить квартальные свечи quarterly = apimoex.get_market_candles( session, 'LKOH', interval=4, columns=('begin', 'open', 'close', 'high', 'low', 'value') ) print(pd.DataFrame(quarterly)) ``` -------------------------------- ### Get Market Candles Source: https://github.com/wlm1ke/apimoex/blob/master/docs/build/html/api.html Fetches historical candle data (OHLCV) for a specified security on the market for a given date interval and candle size. Allows customization of returned columns. ```APIDOC ## GET /iss/engines/{engine}/markets/{market}/securities/{security}/candles ### Description Fetches historical candle data (OHLCV) for a specified security on the market for a given date interval and candle size. Allows customization of returned columns. ### Method GET ### Endpoint /iss/engines/{engine}/markets/{market}/securities/{security}/candles ### Parameters #### Path Parameters - **engine** (string) - Required - The trading engine (e.g., 'stock'). - **market** (string) - Required - The market type (e.g., 'shares'). - **security** (string) - Required - The security ticker. #### Query Parameters - **interval** (integer) - Optional - The size of the candle (1: 1 minute, 10: 10 minutes, 60: 1 hour, 24: 1 day, 7: 1 week, 31: 1 month, 4: 1 quarter). Defaults to 24 (daily). - **start** (string) - Optional - Start date in 'YYYY-MM-DD' format. Defaults to the beginning of history. - **end** (string) - Optional - End date in 'YYYY-MM-DD' format. Defaults to the end of history. - **columns** (tuple[string]) - Optional - Tuple of column names to retrieve (e.g., ('begin', 'open', 'close', 'high', 'low', 'value', 'volume')). If None or empty, all columns are loaded. ### Request Example None ### Response #### Success Response (200) - **data** (list[dict]) - A list of dictionaries, where each dictionary represents a candle with OHLCV data. #### Response Example ```json { "data": [ { "begin": "2023-10-26T00:00:00+03:00", "open": 100.50, "close": 101.20, "high": 101.50, "low": 100.30, "value": 1500000.00, "volume": 14800 } ] } ``` ``` -------------------------------- ### Get Board Candles Source: https://github.com/wlm1ke/apimoex/blob/master/docs/build/html/api.html Fetches historical candle data (OHLCV) for a specified security within a particular trading board for a given date interval and candle size. ```APIDOC ## GET /iss/engines/{engine}/markets/{market}/boards/{board}/securities/{security}/candles ### Description Fetches historical candle data (OHLCV) for a specified security within a particular trading board for a given date interval and candle size. ### Method GET ### Endpoint /iss/engines/{engine}/markets/{market}/boards/{board}/securities/{security}/candles ### Parameters #### Path Parameters - **engine** (string) - Required - The trading engine (e.g., 'stock'). - **market** (string) - Required - The market type (e.g., 'shares'). - **board** (string) - Required - The trading board identifier (e.g., 'TQBR'). - **security** (string) - Required - The security ticker. #### Query Parameters - **interval** (integer) - Optional - The size of the candle (1: 1 minute, 10: 10 minutes, 60: 1 hour, 24: 1 day, 7: 1 week, 31: 1 month, 4: 1 quarter). Defaults to 24 (daily). - **start** (string) - Optional - Start date in 'YYYY-MM-DD' format. Defaults to the beginning of history. - **end** (string) - Optional - End date in 'YYYY-MM-DD' format. Defaults to the end of history. - **columns** (tuple[string]) - Optional - Tuple of column names to retrieve (e.g., ('begin', 'open', 'close', 'high', 'low', 'value', 'volume')). If None or empty, all columns are loaded. ### Request Example None ### Response #### Success Response (200) - **data** (list[dict]) - A list of dictionaries, where each dictionary represents a candle with OHLCV data for the specified board. #### Response Example ```json { "data": [ { "begin": "2023-10-26T00:00:00+03:00", "open": 99.80, "close": 100.10, "high": 100.20, "low": 99.70, "value": 1200000.00, "volume": 12000 } ] } ``` ``` -------------------------------- ### Retrieve Historical Trading Data by Board Source: https://context7.com/wlm1ke/apimoex/llms.txt Gets historical price and volume data for a specific security within a defined trading board and date interval. Useful for technical analysis and backtesting. ```python import requests import apimoex import pandas as pd with requests.Session() as session: data = apimoex.get_board_history(session, 'SNGSP') df = pd.DataFrame(data) df.set_index('TRADEDATE', inplace=True) print(df.head()) sber_2023 = apimoex.get_board_history(session, 'SBER', start='2023-01-01', end='2023-12-31', columns=('TRADEDATE', 'OPEN', 'HIGH', 'LOW', 'CLOSE', 'VOLUME', 'VALUE')) df_sber = pd.DataFrame(sber_2023) print(df_sber.describe()) ``` -------------------------------- ### Get Market Candle Borders (Python) Source: https://context7.com/wlm1ke/apimoex/llms.txt Retrieves candle data borders for all trading modes within a specified market and instrument. It can filter by market type (e.g., 'bonds'). The function requires a requests session, instrument ticker, and optionally a market type. The output is a Pandas DataFrame containing border information. ```python import requests import apimoex import pandas as pd with requests.Session() as session: # Получить границы для всех режимов торгов borders = apimoex.get_market_candle_borders(session, 'SBER') df = pd.DataFrame(borders) print(df[['board_group_id', 'begin', 'end', 'interval']]) # Получить границы для облигаций bond_borders = apimoex.get_market_candle_borders( session, 'SU26238RMFS4', market='bonds' ) print(pd.DataFrame(bond_borders)) ``` -------------------------------- ### Get Security Metadata for a MOEX Board Source: https://github.com/wlm1ke/apimoex/blob/master/docs/build/html/api.html Retrieves a table of securities with metadata such as lot size and registration numbers. The output is a list of dictionaries suitable for conversion to a pandas DataFrame. ```python import requests import apimoex with requests.Session() as session: securities = apimoex.get_board_securities(session, board='TQBR') print(securities) ``` -------------------------------- ### Get Index Tickers (Python) Source: https://github.com/wlm1ke/apimoex/blob/master/docs/build/html/api.html Fetches information about the constituent instruments of a specified index for a given date. It allows filtering by date and selecting specific columns. Returns a list of dictionaries convertible to a pandas DataFrame. ```python from apimoex import get_index_tickers from apimoex.session import Session session = Session() index_tickers = get_index_tickers(session, index='IMOEX', date='2023-01-01') print(index_tickers) ``` -------------------------------- ### Get Market Candles Source: https://github.com/wlm1ke/apimoex/blob/master/docs/api.md Fetches HLOCV (High, Low, Open, Close, Volume) candle data for a specified instrument on a given market for a date range. It handles cases where multiple trading modes might exist for a single instrument. ```APIDOC ## GET /iss/engines/{engine}/markets/{market}/securities/{security}/candles ### Description Fetches HLOCV candle data for a specified instrument on a given market for a date range. Handles multiple trading modes. ### Method GET ### Endpoint /iss/engines/{engine}/markets/{market}/securities/{security}/candles ### Parameters #### Query Parameters - **security** (str) - Required - Ticker of the security. - **interval** (int) - Optional - Candle size (1: minute, 10: 10 minutes, 60: hour, 24: day, 7: week, 31: month, 4: quarter) (default: 24). - **start** (str) - Optional - Start date in YYYY-MM-DD format. Defaults to the beginning of history. - **end** (str) - Optional - End date in YYYY-MM-DD format. Defaults to the end of history. - **columns** (tuple[str, ...]) - Optional - Tuple of columns to retrieve (default: ('begin', 'open', 'close', 'high', 'low', 'value', 'volume')). If empty or None, all columns are returned. - **market** (str) - Optional - Market name (default: 'shares'). - **engine** (str) - Optional - Engine name (default: 'stock'). ### Response #### Success Response (200) - **data** (list[dict[str, str | int | float]]) - A list of dictionaries representing HLOCV candle data, directly convertible to a pandas DataFrame. #### Response Example ```json [ { "begin": "2023-10-26T00:00:00", "open": 100.50, "close": 101.20, "high": 101.50, "low": 100.30, "value": 500000, "volume": 4900 } ] ``` ``` -------------------------------- ### Fetch custom market data with ISSClient Source: https://github.com/wlm1ke/apimoex/blob/master/docs/build/html/getting_started.html Shows how to use the ISSClient class to perform custom requests to the MOEX ISS API and load the resulting JSON data into a pandas DataFrame. ```python import requests import apimoex import pandas as pd request_url = ('https://iss.moex.com/iss/engines/stock/' 'markets/shares/boards/TQBR/securities.json') arguments = {'securities.columns': ('SECID,' 'REGNUMBER,' 'LOTSIZE,' 'SHORTNAME')} with requests.Session() as session: iss = apimoex.ISSClient(session, request_url, arguments) data = iss.get() df = pd.DataFrame(data['securities']) df.set_index('SECID', inplace=True) print(df.head(), '\n') print(df.tail(), '\n') df.info() ``` -------------------------------- ### GET /get_market_history Source: https://github.com/wlm1ke/apimoex/blob/master/docs/build/html/_sources/api.rst.txt Retrieves historical daily market quotes for a specific security. ```APIDOC ## GET /get_market_history ### Description Retrieves historical daily quotes for a specific security across all market modes. ### Method GET ### Endpoint /get_market_history ### Parameters #### Query Parameters - **security** (string) - Required - Ticker symbol - **start** (string) - Optional - Start date - **end** (string) - Optional - End date ### Request Example { "security": "GAZP", "start": "2023-01-01" } ### Response #### Success Response (200) - **history** (array) - List of daily historical records. #### Response Example { "history": [{"trade_date": "2023-01-01", "close": 160.5}] } ``` -------------------------------- ### Use ISSClient for custom MOEX ISS requests Source: https://context7.com/wlm1ke/apimoex/llms.txt Demonstrates using the ISSClient class to perform custom requests to MOEX ISS endpoints and convert the response into a pandas DataFrame. ```python import requests import apimoex import pandas as pd request_url = 'https://iss.moex.com/iss/engines/stock/markets/shares/boards/TQBR/securities.json' arguments = {'securities.columns': 'SECID,REGNUMBER,LOTSIZE,SHORTNAME'} with requests.Session() as session: iss = apimoex.ISSClient(session, request_url, arguments) data = iss.get() df = pd.DataFrame(data['securities']) df.set_index('SECID', inplace=True) print(df.head()) ``` -------------------------------- ### GET /get_market_history Source: https://context7.com/wlm1ke/apimoex/llms.txt Retrieves historical data for a security across all trading boards on the market. ```APIDOC ## GET /get_market_history ### Description Fetches historical market data for a security, aggregating across all available trading boards. ### Method GET ### Endpoint /get_market_history ### Parameters #### Query Parameters - **security** (string) - Required - Security ticker - **start** (string) - Optional - Start date - **end** (string) - Optional - End date ### Response #### Success Response (200) - **data** (array) - List of historical records including BOARDID. #### Response Example [ {"BOARDID": "TQBR", "TRADEDATE": "2023-01-01", "CLOSE": 150.5} ] ``` -------------------------------- ### GET /get_market_history Source: https://github.com/wlm1ke/apimoex/blob/master/docs/api.md Retrieves historical daily quotes for a specific security across all trading modes. ```APIDOC ## GET /get_market_history ### Description Fetches historical price and volume data for a single security across all available trading modes for a given date range. ### Method GET ### Parameters #### Query Parameters - **security** (string) - Required - Ticker symbol - **start** (string) - Optional - Start date (YYYY-MM-DD) - **end** (string) - Optional - End date (YYYY-MM-DD) ### Response #### Success Response (200) - **list** (array) - Historical daily data records #### Response Example [{"TRADEDATE": "2023-10-27", "CLOSE": 250.5, "VOLUME": 1000}] ```