-
Notifications
You must be signed in to change notification settings - Fork 3
/
stonk.py
69 lines (55 loc) · 1.82 KB
/
stonk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import click
import grab_function
import clear_function
CONTEXT_SETTINGS = dict(help_option_names=['--help'])
# Name of the DynamoDB table that will hold the data
DYNAMO_DB_TABLE_NAME = 'WeeklyStock'
# AWS Region where the DynamoDB table is located
AWS_REGION = 'us-east-1'
# URL of the API that is providing stock data (AlphaVantage used when built)
URL = 'https://www.alphavantage.co/query?'
# API Token used to authenticate with the API (You can get one for free at https://www.alphavantage.co)
TOKEN = ''
# The data set that should be targeted (options are in AlphaVantage documentation)
TIMEFRAME = 'TIME_SERIES_WEEKLY'
@click.group(context_settings=CONTEXT_SETTINGS)
def main():
"""
Luke McConnell's stock trading command line tool for adding and removing data from AWS DynamoDB using boto3
\b
Created: 06/15/2020
Updated: 06/20/2020
"""
return
# GRAB COMMAND
@main.command()
@click.option(
"--api_token",
prompt="Token to authenticate with API",
help="Pass in the token to authenticate with the API.",
default=TOKEN)
@click.option(
"--ticker",
prompt="Ticker of stock to grab",
help="Pass in the ticker of the stock to grab (i.e AAPL).")
def grab(ticker, api_token):
"""
Pull in stock data from API
"""
# print(grab_function.main(f"{ticker}"))
grab_function.main(f"{ticker}", DYNAMO_DB_TABLE_NAME, AWS_REGION, URL, f"{api_token}", TIMEFRAME)
print("DONE grabbing")
# CLEAR COMMAND
@main.command()
@click.option(
"--ticker",
prompt="Ticker of stock to delete",
help="Pass in the ticker of the stock to delete (i.e AAPL).")
def clear(ticker):
"""
Clear all stock data from the database
"""
clear_function.main(f"{ticker}", DYNAMO_DB_TABLE_NAME, AWS_REGION)
print("DONE deleting")
if __name__ == '__main__':
main()