Add Fidelity orders by customers

This commit is contained in:
didier
2021-02-05 23:47:53 +00:00
parent f4398d4918
commit a2a46b0be0
2 changed files with 64 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ from discovery import reddit_api
from discovery import finviz_api
from discovery import short_interest_api
from discovery import seeking_alpha_api
from discovery import fidelity_api
# -----------------------------------------------------------------------------------------------------------------------
@@ -20,6 +21,7 @@ def print_discovery():
print(" map S&P500 index stocks map [Finviz]")
print(" sectors show sectors performance [Alpha Vantage]")
print(" gainers show latest top gainers [Yahoo Finance]")
print(" orders Orders by Fidelity Customers [Fidelity]")
print(" earnings next earnings release dates [Seeking Alpha]")
print(" high_short show top high short interest stocks of over 20% ratio [www.highshortinterest.com]")
print(" low_float show low float stocks under 10M shares float [www.lowfloat.com]")
@@ -40,7 +42,7 @@ def disc_menu():
# Add list of arguments that the discovery parser accepts
disc_parser = argparse.ArgumentParser(prog='discovery', add_help=False)
disc_parser.add_argument('cmd', choices=['help', 'q', 'quit',
'map', 'sectors', 'gainers', 'high_short', 'low_float', 'earnings',
'map', 'sectors', 'gainers', 'orders', 'high_short', 'low_float', 'earnings',
'watchlist', 'spac', 'spac_c', 'wsb', 'popular'])
print_discovery()
@@ -81,6 +83,10 @@ def disc_menu():
elif ns_known_args.cmd == 'gainers':
yahoo_finance_api.gainers(l_args)
# --------------------------------------------------- FIDELITY ---------------------------------------------------
elif ns_known_args.cmd == 'orders':
fidelity_api.orders(l_args)
# ------------------------------------------------ SEEKING ALPHA ------------------------------------------------
elif ns_known_args.cmd == 'earnings':
seeking_alpha_api.earnings_release_dates(l_args)

57
discovery/fidelity_api.py Normal file
View File

@@ -0,0 +1,57 @@
import argparse
from bs4 import BeautifulSoup
import requests
import pandas as pd
import re
from stock_market_helper_funcs import *
# ---------------------------------------------------- ORDERS ----------------------------------------------------
def orders(l_args):
parser = argparse.ArgumentParser(prog='orders', description='''Orders by Fidelity customers''')
parser.add_argument('-n', "--num", action="store", dest="n_num", type=check_positive, default=10, help='Top orders')
try:
(ns_parser, l_unknown_args) = parser.parse_known_args(l_args)
if l_unknown_args:
print(f"The following args couldn't be interpreted: {l_unknown_args}")
url_orders = f"https://eresearch.fidelity.com/eresearch/gotoBL/fidelityTopOrders.jhtml"
text_soup_url_orders = BeautifulSoup(requests.get(url_orders).text, "lxml")
l_orders = list()
l_orders_vals = list()
idx = 0
for orders in text_soup_url_orders.findAll('td', {'class' : ['second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eight']}):
if ((idx+1)%3 == 0) or ((idx+1)%4 == 0) or ((idx+1)%6 == 0):
l_orders_vals.append(orders.contents[1])
elif ((idx+1)%5 == 0):
s_orders = str(orders)
l_orders_vals.append(s_orders[s_orders.find('title="') + len('title="'): s_orders.find('"/>')])
else:
l_orders_vals.append(orders.text.strip())
idx += 1
# Add value to dictionary
if (idx+1)%8 == 0:
l_orders.append(l_orders_vals)
l_orders_vals = list()
idx = 0
df_orders = pd.DataFrame(l_orders, columns = ['Symbol', 'Company', 'Price Change', '# Buy Orders',
'Buy / Sell Ratio', '# Sell Orders', 'Latest News'])
df_orders = df_orders[['Symbol', 'Buy / Sell Ratio', 'Price Change', 'Company', '# Buy Orders', '# Sell Orders', 'Latest News']]
print(text_soup_url_orders.findAll('span', {'class' : 'source'})[0].text.capitalize() + ':')
pd.set_option('display.max_colwidth', -1)
print(df_orders.head(n=ns_parser.n_num).iloc[:,:-1].to_string(index=False))
print("")
except SystemExit:
print("")
return