使用 Google Finance API 檢索股票報價
正如您所提到的,Google Finance Gadget API 不再可用。因此,透過這種方法存取股票報價不再可行。
但是,還有其他資源提供類似的功能。一種替代方案是 Google Cloud Platform 的財務資料 API。此 API 可讓您從各種來源檢索財務數據,包括股票報價。
要使用財務資料 API,您需要建立一個 Google Cloud Platform (GCP) 帳戶並啟用 Financial Data API。您專案的資料 API。啟用後,您可以使用以下步驟以程式設計方式存取股票報價:
例如,檢索微軟(MSFT)的最新股票報價,您可以在Python中使用以下代碼:
from google.cloud import finance # Import the financial data API library
client = finance.StockClient() # Instantiate the client
# Define the name of the stock
stock_name = "NASDAQ:MSFT"
# Fetch the stock information
quote = client.get_stock_snapshot(stock_name)
# Print the stock symbol and price
print(f"Stock: {quote.symbol}\nPrice: ${quote.price}")
財務數據API 提供一套全面的財務信息,包括股票報價、歷史定價數據、公司財務狀況,等等。透過利用此 API,您可以以程式設計方式存取股票相關訊息,以增強您的財務應用程式。
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3