mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-26 11:12:50 +00:00
* Add lookup commands * main ETF commands * Add technical analysis to ETF * add prediction techniques to ETF * add comparison analysis to etf * allow to select nr of holdings on load * add shold and summary commands to ETF * minor improvs * screener on ETF menu * add etf/scr wsj commands * readd compare command * add sbc to etf/screener * rename chold and shold * fix rogue etf and reset * minor corrections * minor menu print improv * legend of weights and title of plot * refactor screener to screener and disc on ETF * add ETF scripts
59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
"""WSJ model"""
|
|
__docformat__ = "numpy"
|
|
import pandas as pd
|
|
import requests
|
|
from gamestonk_terminal.helper_funcs import get_user_agent
|
|
|
|
|
|
def etf_movers(sort_type: str = "gainers") -> pd.DataFrame:
|
|
"""
|
|
Scrape data for top etf movers.
|
|
Parameters
|
|
----------
|
|
sort_type: str
|
|
Data to get. Can be "gainers", "decliners" or "activity
|
|
|
|
Returns
|
|
-------
|
|
etfmovers: pd.DataFrame
|
|
Datafame containing the name, price, change and the volume of the etf
|
|
"""
|
|
|
|
if sort_type == "gainers":
|
|
url = (
|
|
"https://www.wsj.com/market-data/mutualfunds-etfs/etfmovers?id=%7B%22application"
|
|
"%22%3A%22WSJ%22%2C%22etfMover%22%3A%22leaders%22%2C%22count%22%3A25%7D&type=mdc_etfmovers"
|
|
)
|
|
elif sort_type == "decliners":
|
|
url = (
|
|
"https://www.wsj.com/market-data/mutualfunds-etfs/etfmovers?id=%7B%22application"
|
|
"%22%3A%22WSJ%22%2C%22etfMover%22%3A%22laggards%22%2C%22count%22%3A25%7D&type=mdc_etfmovers"
|
|
)
|
|
elif sort_type == "active":
|
|
url = (
|
|
"https://www.wsj.com/market-data/mutualfunds-etfs/etfmovers?id=%7B%22application"
|
|
"%22%3A%22WSJ%22%2C%22etfMover%22%3A%22most_active%22%2C%22count%22%3A25%7D&type=mdc_etfmovers"
|
|
)
|
|
|
|
data = requests.get(url, headers={"User-Agent": get_user_agent()}).json()
|
|
name, last_price, net_change, percent_change, volume = [], [], [], [], []
|
|
|
|
for entry in data["data"]["instruments"]:
|
|
name.append(entry["name"])
|
|
last_price.append(entry["lastPrice"])
|
|
net_change.append(entry["priceChange"])
|
|
percent_change.append(entry["percentChange"])
|
|
volume.append(entry["formattedVolume"])
|
|
|
|
etfmovers = pd.DataFrame(
|
|
{
|
|
" ": name,
|
|
"Price": last_price,
|
|
"Chg": net_change,
|
|
"%Chg": percent_change,
|
|
"Vol": volume,
|
|
}
|
|
)
|
|
|
|
return etfmovers
|