mirror of
https://github.com/yongghongg/stock-screener.git
synced 2022-03-09 00:26:31 +03:00
added US stock list function
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
"name": "automate-stock-screener-demo.ipynb",
|
||||
"provenance": [],
|
||||
"collapsed_sections": [],
|
||||
"authorship_tag": "ABX9TyMo4Pda++Ca65VaPKVaB3SM",
|
||||
"authorship_tag": "ABX9TyPclecTAnBBunNXKyPKq9Lh",
|
||||
"include_colab_link": true
|
||||
},
|
||||
"kernelspec": {
|
||||
@@ -52,7 +52,8 @@
|
||||
"import requests\n",
|
||||
"from bs4 import BeautifulSoup\n",
|
||||
"import yfinance as yf\n",
|
||||
"import email"
|
||||
"import email\n",
|
||||
"import pandas as pd"
|
||||
],
|
||||
"execution_count": null,
|
||||
"outputs": []
|
||||
@@ -100,7 +101,6 @@
|
||||
" candle1['Low'] > candle1 ['EMA50']\n",
|
||||
" return cond1 and cond2 and cond3\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# a list to store the screened results\n",
|
||||
"screened_list = [] \n",
|
||||
"# get the full stock list\n",
|
||||
@@ -110,7 +110,7 @@
|
||||
" print(stock_code) # remove this if you dont want the ticker to be printed\n",
|
||||
" try: \n",
|
||||
" # Step 1: get stock price for each stock\n",
|
||||
" price_chart_df = get_stock_price(stock_code + \".KL\")\n",
|
||||
" price_chart_df = get_stock_price(stock_code + \".KL\") # edit/remove \".KL\" for other exchange market\n",
|
||||
"\n",
|
||||
" # Step 2: add technical indicators (in this case EMA)\n",
|
||||
" close = price_chart_df['Close']\n",
|
||||
@@ -159,6 +159,46 @@
|
||||
],
|
||||
"execution_count": null,
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"metadata": {
|
||||
"id": "vcIveOlyI3h_"
|
||||
},
|
||||
"source": [
|
||||
"# for US stock list\n",
|
||||
"# credit to https://github.com/shilewenuw/get_all_tickers/issues/12\n",
|
||||
"def get_US_stock_list(exchange):\n",
|
||||
" headers = {\n",
|
||||
" 'authority': 'api.nasdaq.com',\n",
|
||||
" 'accept': 'application/json, text/plain, */*',\n",
|
||||
" 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36',\n",
|
||||
" 'origin': 'https://www.nasdaq.com',\n",
|
||||
" 'sec-fetch-site': 'same-site',\n",
|
||||
" 'sec-fetch-mode': 'cors',\n",
|
||||
" 'sec-fetch-dest': 'empty',\n",
|
||||
" 'referer': 'https://www.nasdaq.com/',\n",
|
||||
" 'accept-language': 'en-US,en;q=0.9',\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" params = (\n",
|
||||
" ('tableonly', 'true'),\n",
|
||||
" ('limit', '25'),\n",
|
||||
" ('offset', '0'),\n",
|
||||
" ('download', 'true'),\n",
|
||||
" ('exchange', exchange)\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" r = requests.get('https://api.nasdaq.com/api/screener/stocks', headers=headers, params=params)\n",
|
||||
" data = r.json()['data']\n",
|
||||
" df = pd.DataFrame(data['rows'], columns=data['headers'])\n",
|
||||
" df_filtered = df[~df['symbol'].str.contains(\"\\.|\\^|\\s\")]\n",
|
||||
" return df_filtered['symbol'].tolist()\n",
|
||||
"\n",
|
||||
"stock_list = get_US_stock_list('nyse') # or 'nasdaq' or 'amex'"
|
||||
],
|
||||
"execution_count": null,
|
||||
"outputs": []
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user