PHP code example of panychek / moex

1. Go to this page and download the library: Download panychek/moex library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

panychek / moex example snippets




use Panychek\MoEx\Security;
use Panychek\MoEx\Exception\ExceptionInterface as MoexException;

try {
    $security = new Security('Sberbank');
    $last_price = $security->getLastPrice();
    
} catch (MoexException $e) {
    echo $e->getMessage();
}

$security = new Security('#SBER');

Exchange::setLanguage('en');

Exchange::authenticate($username, $password);

$securities = Exchange::findSecurities('Alrosa');

$securities = Exchange::findSecurities('Gazprom', 5);

$usd_rub = Exchange::getRubleRate();
$eur_rub = Exchange::getRubleRate('EUR');

$rtsi = new Security('RTS Index');

$year_to_date_return = $rtsi->getChange('YTD', '%');
$month_to_date_return = $rtsi->getChange('MTD', '%');

$volume_rub = $rtsi->getVolume('RUB');
$volume_usd = $rtsi->getVolume('USD');

$capitalization_rub = $rtsi->getCapitalization('RUB');
$capitalization_usd = $rtsi->getCapitalization('USD');

$security = new Security('MICEX Index');
$data = $security->getHistoricalQuotes('2014-01-01', '2014-12-31');

$data = $security->getHistoricalQuotes('2017-01-01');

$security = new Security('#GAZP');
$security->setLanguage('en');

$code = $security->getId(); // "GAZP"
$name = $security->getName(); // "Gazprom"
$short_name = $security->getShortName(); // "Gazprom"
$isin_code = $security->getIsin(); // "RU0007661625"

$market_title = $security->getMarket()->getTitle(); // "Equities Market"
$engine_title = $security->getEngine()->getTitle(); // "Securities Market"
$board_title = $security->getBoard()->getTitle(); // "T+: Stocks, DRs"
$capitalization = $security->getEngine()->getCapitalization(); // 33015281259414 RUB

$issuer_title = $security->getIssuer()->getTitle(); // "Публичное акционерное общество "Газпром""

$indices = $security->getIndices();
foreach ($indices as $index) {
    $code = $index->getId(); // "MICEX10INDEX", "MICEXBMI", "MICEXINDEXCF", etc.
    $short_name = $index->getShortName(); // "MICEX10 Index", "Moscow Exchange Broad Market Index", "MICEX Index", etc.
}

$exchange = $security->getExchange();

$turnovers_rub = $exchange->getTurnovers('rub'); 
$turnovers_usd = $exchange->getTurnovers('usd');
$num_trades = $exchange->getNumberOfTrades(); 

$christmas_turnovers = $exchange->getTurnovers('usd', '2015-12-25');
$christmas_num_trades = $exchange->getNumberOfTrades('2015-12-25');

$security = new Security('USDRUB');
$fx_market = $security->getEngine();

$fx_turnovers_rub = $fx_market->getTurnovers('rub');
$fx_turnovers_usd = $security->getEngine()->getTurnovers('usd');
$fx_num_trades = $security->getEngine()->getNumberOfTrades(); 

$fx_christmas_turnovers = $fx_market->getTurnovers('usd', '2015-12-25');
$fx_christmas_num_trades = $fx_market->getNumberOfTrades('2015-12-25');

$shares_group = SecurityGroup::getInstance('stock_shares');
$first_level = $shares_group->getCollection('one');
$securities = $first_level->getSecurities();

$logger = function(\GuzzleHttp\TransferStats $stats) {
    $request = $stats->getRequest();    
    $uri = $request->getUri();
    
    $time = $stats->getTransferTime();
    
    $html = 'Request URI: %s<br />Time: %s<br /><br />';
    echo sprintf($html, $uri, $time);
};

Client::getInstance()->setRequestLogger($logger);