-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrest.py
More file actions
53 lines (40 loc) · 1.44 KB
/
rest.py
File metadata and controls
53 lines (40 loc) · 1.44 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
"""REST API örneği.
Çalıştırma:
ALTINAPI_KEY=hapi_xxx python examples/rest.py
"""
from __future__ import annotations
import os
import sys
from altinapi import AltinapiClient, AltinapiError
def main() -> None:
api_key = os.environ.get("ALTINAPI_KEY")
if not api_key:
print("ALTINAPI_KEY environment değişkeni eksik", file=sys.stderr)
sys.exit(1)
client = AltinapiClient(api_key=api_key)
try:
# 1. Tüm fiyatlar
print("\n📊 Tüm fiyatlar:")
tumu = client.get_all_prices()
print(f"Toplam sembol: {len(tumu['data'])}")
print(f"Son güncelleme: {tumu['updatedAt']}")
print(f"Veri eski mi: {tumu['stale']}")
# 2. Sadece döviz
print("\n💱 Döviz (DOVIZ):")
doviz = client.get_prices_by_category("DOVIZ")
for f in doviz["data"][:10]:
print(f" {f['symbol']:<15} {f['bid']} / {f['ask']}")
# 3. Tek sembol — gram altın
print("\n🥇 Altın (ALTIN):")
altin = client.get_price("ALTIN")
print(f" Alış: {altin['bid']} TL/gram")
print(f" Satış: {altin['ask']} TL/gram")
# 4. Çeyrek altın
print("\n🪙 Çeyrek Altın:")
ceyrek = client.get_price("CEYREK_YENI")
print(f" {ceyrek['bid']} / {ceyrek['ask']} TL")
except AltinapiError as err:
print(f"API hatası: {err}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()