UCONN

UCONN
UCONN

API - Application Programming Interface

API - Application Programming Interface


An API, or Application Programming Interface, is a software routine that can access

various hardware devices and software systems. For hardware devices, APIs provide a

way to instruct those devices to perform certain operations like turn on lights.

For software systems API’s focus on retrieving data that that system contains.

The Application Program Interface was not originally about routines on the internet

rather a way to communicate with operating systems and hardware.

When computers started to interact with each other standards needed to be created

so one system can perform certain operations on another.

The World Wide Web

With the explosion of the world wide web a need arose to easily share data across

platforms. Salesforce.com and  ebay launched API’s which allows their users to provide data to the platforms.

Standards for building these processes were focused around leveraging the

HTTP protocol.

APIs form a foundation for communication on the internet for data sharing and

loading on the web.

Some of the uses of APIs are in:

Payment systems to process credit card payments.

Maps to provide directions or locations. 

Logins where you can leverage Google or Facebook user validations for site access.

Whether apps can access data via APIs.

Stock prices can be accessed via finance APIs.

APIs can also be used in operating systems to access video cameras.

Smart home devices can be accessed via API to turn on lights and adjust thermostats.

In factories APIs can access machinery for delivering instructions.PI.

API Architecture


The common API categories used:

REST API (Representational State Transfer) uses HTTP methods

like GET & POST to retrieve and process data.


SOAP (Simple Object Access Protocol) uses XML markup language for processing.


GraphQL developed by Meta for client data retrieval.


gRPC (Google Remote Procedure Call) leveraging protocol buffers sending

data in binary format.


Access type


Public - No restrictions anyone can access.

Private - Developers with credentials to access specific systems.

Partner - Business partners provide access for processing to each other's systems.


The "Language" of APIs: JSON

Most modern APIs speak JSON (JavaScript Object Notation). Even though 

WebSockets: Creates a two-way, "always-on" tunnel between the client and server.

Sending Data: The POST Request

When you create a new tweet, sign up for a website, or upload a photo,

you aren't just "getting" data; you are "posting" it to a server.

API Keys: The "Digital Passport"

Most real-world APIs (like OpenAI, Google Maps, or Spotify) aren't free and open.

They need to know who is calling them to prevent abuse or to bill you.

Think of an API Key as a long, random password. You usually send it in the Headers of your request. Here is how that looks in code:



APIs


UBER


Yfinance Github

We can use the finance API an open-source Python library to retrieve stock data that is published on the Yahoo Finance site. Currently this is a widely used free of charge access for financial data.


Python API


We can go thru some simple methods to pull pricing data.

Start with Apple. The stock ticker used to trade apple is AAPL.

On the Yahoo finance site we can see historical pricing data by accessing the

link to retrieve that data.




The API returns data as Pandas DataFrames.


Pandas library


In order to use you need to install the library on your machine.


john_iacovacci1@cloudshell:~ (cloud-project-examples)$ mkdir yf

john_iacovacci1@cloudshell:~ (cloud-project-examples)$ cd yf

john_iacovacci1@cloudshell:~/yf (cloud-project-examples)$ pip install openbb-yfinance

Successfully installed openbb-yfinance-1.5.2 yfinance-0.2.66

john_iacovacci1@cloudshell:~/yf (cloud-project-examples)$ 

Panda libraries need to be installed


john_iacovacci1@cloudshell:~/yf (cloud-project-examples)$ pip3 install pandas



We can now list all the available fields that the yfinance API provides.


all.py

====================================================

import yfinance as yf


# set up tckr

tckr = yf.Ticker("MSFT")


# retrieve information

info = tckr.info


# Use a loop thru info

for key, value in info.items():

    txt = "Field name is {} field value is {} "

    print(txt.format(key,value))

====================================================


john_iacovacci1@cloudshell:~/yf (cloud-project-examples)$ python3 all.py

Field name is address1 field value is One Microsoft Way 

Field name is city field value is Redmond 

Field name is state field value is WA 

Field name is zip field value is 98052-6399 

Field name is country field value is United States 

Field name is phone field value is 425 882 8080 

Field name is website field value is https://www.microsoft.com 

Field name is industry field value is Software - Infrastructure 

Field name is industryKey field value is software-infrastructure 

Field name is industryDisp field value is Software - Infrastructure 

Field name is sector field value is Technology 

Field name is sectorKey field value is technology 

Field name is sectorDisp field value is Technology 

Field name is longBusinessSummary field value is Microsoft Corporation develops and supports software, services, devices, and solutions worldwide. The Productivity and Business Processes segment offers Microsoft 365 commercial, enterprise mobility + security, windows commercial, power BI, exchange, sharepoint, Microsoft teams, security and compliance, and copilot; Microsoft 365 commercial products, such as Windows commercial on-premises and office licensed services; Microsoft 365 consumer products and cloud services, including Microsoft 365 consumer subscriptions, office licensed on-premises, and other consumer services; LinkedIn; dynamics products and cloud services, such as dynamics 365, cloud-based applications, and on-premises ERP and CRM applications. Its Intelligent Cloud segment provides Server products and cloud services comprising Azure and other cloud services, GitHub, Nuance Healthcare, virtual desktop offerings, and other cloud services; server products, including SQL and windows server, visual studio and system center related client access licenses, and other on-premises offerings; enterprise and partner services, such as enterprise support and nuance professional services, industry solutions, Microsoft partner network, and learning experience. The Personal Computing segment provides windows and devices, such as Windows OEM licensing and devices and surface and PC accessories; gaming services and solutions, such as Xbox hardware, content, and services, first- and third-party content Xbox game pass, subscriptions, and cloud gaming, advertising, and other cloud services; search and news advertising services that includes Bing and Copilot, Microsoft News and Edge, and third-party affiliates. It sells its products through OEMs, distributors, and resellers; and online and retail stores. The company was founded in 1975 and is headquartered in Redmond, Washington. 

Field name is fullTimeEmployees field value is 228000 

Field name is companyOfficers field value is [{'maxAge': 1, 'name': 'Mr. Satya  Nadella', 'age': 58, 'title': 'Chairman & CEO', 'yearBorn': 1967, 'fiscalYear': 2025, 'totalPay': 12251294, 'exercisedValue': 0, 'unexercisedValue': 0}, {'maxAge': 1, 'name': 'Mr. Bradford L. Smith LCA', 'age': 66, 'title': 'President & Vice Chairman', 'yearBorn': 1959, 'fiscalYear': 2025, 'totalPay': 4532750, 'exercisedValue': 0, 'unexercisedValue': 0}, {'maxAge': 1, 'name': 'Ms. Amy E. Hood', 'age': 53, 'title': 'Executive VP & CFO', 'yearBorn': 1972, 'fiscalYear': 2025, 'totalPay': 4444191, 'exercisedValue': 0, 'unexercisedValue': 0}, {'maxAge': 1, 'name': 'Mr. Takeshi  Numoto', 'age': 54, 'title': 'Executive VP & Chief Marketing Officer', 'yearBorn': 1971, 'fiscalYear': 2025, 'totalPay': 2871250, 'exercisedValue': 0, 'unexercisedValue': 0}, {'maxAge': 1, 'name': 'Mr. Judson B. Althoff', 'age': 51, 'title': 'Executive VP & CEO of Commercial Business', 'yearBorn': 1974, 'fiscalYear': 2025, 'totalPay': 4490115, 'exercisedValue': 0, 'unexercisedValue': 0}, {'maxAge': 1, 'name': 'Ms. Carolina  Dybeck Happe', 'age': 53, 'title': 'Executive VP & COO', 'yearBorn': 1972, 'fiscalYear': 2025, 'exercisedValue': 0, 'unexercisedValue': 0}, {'maxAge': 1, 'name': 'Ms. Alice L. Jolla', 'age': 59, 'title': 'Corporate VP & Chief Accounting Officer', 'yearBorn': 1966, 'fiscalYear': 2025, 'exercisedValue': 0, 'unexercisedValue': 0}, {'maxAge': 1, 'name': 'Mr. Matthew  Kerner', 'title': 'CTO & Corporate VP of Worldwide Sales and Solutions', 'fiscalYear': 2025, 'exercisedValue': 0, 'unexercisedValue': 0}, {'maxAge': 1, 'name': 'Jonathan  Neilson', 'title': 'Vice President of Investor Relations', 'fiscalYear': 2025, 'exercisedValue': 0, 'unexercisedValue': 0}, {'maxAge': 1, 'name': 'Mr. Jonathan M. Palmer', 'title': 'Corporate Vice President & Chief Legal Officer', 'fiscalYear': 2025, 'exercisedValue': 0, 'unexercisedValue': 0}] 

Field name is auditRisk field value is 9 

Field name is boardRisk field value is 8 

Field name is compensationRisk field value is 5 

Field name is shareHolderRightsRisk field value is 2 

Field name is overallRisk field value is 5 

Field name is governanceEpochDate field value is 1769904000 

Field name is compensationAsOfEpochDate field value is 1767139200 

Field name is irWebsite field value is http://www.microsoft.com/investor/default.aspx 

Field name is executiveTeam field value is [] 

Field name is maxAge field value is 86400 

Field name is priceHint field value is 2 

Field name is previousClose field value is 401.72 

Field name is open field value is 390.9925 

Field name is dayLow field value is 390.0 

Field name is dayHigh field value is 396.8 

Field name is regularMarketPreviousClose field value is 401.72 

Field name is regularMarketOpen field value is 390.9925 

Field name is regularMarketDayLow field value is 390.0 

Field name is regularMarketDayHigh field value is 396.8 

Field name is dividendRate field value is 3.64 

Field name is dividendYield field value is 0.93 

Field name is exDividendDate field value is 1771459200 

Field name is payoutRatio field value is 0.21280001 

Field name is fiveYearAvgDividendYield field value is 0.79 

Field name is beta field value is 1.084 

Field name is trailingPE field value is 24.576971 

Field name is forwardPE field value is 20.843594 

Field name is volume field value is 41581101 

Field name is regularMarketVolume field value is 41581101 

Field name is averageVolume field value is 32471926 

Field name is averageVolume10days field value is 35807370 

Field name is averageDailyVolume10Day field value is 35807370 

Field name is bid field value is 393.1 

Field name is ask field value is 400.0 

Field name is bidSize field value is 2 

Field name is askSize field value is 1 

Field name is marketCap field value is 2918992052224 

Field name is nonDilutedMarketCap field value is 2916341563308 

Field name is fiftyTwoWeekLow field value is 344.79 

Field name is fiftyTwoWeekHigh field value is 555.45 

Field name is allTimeHigh field value is 555.45 

Field name is allTimeLow field value is 0.088542 

Field name is priceToSalesTrailing12Months field value is 9.5562725 

Field name is fiftyDayAverage field value is 445.3536 

Field name is twoHundredDayAverage field value is 485.7603 

Field name is trailingAnnualDividendRate field value is 3.48 

Field name is trailingAnnualDividendYield field value is 0.00866275 

Field name is currency field value is USD 

Field name is tradeable field value is False 

Field name is enterpriseValue field value is 2950157565952 

Field name is profitMargins field value is 0.39044 

Field name is floatShares field value is 7414861914 

Field name is sharesOutstanding field value is 7425629076 

Field name is sharesShort field value is 56124540 

Field name is sharesShortPriorMonth field value is 54651789 

Field name is sharesShortPreviousMonthDate field value is 1768435200 

Field name is dateShortInterest field value is 1770940800 

Field name is sharesPercentSharesOut field value is 0.0076 

Field name is heldPercentInsiders field value is 0.0030899998 

Field name is heldPercentInstitutions field value is 0.75859 

Field name is shortRatio field value is 1.29 

Field name is shortPercentOfFloat field value is 0.0076 

Field name is impliedSharesOutstanding field value is 7432377656 

Field name is bookValue field value is 52.615 

Field name is priceToBook field value is 7.464411 

Field name is lastFiscalYearEnd field value is 1751241600 

Field name is nextFiscalYearEnd field value is 1782777600 

Field name is mostRecentQuarter field value is 1767139200 

Field name is earningsQuarterlyGrowth field value is 0.595 

Field name is netIncomeToCommon field value is 119262003200 

Field name is trailingEps field value is 15.98 

Field name is forwardEps field value is 18.84224 

Field name is lastSplitFactor field value is 2:1 

Field name is lastSplitDate field value is 1045526400 

Field name is enterpriseToRevenue field value is 9.658 

Field name is enterpriseToEbitda field value is 16.833 

Field name is 52WeekChange field value is 0.0109398365 

Field name is SandP52WeekChange field value is 0.17593324 

Field name is lastDividendValue field value is 0.91 

Field name is lastDividendDate field value is 1771459200 

Field name is quoteType field value is EQUITY 

Field name is currentPrice field value is 392.74 

Field name is targetHighPrice field value is 730.0 

Field name is targetLowPrice field value is 392.0 

Field name is targetMeanPrice field value is 595.99567 

Field name is targetMedianPrice field value is 600.0 

Field name is recommendationMean field value is 1.2807 

Field name is recommendationKey field value is strong_buy 

Field name is numberOfAnalystOpinions field value is 53 

Field name is totalCash field value is 89461997568 

Field name is totalCashPerShare field value is 12.048 

Field name is ebitda field value is 175258992640 

Field name is totalDebt field value is 123278000128 

Field name is quickRatio field value is 1.239 

Field name is currentRatio field value is 1.386 

Field name is totalRevenue field value is 305453006848 

Field name is debtToEquity field value is 31.539 

Field name is revenuePerShare field value is 41.1 

Field name is returnOnAssets field value is 0.1486 

Field name is returnOnEquity field value is 0.34390998 

Field name is grossProfits field value is 209498996736 

Field name is freeCashflow field value is 53640626176 

Field name is operatingCashflow field value is 160506003456 

Field name is earningsGrowth field value is 0.598 

Field name is revenueGrowth field value is 0.167 

Field name is grossMargins field value is 0.68586 

Field name is ebitdaMargins field value is 0.57377 

Field name is operatingMargins field value is 0.47094002 

Field name is financialCurrency field value is USD 

Field name is symbol field value is MSFT 

Field name is language field value is en-US 

Field name is region field value is US 

Field name is typeDisp field value is Equity 

Field name is quoteSourceName field value is Nasdaq Real Time Price 

Field name is triggerable field value is True 

Field name is customPriceAlertConfidence field value is HIGH 

Field name is postMarketTime field value is 1772240396 

Field name is regularMarketTime field value is 1772226003 

Field name is exchange field value is NMS 

Field name is messageBoardId field value is finmb_21835 

Field name is exchangeTimezoneName field value is America/New_York 

Field name is exchangeTimezoneShortName field value is EST 

Field name is gmtOffSetMilliseconds field value is -18000000 

Field name is market field value is us_market 

Field name is esgPopulated field value is False 

Field name is marketState field value is CLOSED 

Field name is corporateActions field value is [] 

Field name is shortName field value is Microsoft Corporation 

Field name is longName field value is Microsoft Corporation 

Field name is regularMarketChangePercent field value is -2.2353907 

Field name is regularMarketPrice field value is 392.74 

Field name is priceEpsCurrentYear field value is 23.476316 

Field name is fiftyDayAverageChange field value is -52.613617 

Field name is fiftyDayAverageChangePercent field value is -0.11813897 

Field name is twoHundredDayAverageChange field value is -93.020325 

Field name is twoHundredDayAverageChangePercent field value is -0.19149429 

Field name is sourceInterval field value is 15 

