-
-
Save xynobo/0dd620caa0f42c99a7e89369d938da80 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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