Skip to content

Commit

Permalink
add version 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
areed1192 committed Aug 19, 2020
1 parent ddb2a48 commit d0c611f
Show file tree
Hide file tree
Showing 15 changed files with 1,400 additions and 1,277 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

## Overview

Current Version: **0.2.9**
Current Version: **0.3.0**

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.

Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from setuptools import setup, find_packages
from setuptools import setup
from setuptools import find_packages

# load the README file.
with open("README.md", "r") as fh:
with open(file="README.md", mode="r") as fh:
long_description = fh.read()

setup(
Expand All @@ -16,7 +17,7 @@

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

# here is a simple description of the library, this will appear when
# someone searches for the library on https://pypi.org/search
Expand Down
2 changes: 1 addition & 1 deletion td/app/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from configparser import ConfigParser
from requests_oauthlib import OAuth2Session
from datetime import datetime
from td.defaults import StatePath
from td.utils import StatePath

from typing import Union
from typing import List
Expand Down
58 changes: 29 additions & 29 deletions td/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,34 @@
import requests
import urllib.parse

from . import defaults

from typing import Any
from typing import Dict
from typing import List
from typing import Union
from typing import Optional

from td.utils import StatePath
from td.utils import TDUtilities

from td.orders import Order
from td.orders import OrderLeg
from td.defaults import StatePath
from td.stream import TDStreamerClient
from td.option_chain import OptionChain
from td.fields import VALID_CHART_VALUES
from td.fields import ENDPOINT_ARGUMENTS
from td.app.auth import FlaskTDAuth

from td.enums import VALID_CHART_VALUES
from td.enums import ENDPOINT_ARGUMENTS

from td.oauth import run
from td.oauth import shutdown
from td.exceptions import TknExpError, ExdLmtError, NotNulError, ForbidError, NotFndError, ServerError, GeneralError
from td.app.auth import FlaskTDAuth

from td.exceptions import TknExpError
from td.exceptions import ExdLmtError
from td.exceptions import NotNulError
from td.exceptions import ForbidError
from td.exceptions import NotFndError
from td.exceptions import ServerError
from td.exceptions import GeneralError

class TDClient():

Expand Down Expand Up @@ -105,6 +114,7 @@ def __init__(self, client_id: str, redirect_uri: str, account_number: str = None
self.account_number = account_number
self.credentials_path = StatePath(credentials_file=credentials_path)
self._redirect_code = None
self._td_utilities = TDUtilities()

if self.auth_flow == 'flask':
self._flask_app = FlaskTDAuth(
Expand Down Expand Up @@ -546,8 +556,8 @@ def _make_request(self, method: str, endpoint: str, mode: str = None, params: di
else:
order_id = ''

# If it's okay and we need details, then add them.
if response.ok and order_details:

response_dict = {
'order_id':order_id,
'headers':response_headers,
Expand All @@ -559,19 +569,11 @@ def _make_request(self, method: str, endpoint: str, mode: str = None, params: di

return response_dict

# If it's okay and no details.
elif response.ok:

return response.json()

else:

print('='*80)
print("RESPONSE STATUS CODE: {status_code}".format(status_code=status_code))
print("RESPONSE URL: {url}".format(url=response.url))
print("RESPONSE HEADERS: {headers}".format(headers=response.headers))
print("RESPONSE PARAMS: {params}".format(params=response.links))
print("RESPONSE TEXT: {text}".format(text=response.text))
print('-'*80)

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

# Attempt to grab the key, if it fails we know there is an error.
try:
# check if the period is valid.
if int(period) in VALID_CHART_VALUES[frequency_type][period_type]:
True
else:
raise IndexError('Invalid Period.')

# check if the period is valid.
if period in VALID_CHART_VALUES[frequency_type][int(period_type)]:
True
else:
raise IndexError('Invalid Period.')
except:
raise KeyError('Invalid Frequency Type or Period Type you passed through is not valid')

if frequency_type == 'minute' and frequency not in ['1', '5', '10', '15', '30']:
if frequency_type == 'minute' and int(frequency) not in [1, 5, 10, 15, 30]:
raise ValueError('Invalid Minute Frequency, must be 1,5,10,15,30')

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

# Grab the Streamer Info.
userPrincipalsResponse = self.get_user_principals(
fields=['streamerConnectionInfo','streamerSubscriptionKeys','preferences','surrogateIds'])
fields=['streamerConnectionInfo','streamerSubscriptionKeys','preferences','surrogateIds']
)


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

# Parse the token timestamp.
tokenTimeStampAsMs = self._create_token_timestamp(
token_timestamp=tokenTimeStamp)
token_timestamp=tokenTimeStamp
)

# Define our Credentials Dictionary used for authentication.
credentials = {
Expand Down
Loading

0 comments on commit d0c611f

Please sign in to comment.