-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from dalenguyen/dev
Dev
- Loading branch information
Showing
15 changed files
with
258 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Editor configuration, see http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
max_line_length = 120 | ||
|
||
[*.md] | ||
max_line_length = off | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Change log | ||
|
||
> **Tags:** | ||
> | ||
> - :boom: [Breaking Change] | ||
> - :eyeglasses: [Spec Compliancy] | ||
> - :rocket: [New Feature] | ||
> - :bug: [Bug Fix] | ||
> - :memo: [Documentation] | ||
> - :nail_care: [Polish] | ||
--- | ||
|
||
## [1.0.0] - 2021-02-27 | ||
|
||
#### - :rocket: [New Feature] | ||
|
||
- Restructured projects | ||
- Added WealthSimple | ||
|
||
## [0.0.4] - 2019-04-09 | ||
|
||
#### - :rocket: [New Feature] | ||
|
||
- Retrieve stock price & data from Yahoo! Finance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Contributing to StockAI | ||
|
||
I would love for you to contribute to this project and help make it better than it is today. I will update the the detail later. For now, just a simple pull request will works. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import sys | ||
sys.path.append('../stockai') | ||
|
||
from stockai import WealthSimple | ||
|
||
email: str = '' | ||
password: str = '' | ||
|
||
def prepare_credentails(): | ||
global email, password | ||
print('Prepare credentials') | ||
while not email: | ||
email = str(input("Enter email: \n>>> ")) | ||
while not password: | ||
password = str(input("Enter password: \n>>> ")) | ||
|
||
def init(): | ||
global username, password | ||
|
||
ws = WealthSimple(email, password) | ||
|
||
print('Get me...\n') | ||
me = ws.get_me() | ||
print(me) | ||
|
||
print('Get accounts\n') | ||
accounts = ws.get_accounts() | ||
print(accounts) | ||
|
||
print('Get security \n') | ||
TSLA = ws.get_security('TSLA') | ||
print(TSLA) | ||
|
||
prepare_credentails() | ||
init() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
ciso8601==2.1.1 | ||
requests==2.21.0 | ||
ciso8601==2.1.3 | ||
requests==2.25.1 | ||
loguru==0.5.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,26 @@ | |
with open("README.md", "r") as fh: | ||
long_description = fh.read() | ||
|
||
# Deploy to PyPI | ||
# | ||
# pip install twine | ||
# python setup.py sdist bdist_wheel | ||
# twine upload --skip-existing dist/* | ||
|
||
setuptools.setup( | ||
name="stockai", | ||
version="0.0.4", | ||
version="1.0.0", | ||
author="Dale Nguyen", | ||
author_email="[email protected]", | ||
description="Get stock info from Yahoo! Finance", | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
url="https://github.com/dalenguyen/stockai", | ||
packages=setuptools.find_packages(), | ||
install_requires = [ 'ciso8601', 'requests', ], | ||
install_requires = [ 'ciso8601', 'requests', 'loguru' ], | ||
classifiers=[ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)", | ||
"Operating System :: OS Independent", | ||
], | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import requests | ||
|
||
class WSAPIRequest: | ||
""" | ||
Handle API requests for WealthSimple | ||
""" | ||
|
||
def __init__(self, session, WS_URL): | ||
self.session = session | ||
self.WS_URL = WS_URL | ||
|
||
def request(self, method, endpoint, params=None): | ||
url = self.WS_URL + endpoint | ||
|
||
if method == 'POST': | ||
return self.post(url, params) | ||
elif method == 'GET': | ||
return self.get(url, params) | ||
else: | ||
raise Exception('Invalid request method: {method}') | ||
|
||
def post(self, url, params=None): | ||
try: | ||
return self.session.post(url, params) | ||
except Exception as error: | ||
print(error) | ||
|
||
def get(self, url, payload=None): | ||
auth = self.session.headers['Authorization'] | ||
return requests.get(url, headers = { 'Authorization': auth }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from requests import Session | ||
from .requests import WSAPIRequest | ||
from loguru import logger | ||
|
||
class WealthSimple(): | ||
BASE_DOMAIN = 'https://trade-service.wealthsimple.com/' | ||
|
||
def __init__(self, email: str, password: str): | ||
self.session = Session() | ||
self.WSAPI = WSAPIRequest(self.session, self.BASE_DOMAIN) | ||
self.login(email, password) | ||
|
||
def login (self, email: str = None, password: str = None) -> None: | ||
if email and password: | ||
payload = { "email": email, "password": password, "timeoutMs": 2e4 } | ||
response = self.WSAPI.request('POST', 'auth/login', payload) | ||
|
||
# Check of OTP | ||
if "x-wealthsimple-otp" in response.headers: | ||
TFACode = '' | ||
while not TFACode: | ||
# Obtain user input and ensure it is not empty | ||
TFACode = input('Enter 2FA code: ') | ||
payload['otp'] = TFACode | ||
response = self.WSAPI.request('POST', 'auth/login', payload) | ||
|
||
if response.status_code == 401: | ||
raise Exception('Invalid Login') | ||
|
||
self.session.headers.update( | ||
{"Authorization": response.headers["X-Access-Token"]} | ||
) | ||
self.session.headers.update( | ||
{"refresh_token": response.headers["X-Refresh-Token"]} | ||
) | ||
else: | ||
raise Exception('Missing login credentials') | ||
|
||
def get_me(self): | ||
logger.debug('get_me') | ||
response = self.WSAPI.request('GET', 'me') | ||
logger.debug(f'get_me {response.status_code}') | ||
|
||
if response.status_code == 401: | ||
raise Exception('Invalid Access Token') | ||
else: | ||
return response.json() | ||
|
||
def get_accounts(self) -> list: | ||
""" | ||
Get Wealthsimple Trade Accounts | ||
""" | ||
response = self.WSAPI.request('GET', 'account/list') | ||
response = response.json() | ||
return response['results'] | ||
|
||
def get_security(self, id: str) -> dict: | ||
""" | ||
Get Security Info | ||
""" | ||
logger.debug('get_security') | ||
response = self.WSAPI.request('GET', f'securities/{id}') | ||
logger.debug(f"get_security {response.status_code}") | ||
|
||
if response.status_code == 401: | ||
raise Exception(f'Cannot get security {id}') | ||
else: | ||
return response.json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.