Skip to content

Instantly share code, notes, and snippets.

@AphelionDH AphelionDH/tradingview.php
Last active Sep 13, 2019

Embed
What would you like to do?
<?php
ini_set('pcre.backtrack_limit', '10000000');
$url = 'https://ru.tradingview.com/chart/VIX/veShLNLq-vix/'; // Ссылка на торговую идею trading view
$filename = dirname(__FILE__) . '/candles.json'; // Путь к файлу, в который будут сохранены свечи
$html = file_get_contents($url);
if (empty($html)) {
die('Failed to load data');
}
if (!preg_match('/data-options="(.*?)"/', $html, $match)) {
die('Failed to find chart data');
}
$data = htmlspecialchars_decode($match[1]);
$json = json_decode($data);
$json = json_decode($json->content);
$bars = $json->panes[0]->sources[0]->bars;
$output = [];
foreach ($bars->data as $bar) {
$bar = $bar->value;
$output[] = [
'timestamp' => $bar[0],
'open' => $bar[1],
'high' => $bar[2],
'low' => $bar[3],
'close' => $bar[4],
'volume' => $bar[5]
];
}
file_put_contents($filename, json_encode($output, JSON_PRETTY_PRINT));
echo 'Success' . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.