This repository was archived by the owner on Feb 12, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathborsa.py
More file actions
50 lines (38 loc) · 1.56 KB
/
Copy pathborsa.py
File metadata and controls
50 lines (38 loc) · 1.56 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
# ///////////////////////////////////
import subprocess
import sys
def install_package(package_name):
"""Belirtilen paketi yükler."""
subprocess.check_call([sys.executable, "-m", "pip", "install", package_name])
try:
import yfinance
except ImportError:
print("Görünüşe göre 'yfinance' kütüphanesi yüklenmemiş. Yükleniyor...")
install_package('yfinance')
# ///////////////////////////////////
import yfinance as yf
def get_stock_data(symbol):
stock = yf.Ticker(symbol)
historical_data = stock.history(period='1d')
if historical_data.empty:
raise ValueError("Geçersiz sembol.")
latest_data = historical_data.iloc[-1]
return latest_data
while True:
symbol = input("Lütfen hisse senedi sembolünü girin (örn: AAPL, MSFT, TSLA): ")
try:
latest_data = get_stock_data(symbol)
# Function to format prices to two decimal places
def format_price(price):
return f"{price:.2f}"
print(f'Sembol: {symbol}')
print(f'Tarih: {latest_data.name.date()}')
print(f'Açılış Fiyatı: {format_price(latest_data["Open"])}')
print(f'Yüksek Fiyat: {format_price(latest_data["High"])}')
print(f'Düşük Fiyat: {format_price(latest_data["Low"])}')
print(f'Kapanış Fiyatı: {format_price(latest_data["Close"])}')
print(f'Hacim: {latest_data["Volume"]}')
break # Başarılı bir şekilde veri alındıysa döngüden çık
except ValueError as e:
print(e)
print("Lütfen geçerli bir hisse senedi sembolü girin.")