Skip to content

Instantly share code, notes, and snippets.

@AphelionDH
Last active February 11, 2024 07:57
Show Gist options
  • Save AphelionDH/ef168f9bcff907245907db07d92004b0 to your computer and use it in GitHub Desktop.
Save AphelionDH/ef168f9bcff907245907db07d92004b0 to your computer and use it in GitHub Desktop.
<?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;
@AlexisMinerscience
Copy link

The script seems to have stopped working: 'Failed to find chart data'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment