-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
83 lines (70 loc) · 3.08 KB
/
index.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
require_once __DIR__ . '/vendor/autoload.php';
$loader = new Twig_Loader_Array([
'index' =>
'
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width initial-scale=1">
<title>Should I Hodl?</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="should-i-hodl-container">
<div class="should-i-hodl__header">
Should I Hodl? 🤔
</div>
<div class="should-i-hodl-content">
<div class="should-i-hodl-content__current">
1 Bitcoin is currently worth <u>${{ currentUSValue }}</u>
</div>
<div class="should-i-hodl-content__yesterday">
Yesterday, 1 Bitcoin was worth <u>${{ yesterdaysValue }}</u> on average, so it {{ balance }} by <u>${{ difference }}</u> <br><br>What does this mean for your personal cryptocurrency portfolio?
</div>
</div>
<div class="should-i-hodl-content__holding-status">
👉 {{ shouldHold }}.
</div>
<div class="should-i-hodl-content__about">
Made with 💛 by <a href="https://twitter.com/helenasometimes">Nienke</a> during the Stupid Hackathon Amsterdam, 2017 <br>
<a href="https://github.com/StupidHackathonAMS/should-i-hodl">Source code</a>
</div>
</div>
</body>
</html>
'
]);
$twig = new Twig_Environment($loader);
$Blockchain = new \Blockchain\Blockchain();
// Determine HODL status
define("SHOULD_HODL", true);
// Get last market price value of 1 Bitcoin in USD
$rates = $Blockchain->Rates->get();
$getUSRates = get_object_vars($rates['USD']);
$currentUSValue = $getUSRates['last'];
// Get yesterday's average value of 1 Bitcoin in USD
$chartName = 'market-price';
$yesterdaysDate = date('Y-m-d',strtotime("-1 days"));
$link = "https://api.blockchain.info/charts/$chartName?&start=$yesterdaysDate";
$getValueObjectProperties = array_shift(get_object_vars(json_decode(file_get_contents($link)))['values']);
$yesterdaysAvgBitCoinValue = get_object_vars($getValueObjectProperties)["y"];
$difference = $currentUSValue - $yesterdaysAvgBitCoinValue;
if ($difference < 0) {
$balance = 'went down';
} else {
$balance = 'went up';
}
$shouldHold = '';
if (SHOULD_HODL) {
$shouldHold = 'YOU SHOULD HOLD';
}
echo $twig->render('index', [
'currentUSValue' => $currentUSValue,
'yesterdaysValue' => $yesterdaysAvgBitCoinValue,
'balance' => $balance,
'difference' => abs($difference),
'shouldHold' => $shouldHold,
]);
?>