Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
An unofficial library to capture data from Yahoo Finance API in an easier way. Having access to capture data from various stocks provided by the service.
An unofficial library to capture data from Yahoo Finance API in an easier way. Having access to capture data from some stocks provided by the service. It is possible to configure your capture to select and filter different types of data regarding the stocks provided.
initially, install the package through the following command in your terminal:
pip install yfapi
Note: For those more familiarized and who choose to keep the packages in a venv environment, you can use the command python -m venv yfapi.
If you are running your code on Windows, it is extremely important that you consider indenting your code as in the following example:
from yfapi import YahooFinance
if __name__ == '__main__':
# directly run your code that uses the
# YahooFinance class here, or even functions that use it.
Then we would use it as follows:
from yfapi import YahooFinance
if __name__ == '__main__':
stock_data = YahooFinance('STOCK_TICKER', '1d', '1d')
Initially, it is necessary to instantiate our variable that will receive the YahooFinance class, followed by the following attributes:
Attribute | Type |
---|---|
ticker | str or list |
interval | str |
range | str |
ticker: It is the code referring to the stock, Example: AMZN (Amazon), TSLA (Tesla) and AAPL (Apple).
interval: It is the time interval of how you want the data referring to the "range" attribute. Examples: 1m, 2m, 5m, 15m, 30m, 60m, 90m, 1h, 1d, 5d, 1wk, 1mo, 3mo.
range: It is the scale of capture, which can be days, months or years. Examples: 1d, 2d, 5d, 1mo, 2mo, 3mo, 6mo, 1y, 2y, 5y, 10y, ytd, max.
for that, instantiate as in this example code:
from yfapi import YahooFinance
google_data = YahooFinance('GOOG', '1d', '1d')
remember, if you are running the code on Windows you should run such functions like this:
from yfapi import YahooFinance
if __name__ == '__main__':
google_data = YahooFinance('GOOG', '1d', '1d')
Note: if you instantiate the YahooFinance class using a list of tickers for the "ticker" attribute, a loading bar will be shown referring to the amount of tickers present in the list.
Returns a Pandas DataFrame, with the following values referring to stock:
For that, just use the method like this example code:
from yfapi import YahooFinance
google_data = YahooFinance('GOOG', '1d', '1d')
google_info = google_data.info()
Returns a Pandas DataFrame with the following data:
it is necessary to insert the argument referring to which type of period you are looking for, being possible to capture "pre", "regular" and "post".
Arg | Type |
---|---|
type | str |
For that, just use the method like this example code:
from yfapi import YahooFinance
google_data = YahooFinance('GOOG', '1d', '1d')
google_trading_period = google_data.trading_period("regular")
Returns a Pandas DataFrame with the following data:
For that, just use the method like this example code:
from yfapi import YahooFinance
google_data = YahooFinance('GOOG', '1d', '1d')
google_values = google_data.all_values()
Returns a Pandas DataFrame with the following data:
For that, just use the method like this example code:
from yfapi import YahooFinance
google_data = YahooFinance('GOOG', '1d', '1d')
google_close = google_data.close()
Returns a Pandas DataFrame with the following data:
For that, just use the method like this example code:
from yfapi import YahooFinance
google_data = YahooFinance('GOOG', '1d', '1d')
google_open = google_data.open()
Returns a Pandas DataFrame with the following data:
For that, just use the method like this example code:
from yfapi import YahooFinance
google_data = YahooFinance('GOOG', '1d', '1d')
google_high = google_data.high()
Returns a Pandas DataFrame with the following data:
For that, just use the method like this example code:
from yfapi import YahooFinance
google_data = YahooFinance('GOOG', '1d', '1d')
google_low = google_data.low()
Returns a Pandas DataFrame with the following data:
For that, just use the method like this example code:
from yfapi import YahooFinance
google_data = YahooFinance('GOOG', '1d', '1d')
google_volume = google_data.volume()
If you have already captured some data using the methods mentioned above, you can export it to a .csv spreadsheet.
Arg | Type |
---|---|
dir (optional) | str |
sep (optional) | str |
dir: The path where you want your .csv file to be saved, by default is set to the current folder where the script is running and named "database.csv", which is also changeable. Your .csv will be saved in the given path, for example: "my_stock_databases/stock_name.csv". It is recommended to insert the suffix ".csv", however if it does not exist, it will be inserted at the end of the string received by this argument.
sep: It is the separator/delimiter used in this worksheet .csv, by default it is set to ";", but you can change it to any other. For example a comma (",").
For that, just use the method like this example code:
from yfapi import YahooFinance
google_data = YahooFinance('GOOG', '1d', '1d')
google_data = google_data.all_values()
google_data.to_csv("google_database.csv", sep=",")
Note: If you haven't captured any data, an error will be returned stating this.
If you have already captured some data using the methods mentioned above, you can export it to a .xlsx spreadsheet.
Arg | Type |
---|---|
dir (optional) | str |
For that, just use the method like this example code:
from yfapi import YahooFinance
google_data = YahooFinance('GOOG', '1d', '1d')
google_data = google_data.all_values()
google_data.to_excel("google_database.xlsx")
Note: If you haven't captured any data, an error will be returned stating this.
FAQs
An unofficial library to capture data from Yahoo Finance API in an easier way. Having access to capture data from various stocks provided by the service.
We found that yfapi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.