xx

Portföy Takip Uygulaması - Gerçek Zamanlı Fiyatlar

Portföy Takip Uygulaması

Borsa, kripto ve döviz varlıklarınızı (gerçek API verileriyle) takip edin.

API Yapılandırması

Hisse senedi ve döviz kurları için gereklidir. Buradan ücretsiz alabilirsiniz.

Kripto para fiyatları için CoinGecko API'si kullanılır. Temel fiyat sorguları için genellikle API anahtarı gerektirmez.

Kripto varlık eklerken CoinGecko ID'sini kullanın (örn: "bitcoin", "ethereum").

Yeni Varlık Ekle

Portföyüm

Portföyünüzde henüz varlık bulunmamaktadır.

Portföy Özeti

Toplam Portföy Değeri

0.00 ₺

Toplam Kâr/Zarar

0.00 ₺

Son Fiyat Güncelleme: Henüz Yok

© Portföy Takip Uygulaması. Bu bir demo uygulamasıdır.

Fiyat verileri Financial Modeling Prep ve CoinGecko API'lerinden sağlanmaktadır. API anahtarlarınızı güvenli tutunuz.

gem

import os import requests from flask import Flask, render_template app = Flask(__name__) # --- YAPILANDIRMA --- # 993X8HLMZD6SMPPU. ALPHA_VANTAGE_API_KEY = "993X8HLMZD6SMPPU." # Örnek bir portföy. Gerçek bir uygulamada bu veritabanından gelmelidir. portfolio = [ {'type': 'stock', 'symbol': 'AAPL', 'name': 'Apple Inc.', 'quantity': 10}, {'type': 'stock', 'symbol': 'MSFT', 'name': 'Microsoft Corp.', 'quantity': 5}, {'type': 'crypto', 'id': 'bitcoin', 'name': 'Bitcoin', 'quantity': 0.5}, {'type': 'crypto', 'id': 'ethereum', 'name': 'Ethereum', 'quantity': 3}, {'type': 'forex', 'from': 'EUR', 'to': 'TRY', 'name': 'Euro/TL', 'quantity': 1000} ] # --- API VERİ ÇEKME FONKSİYONLARI --- def get_stock_price(symbol): """Alpha Vantage API'sinden hisse senedi fiyatı çeker.""" try: url = f'https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol={symbol}&apikey={ALPHA_VANTAGE_API_KEY}' response = requests.get(url) response.raise_for_status() # HTTP hatalarını kontrol et data = response.json() price = float(data['Global Quote']['05. price']) return price except Exception as e: print(f"Hisse senedi verisi alınamadı ({symbol}): {e}") return None def get_crypto_price(crypto_id): """CoinGecko API'sinden kripto para fiyatı çeker.""" try: url = f'https://api.coingecko.com/api/v3/simple/price?ids={crypto_id}&vs_currencies=usd' response = requests.get(url) response.raise_for_status() data = response.json() price = float(data[crypto_id]['usd']) return price except Exception as e: print(f"Kripto para verisi alınamadı ({crypto_id}): {e}") return None def get_forex_rate(from_currency, to_currency): """Alpha Vantage API'sinden döviz kuru çeker.""" try: url = f'https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency={from_currency}&to_currency={to_currency}&apikey={ALPHA_VANTAGE_API_KEY}' response = requests.get(url) response.raise_for_status() data = response.json() rate = float(data['Realtime Currency Exchange Rate']['5. Exchange Rate']) return rate except Exception as e: print(f"Döviz kuru alınamadı ({from_currency}/{to_currency}): {e}") return None # --- ANA UYGULAMA ROTASI --- @app.route('/') def home(): enriched_portfolio = [] total_portfolio_value = 0.0 for asset in portfolio: current_price = 0 if asset['type'] == 'stock': current_price = get_stock_price(asset['symbol']) asset['currency'] = 'USD' elif asset['type'] == 'crypto': current_price = get_crypto_price(asset['id']) asset['currency'] = 'USD' elif asset['type'] == 'forex': # Döviz için 'price' 1 birim karşılığıdır. current_price = get_forex_rate(asset['from'], asset['to']) asset['currency'] = asset['to'] if current_price is not None: asset['current_price'] = current_price asset['total_value'] = asset['quantity'] * current_price total_portfolio_value += asset['total_value'] # Dövizleri şimdilik direkt topluyoruz. else: asset['current_price'] = 'Veri Alınamadı' asset['total_value'] = 'N/A' enriched_portfolio.append(asset) return render_template('index.html', portfolio=enriched_portfolio, total_value=total_portfolio_value) if __name__ == '__main__': app.run(debug=True)