-
Notifications
You must be signed in to change notification settings - Fork 0
/
getCurrentPrice.php
52 lines (47 loc) · 1.67 KB
/
getCurrentPrice.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* Calls specifies apis and returns data for frontend
*/
if(isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME']=="localhost"){
$url = "http://localhost/cryptboard/callExchanges.php";
}else{
$url = "http://nammabagalkot.in/cryptboard/callExchanges.php";
}
$responseData = file_get_contents($url);
$responseData = json_decode($responseData);
$lastFetchData = getLastPrice();
foreach ($responseData as $key => $value) {
$name = $value->name;
if(array_key_exists($name, $lastFetchData)){
$difference = $value->buy - $lastFetchData[$name];
// echo $value->buy;
// echo "-".$lastFetchData[$name]."<br/>";
$value->lastPrice = $lastFetchData[$name];
$value->difference = $difference;
}
}
print json_encode($responseData);
function getLastPrice(){
$properties = parse_ini_file("./php.ini", "true") or die("Could not find ini file");
$exhangesPropertyFile = $properties['exchanges'];
$exchanges = [];
foreach ($exhangesPropertyFile as $e) {
$exchanges[] = explode(",", $e)[0];
}
date_default_timezone_set('Asia/Kolkata');
$date = date('m_d_Y', time());
$time_stamp = date('m/d/Y H:i:s', time());
$lastFetchData = [];
foreach ($exchanges as $exchange) {
$fileToday = "data/" . $date ."_". $exchange."_price.txt";
if (file_exists($fileToday)) {
$fileData = file_get_contents($fileToday);
$fileDataLines = explode("\n", $fileData);
$lastLine = $fileDataLines[count($fileDataLines)-2];
$lastPrice = explode(",", $lastLine)[1];
$lastFetchData[$exchange] = $lastPrice;
}
}
return $lastFetchData;
}
?>