Skip to content

Commit

Permalink
Modify readme
Browse files Browse the repository at this point in the history
  • Loading branch information
areed1192 committed Feb 29, 2020
1 parent e105b5f commit 781f1b0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 686 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ td/__pycache__/
__pycache__/
*.py[cod]
*$py.class
samples/instructions/photos
config.py

# C extensions
*.so
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,38 +127,38 @@ If you have a project, you think I can help you with feel free to reach out at c

While in Visual Studio Code, right click anywhere in the code editor while in the `test_td_client.py` file. The following dropdown will appear:

![alt text](samples/instructions/photos/terminal_dropdown.jpg "Terminal Dropdown")
![alt text](https://github.com/areed1192/td-ameritrade-python-api/blob/master/samples/instructions/photos/terminal_dropdown.jpg "Terminal Dropdown")

From the dropdown, click `Run Python file in Terminal`, this will start the python script.

**Step 2 - Go to Redirect URL:**

The TD Library will automatically generate the redirect URL that will navigate you to the TD website for for you authentication. You can either copy the link and paste it into a browser manually or if you're using Visual Studio Code you can press `CTRL + Click` to have Visual Studio Code navigate you to the URL immeditately.

![alt text](samples/instructions/photos/redirect_uri.jpg "Redirect URI")
![alt text](https://github.com/areed1192/td-ameritrade-python-api/blob/master/samples/instructions/photos/redirect_uri.jpg "Redirect URI")

**Step 3 - Login to the TD API:**

Once you've arrived at the login screen, you'll need to provide your credentials to authenticate the session. Please provide your Account Username and Account Password in the userform and then press enter. As a reminder these, are the same username/password combination you use to login to your regular TD Account.

![alt text](samples/instructions/photos/td_login.jpg "TD Login")
![alt text](https://github.com/areed1192/td-ameritrade-python-api/blob/master/samples/instructions/photos/td_login.jpg "TD Login")

**Step 4 - Accept the Terms:**

Accept the Terms of the API by clicking `Allow`, this will redirect you.

![alt text](samples/instructions/photos/td_terms.jpg "TD Terms")
![alt text](https://github.com/areed1192/td-ameritrade-python-api/blob/master/samples/instructions/photos/td_terms.jpg "TD Terms")

**Step 5 - Copy the Authorization Code:**

After accepting the terms, you'll be taken to the URL that you provided as your `redirect URI`. However, at the end of that URL will be `authorization code`. To complete the authentication workflow, copy the URL as it appears below. Don't worry if the numbers don't match, as you will have a different code.

![alt text](samples/instructions/photos/auth_code.jpg "TD Terms")
![alt text](https://github.com/areed1192/td-ameritrade-python-api/blob/master/samples/instructions/photos/auth_code.jpg "TD Terms")

**Step 6 - Paste the Authorization Code in the Terminal:**

Take the URL and copy it into the Terminal, after you have pasted it, press `Enter`. The authentication workflow will complete and the script will start running. At this stage, we are exchanging your authorization code for an access token. That access token is valid only for 30 minutes. However, a refresh token is also stored that will refresh your access token when it expires.

![alt text](samples/instructions/photos/paste_url.jpg "TD Terms")
![alt text](https://github.com/areed1192/td-ameritrade-python-api/blob/master/samples/instructions/photos/paste_url.jpg "TD Terms")

After, that the script should run. Additionally, inside the `td` folder you'll notice a new JSON file called `TdAmeritradeState.json`. This file contains all the info used during a session. Please DO NOT DELETE THIS FILE OR ELSE YOU WILL NEED TO GO THROUGH THE STEPS ABOVE.
15 changes: 14 additions & 1 deletion td/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1899,8 +1899,21 @@ def place_order(self, account=None, order=None):
# make the request
response = requests.post(url=url, headers=merged_headers, data=json.dumps(order), verify=True)

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

if response.status_code == 201:
return "Order was successfully placed."
print("Order was successfully placed.")
return response
else:
return response.json()

Expand Down
Loading

0 comments on commit 781f1b0

Please sign in to comment.