Skip to content

Commit d0c611f

Browse files
committed
add version 0.3.0
1 parent ddb2a48 commit d0c611f

File tree

15 files changed

+1400
-1277
lines changed

15 files changed

+1400
-1277
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
## Overview
1717

18-
Current Version: **0.2.9**
18+
Current Version: **0.3.0**
1919

2020
The unofficial Python API client library for TD Ameritrade allows individuals with TD Ameritrade accounts to manage trades, pull historical and real-time data, manage their accounts, create and modify orders all using the Python programming language.
2121

setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from setuptools import setup, find_packages
1+
from setuptools import setup
2+
from setuptools import find_packages
23

34
# load the README file.
4-
with open("README.md", "r") as fh:
5+
with open(file="README.md", mode="r") as fh:
56
long_description = fh.read()
67

78
setup(
@@ -16,7 +17,7 @@
1617

1718
# I'm in alpha development still, so a compliant version number is a1.
1819
# read this as MAJOR VERSION 0, MINOR VERSION 1, MAINTENANCE VERSION 0
19-
version='0.2.9',
20+
version='0.3.0',
2021

2122
# here is a simple description of the library, this will appear when
2223
# someone searches for the library on https://pypi.org/search

td/app/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from configparser import ConfigParser
66
from requests_oauthlib import OAuth2Session
77
from datetime import datetime
8-
from td.defaults import StatePath
8+
from td.utils import StatePath
99

1010
from typing import Union
1111
from typing import List

td/client.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,34 @@
66
import requests
77
import urllib.parse
88

9-
from . import defaults
10-
119
from typing import Any
1210
from typing import Dict
1311
from typing import List
1412
from typing import Union
1513
from typing import Optional
1614

15+
from td.utils import StatePath
16+
from td.utils import TDUtilities
17+
1718
from td.orders import Order
1819
from td.orders import OrderLeg
19-
from td.defaults import StatePath
2020
from td.stream import TDStreamerClient
2121
from td.option_chain import OptionChain
22-
from td.fields import VALID_CHART_VALUES
23-
from td.fields import ENDPOINT_ARGUMENTS
24-
from td.app.auth import FlaskTDAuth
22+
23+
from td.enums import VALID_CHART_VALUES
24+
from td.enums import ENDPOINT_ARGUMENTS
25+
2526
from td.oauth import run
2627
from td.oauth import shutdown
27-
from td.exceptions import TknExpError, ExdLmtError, NotNulError, ForbidError, NotFndError, ServerError, GeneralError
28+
from td.app.auth import FlaskTDAuth
29+
30+
from td.exceptions import TknExpError
31+
from td.exceptions import ExdLmtError
32+
from td.exceptions import NotNulError
33+
from td.exceptions import ForbidError
34+
from td.exceptions import NotFndError
35+
from td.exceptions import ServerError
36+
from td.exceptions import GeneralError
2837

2938
class TDClient():
3039

@@ -105,6 +114,7 @@ def __init__(self, client_id: str, redirect_uri: str, account_number: str = None
105114
self.account_number = account_number
106115
self.credentials_path = StatePath(credentials_file=credentials_path)
107116
self._redirect_code = None
117+
self._td_utilities = TDUtilities()
108118

109119
if self.auth_flow == 'flask':
110120
self._flask_app = FlaskTDAuth(
@@ -546,8 +556,8 @@ def _make_request(self, method: str, endpoint: str, mode: str = None, params: di
546556
else:
547557
order_id = ''
548558

559+
# If it's okay and we need details, then add them.
549560
if response.ok and order_details:
550-
551561
response_dict = {
552562
'order_id':order_id,
553563
'headers':response_headers,
@@ -559,19 +569,11 @@ def _make_request(self, method: str, endpoint: str, mode: str = None, params: di
559569

560570
return response_dict
561571

572+
# If it's okay and no details.
562573
elif response.ok:
563-
564574
return response.json()
565575

566576
else:
567-
568-
print('='*80)
569-
print("RESPONSE STATUS CODE: {status_code}".format(status_code=status_code))
570-
print("RESPONSE URL: {url}".format(url=response.url))
571-
print("RESPONSE HEADERS: {headers}".format(headers=response.headers))
572-
print("RESPONSE PARAMS: {params}".format(params=response.links))
573-
print("RESPONSE TEXT: {text}".format(text=response.text))
574-
print('-'*80)
575577

576578
if response.status_code == 400:
577579
raise NotNulError(message=response.text)
@@ -745,17 +747,13 @@ def get_price_history(self, symbol: str, period_type:str = None, period: str = N
745747
elif (not start_date and not end_date and period):
746748

747749
# Attempt to grab the key, if it fails we know there is an error.
748-
try:
750+
# check if the period is valid.
751+
if int(period) in VALID_CHART_VALUES[frequency_type][period_type]:
752+
True
753+
else:
754+
raise IndexError('Invalid Period.')
749755

750-
# check if the period is valid.
751-
if period in VALID_CHART_VALUES[frequency_type][int(period_type)]:
752-
True
753-
else:
754-
raise IndexError('Invalid Period.')
755-
except:
756-
raise KeyError('Invalid Frequency Type or Period Type you passed through is not valid')
757-
758-
if frequency_type == 'minute' and frequency not in ['1', '5', '10', '15', '30']:
756+
if frequency_type == 'minute' and int(frequency) not in [1, 5, 10, 15, 30]:
759757
raise ValueError('Invalid Minute Frequency, must be 1,5,10,15,30')
760758

761759
# build the params dictionary
@@ -2027,7 +2025,8 @@ def create_streaming_session(self) -> TDStreamerClient:
20272025

20282026
# Grab the Streamer Info.
20292027
userPrincipalsResponse = self.get_user_principals(
2030-
fields=['streamerConnectionInfo','streamerSubscriptionKeys','preferences','surrogateIds'])
2028+
fields=['streamerConnectionInfo','streamerSubscriptionKeys','preferences','surrogateIds']
2029+
)
20312030

20322031

20332032
# Grab the timestampe.
@@ -2038,7 +2037,8 @@ def create_streaming_session(self) -> TDStreamerClient:
20382037

20392038
# Parse the token timestamp.
20402039
tokenTimeStampAsMs = self._create_token_timestamp(
2041-
token_timestamp=tokenTimeStamp)
2040+
token_timestamp=tokenTimeStamp
2041+
)
20422042

20432043
# Define our Credentials Dictionary used for authentication.
20442044
credentials = {

0 commit comments

Comments
 (0)