Field name is exchangeDataDelayedBy field value is 0 

Field name is averageAnalystRating field value is 1.3 - Strong Buy 

Field name is cryptoTradeable field value is False 

Field name is hasPrePostMarketData field value is True 

Field name is firstTradeDateMilliseconds field value is 511108200000 

Field name is postMarketChangePercent field value is 0.36403677 

Field name is postMarketPrice field value is 394.1697 

Field name is postMarketChange field value is 1.429718 

Field name is regularMarketChange field value is -8.980011 

Field name is regularMarketDayRange field value is 390.0 - 396.8 

Field name is fullExchangeName field value is NasdaqGS 

Field name is averageDailyVolume3Month field value is 32471926 

Field name is fiftyTwoWeekLowChange field value is 47.94998 

Field name is fiftyTwoWeekLowChangePercent field value is 0.13907011 

Field name is fiftyTwoWeekRange field value is 344.79 - 555.45 

Field name is fiftyTwoWeekHighChange field value is -162.71002 

Field name is fiftyTwoWeekHighChangePercent field value is -0.2929337 

Field name is fiftyTwoWeekChangePercent field value is 1.0939837 

Field name is dividendDate field value is 1773273600 

Field name is earningsTimestamp field value is 1769634000 

Field name is earningsTimestampStart field value is 1777496400 

Field name is earningsTimestampEnd field value is 1777496400 

Field name is earningsCallTimestampStart field value is 1769639400 

Field name is earningsCallTimestampEnd field value is 1769639400 

Field name is isEarningsDateEstimate field value is False 

Field name is epsTrailingTwelveMonths field value is 15.98 

Field name is epsForward field value is 18.84224 

Field name is epsCurrentYear field value is 16.7292 

Field name is displayName field value is Microsoft 

Field name is trailingPegRatio field value is 1.4817 

john_iacovacci1@cloudshell:~/yf (cloud-project-examples)$ 



Stock prices


We will now cate a python program to retrieve daily prices from microsoft ticker MSF.


msft_price.py


=======================================================

import yfinance as yf


# set up ticker

tckr_sym = "MSFT"


# Build object

tckr = yf.Ticker(tckr_sym)


# retrieve price data

hist_data = tckr.history(period="3mo")  


# Data

print(f" Stock/price data for {tckr_sym}:")

print(hist_data[['Open', 'High', 'Low', 'Close', 'Volume']])



=======================================================

john_iacovacci1@cloudshell:~/yf (cloud-project-examples)$ python3 msft_price.py

 Stock/price data for MSFT:

                                 Open        High         Low       Close    Volume

Date                                                                               

2025-11-28 00:00:00-05:00  486.489626  491.508171  485.541778  490.889587  14386700

2025-12-01 00:00:00-05:00  487.327702  488.744451  483.546324  485.631561  23964000

2025-12-02 00:00:00-05:00  485.611626  492.376185  485.212543  488.884155  19562700

2025-12-03 00:00:00-05:00  475.235297  483.137244  474.117853  476.642090  34615100

2025-12-04 00:00:00-05:00  478.667468  480.223913  475.404895  479.744995  22318200

...                               ...         ...         ...         ...       ...

2026-02-23 00:00:00-05:00  395.000000  395.359985  383.100006  384.470001  43238300

2026-02-24 00:00:00-05:00  384.140015  389.359985  381.709991  389.000000  33884700

2026-02-25 00:00:00-05:00  390.529999  401.470001  390.160004  400.600006  43625500

2026-02-26 00:00:00-05:00  404.709991  407.489990  398.739990  401.720001  34405900

2026-02-27 00:00:00-05:00  390.880005  396.820007  389.880005  392.739990  51276300


[62 rows x 5 columns]

john_iacovacci1@cloudshell:~/yf (cloud-project-examples)$ 


No comments:

Post a Comment

Assignment #7 due 4/8/2026

  Take or use picture of a document(piece of mail) or any picture that has words. Use the https://uconnstamfordslp.blogspot.com/p/google-api...