Bir arkadaşım benden bitcoin borsası olan binance'ın 5 dk lık verilerini geçmişe yönelik çekmemi istedi, internetten araştırmalarım sonucunda aşağıdaki koda ulaştım. Fakat sıkıntı binance ın tarih olarak unix epoch zamanı kullanması. While döngüsü ile verileri çekince 3 aylık veriler yaklaşık 25.000 satır ve tarihler unix şeklinde (örneğin 1567460400000 şeklinde geliyor bu da https://www.epochconverter.com/ adresinden bakınca GMT: Monday, 2 September 2019 21:40:00 e denk geliyor. Php ile epoh u nasıl çevirebiliriz?) json şeklinde çekilen ham hali resim olarak altta paylaşıyorum. Bu da kodlar
<?php
header("Content-type: text/html; charset=utf-8");
//get list of symbols
$xinfo = json_decode(file_get_contents("https://api.binance.com/api/v1/exchangeInfo"), true);
$symbols = [];
foreach($xinfo["symbols"] as $sym) $symbols[] = $sym["symbol"];
asort($symbols);
echo '<form method="get">';
echo '<select name="symbol">';
foreach($symbols as $sym) echo '<option val="'.$sym.'">'.$sym.'</option>';
echo '</select>';
echo '<input type="submit"></form>';
$intervals = array("5m");
if ($_GET["symbol"] != "") echo $_GET["symbol"] . "<br>";
foreach ($intervals as $int)
{
    echo "-----------------<br>";
    echo $int . "<br>";
    $filename = "binance_".$_GET["symbol"]."_".$int.".json";
    if (file_exists ( $filename ))
    {
        echo "file ".$filename." exists. Skipping.<br>";
        continue;
    }
    $ts_ms = round(microtime(true)*1000); //current GMT UNIX time in miliseconds
    $qty = 10;
    $ts_last = 1559509908000; //1.1.2017 milisec
    while ($ts_last < $ts_ms && $qty > 0)
    {
        echo gmdate("Y-m-dTH:i:sZ", $ts_last/1000) . "<br>";
        $string = file_get_contents("https://api.binance.com/api/v1/klines?symbol=".$_GET["symbol"]."&interval=".$int."&startTime=".$ts_last);
        //print_r($http_response_header);//global variable, always filled
        if ( $http_response_header[0] != "HTTP/1.1 200 OK") {echo $string . "<br>" . $http_response_header[0]; exit;}
        $json = json_decode($string, true);
        //json trim [ /not first/
        if ($ts_last != 1559509908000) $string = substr($string, 1);
        $ts_last = $json[count($json)-1][6]; $ts_last++;
        $qty = count($json);
        echo $qty . "<br>";
        //json trim ] add, /not last, should have less than 500, 0.2% chance/
        if ($qty == 500) {$string = substr($string, 0, -1); $string .= ",n";}
        file_put_contents($filename, $string, FILE_APPEND | LOCK_EX);
        echo str_repeat(' ',1024*64);
        flush();
        ob_flush();
        usleep(200000);
        set_time_limit (60);
    }
    echo "Done! " . $filename . "<br>";
}




Şimdiden teşekkürler ilgilenenler için...