1. Go to this page and download the library: Download rekryt/tbank-lib 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/ */
$stream = $client->marketDataStream();
$stream->subscribeCandles([$instrumentUid], SubscriptionInterval::OneMinute);
$stream->subscribeLastPrice([$instrumentUid]);
foreach ($stream->events() as $event) {
if ($event instanceof PayloadEvent && $event->payload instanceof Candle) {
$candle = $event->payload;
printf("%s: закрытие %s\n", $candle->time?->toString() ?? '', $candle->close?->toString() ?? '');
}
// за время разрыва биржа торговала: пропуск добирают unary-методами
if ($event instanceof StreamDisconnectedEvent) {
printf("разрыв, попытка %d через %.1f с\n", $event->attempt, $event->retryIn);
}
}
$registry = $client->registry();
$registry->warmup(); // весь список одним запросом
$sber = $registry->byTicker('SBER', 'TQBR');
echo $sber?->uid;
sh
php examples/quickstart/first-request.php # счета и портфель
php examples/market-data/get-candles.php # один метод API
php examples/streams/market-data-stream.php # стрим котировок
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.