Adding ARK orders

This commit is contained in:
Artem Veremey
2021-03-09 09:43:26 -08:00
parent 35583d762d
commit 1561eafbc7
5 changed files with 111 additions and 2 deletions

View File

@@ -0,0 +1,93 @@
import argparse
import json
from pandas.core.base import DataError
from pandas.core.frame import DataFrame
import requests
from colorama import Fore, Style
from bs4 import BeautifulSoup
import pandas as pd
from gamestonk_terminal.helper_funcs import (
check_positive,
get_user_agent,
patch_pandas_text_adjustment,
parse_known_args_and_warn,
)
from gamestonk_terminal.config_terminal import USE_COLOR
def direction_color_red_green(val: str) -> str:
if val == "Buy":
ret = Fore.GREEN + val + Style.RESET_ALL
elif val == "Sell":
ret = Fore.RED + val + Style.RESET_ALL
else:
ret = val
return ret
def get_ark_orders() -> DataFrame:
url_orders = "https://cathiesark.com/ark-funds-combined/trades"
raw_page = requests.get(url_orders, headers={"User-Agent": get_user_agent()}).text
parsed_script = BeautifulSoup(raw_page, "lxml").find(
"script", {"id": "__NEXT_DATA__"}
)
parsed_json = json.loads(parsed_script.string)
df_orders = pd.json_normalize(parsed_json["props"]["pageProps"]["arkTrades"])
df_orders.drop(
[
"everything",
"everything.profile.customThumbnail",
"hidden",
"images.thumbnail",
],
axis=1,
inplace=True,
)
df_orders["date"] = pd.to_datetime(df_orders["date"], format="%Y-%m-%dZ").dt.date
return df_orders
def ark_orders(l_args):
parser = argparse.ArgumentParser(
prog="ARK Orders",
description="""
Orders by ARK Investment Management LLC - https://ark-funds.com/. [Source: https://cathiesark.com]
""",
)
parser.add_argument(
"-n",
"--num",
action="store",
dest="n_num",
type=check_positive,
default=20,
help="Last N orders.",
)
ns_parser = parse_known_args_and_warn(parser, l_args)
df_orders = get_ark_orders()
if USE_COLOR:
df_orders["direction"] = df_orders["direction"].apply(direction_color_red_green)
patch_pandas_text_adjustment()
df_orders["link"] = "https://finviz.com/quote.ashx?t=" + df_orders["ticker"]
pd.set_option("display.max_colwidth", None)
pd.set_option("display.max_rows", None)
print("")
print("Orders by ARK Investment Management LLC")
print("")
print(df_orders.head(ns_parser.n_num))
print("")

View File

@@ -5,6 +5,7 @@ from gamestonk_terminal.discovery import finviz_api
from gamestonk_terminal.discovery import short_interest_api
from gamestonk_terminal.discovery import seeking_alpha_api
from gamestonk_terminal.discovery import fidelity_api
from gamestonk_terminal.discovery import ark_api
from gamestonk_terminal.discovery import simply_wallst_api
from gamestonk_terminal.discovery import spachero_api
from gamestonk_terminal.discovery import unusual_whales_api
@@ -24,6 +25,7 @@ def print_discovery():
print(" sectors show sectors performance [Alpha Vantage]")
print(" gainers show latest top gainers [Yahoo Finance]")
print(" orders orders by Fidelity Customers [Fidelity]")
print(" ark_orders orders by ARK Investment Management LLC")
print(" up_earnings upcoming earnings release dates [Seeking Alpha]")
print(
" high_short show top high short interest stocks of over 20% ratio [www.highshortinterest.com]"
@@ -53,6 +55,7 @@ def disc_menu():
"gainers",
"spacs",
"orders",
"ark_orders",
"spachero",
"high_short",
"low_float",
@@ -107,6 +110,9 @@ def disc_menu():
elif ns_known_args.cmd == "orders":
fidelity_api.orders(l_args)
elif ns_known_args.cmd == "ark_orders":
ark_api.ark_orders(l_args)
elif ns_known_args.cmd == "simply_wallst":
simply_wallst_api.simply_wallst(l_args)

View File

@@ -308,7 +308,7 @@ def popular_tickers(l_args):
n_top_stocks += 1
except HTTPError as e:
if e.response.status_code != 404:
print(f"Unexpected exception from Fiviz: {e}")
print(f"Unexpected exception from Finviz: {e}")
except Exception as e:
print(e)

2
notebooks/templates/due_diligence.ipynb Normal file → Executable file
View File

@@ -102,7 +102,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.8.8"
}
},
"nbformat": 4,

10
tests/test_discovery_ark_api.py Executable file
View File

@@ -0,0 +1,10 @@
import unittest
from gamestonk_terminal.discovery.ark_api import (
ark_orders,
)
class TestDiscoveryArkApi(unittest.TestCase):
def test_ark_orders(self):
ark_orders([])