-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrest.php
More file actions
53 lines (43 loc) · 1.45 KB
/
rest.php
File metadata and controls
53 lines (43 loc) · 1.45 KB
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
<?php
declare(strict_types=1);
/**
* REST API örneği.
*
* Çalıştırma:
* ALTINAPI_KEY=hapi_xxx php examples/rest.php
*/
require __DIR__ . '/../vendor/autoload.php';
use Altinapi\AltinapiClient;
use Altinapi\AltinapiError;
$apiKey = getenv('ALTINAPI_KEY');
if ($apiKey === false || $apiKey === '') {
fwrite(STDERR, "ALTINAPI_KEY environment değişkeni eksik\n");
exit(1);
}
$client = new AltinapiClient(['apiKey' => $apiKey]);
try {
// 1. Tüm fiyatlar
echo "\n📊 Tüm fiyatlar:\n";
$tumu = $client->getAllPrices();
echo 'Toplam sembol: ' . count($tumu['data']) . "\n";
echo "Son güncelleme: {$tumu['updatedAt']}\n";
echo 'Veri eski mi: ' . ($tumu['stale'] ? 'evet' : 'hayır') . "\n";
// 2. Sadece döviz
echo "\n💱 Döviz (DOVIZ):\n";
$doviz = $client->getPricesByCategory('DOVIZ');
foreach (array_slice($doviz['data'], 0, 10) as $f) {
printf(" %-15s %s / %s\n", $f['symbol'], $f['bid'], $f['ask']);
}
// 3. Gram altın
echo "\n🥇 Altın (ALTIN):\n";
$altin = $client->getPrice('ALTIN');
echo " Alış: {$altin['bid']} TL/gram\n";
echo " Satış: {$altin['ask']} TL/gram\n";
// 4. Çeyrek altın
echo "\n🪙 Çeyrek Altın:\n";
$ceyrek = $client->getPrice('CEYREK_YENI');
echo " {$ceyrek['bid']} / {$ceyrek['ask']} TL\n";
} catch (AltinapiError $err) {
fwrite(STDERR, "API hatası [{$err->statusCode}]: {$err->getMessage()}\n");
exit(1);
}