-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrest.ts
More file actions
54 lines (46 loc) · 1.5 KB
/
Copy pathrest.ts
File metadata and controls
54 lines (46 loc) · 1.5 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
54
/**
* REST API örneği
*
* Çalıştırma:
* ALTINAPI_KEY=hapi_xxx npx tsx examples/rest.ts
*/
import { AltinapiClient, AltinapiError } from '../src/index.js';
const apiKey = process.env.ALTINAPI_KEY;
if (!apiKey) {
console.error('ALTINAPI_KEY environment değişkeni eksik');
process.exit(1);
}
const client = new AltinapiClient({ apiKey });
async function main() {
try {
// 1. Tüm fiyatlar
console.log('\n📊 Tüm fiyatlar:');
const tumu = await client.getAllPrices();
console.log(`Toplam sembol: ${tumu.data.length}`);
console.log(`Son güncelleme: ${tumu.updatedAt}`);
console.log(`Veri eski mi: ${tumu.stale}\n`);
// 2. Sadece döviz
console.log('💱 Döviz (DOVIZ):');
const doviz = await client.getPricesByCategory('DOVIZ');
for (const f of doviz.data) {
console.log(` ${f.symbol.padEnd(15)} ${f.bid} / ${f.ask}`);
}
// 3. Tek sembol
console.log('\n🥇 Altın (ALTIN):');
const altin = await client.getPrice('ALTIN');
console.log(` Alış: ${altin.bid} TL/gram`);
console.log(` Satış: ${altin.ask} TL/gram`);
// 4. Çeyrek altın
console.log('\n🪙 Çeyrek Altın:');
const ceyrek = await client.getPrice('CEYREK_YENI');
console.log(` ${ceyrek.bid} / ${ceyrek.ask} TL`);
} catch (err) {
if (err instanceof AltinapiError) {
console.error(`API hatası [${err.statusCode ?? '?'}]: ${err.message}`);
} else {
console.error('Beklenmedik hata:', err);
}
process.exit(1);
}
}
main();