Skip to content

Commit

Permalink
update to 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
areed1192 committed Dec 15, 2020
1 parent 45c64dc commit 5c9d1ac
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 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.3.2**
Current Version: **0.3.4**

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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# Set the version.
# For the next one do 3.4!!!
version='0.3.2',
version='0.3.4',

# here is a simple description of the library, this will appear when
# someone searches for the library on https://pypi.org/search
Expand Down
10 changes: 10 additions & 0 deletions td/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,20 @@ async def _connect(self) -> websockets.WebSocketClientProtocol:

# If we are connected then login.
if is_connected:

await self._send_message(login_request)

while True:

# Grab the Response.
response = await self._receive_message(return_value=True)
responses = response.get('response')

# If we get a code 3, we had a login error.
if responses[0]['content']['code'] == 3:
raise ValueError('LOGIN ERROR: ' + responses[0]['content']['msg'])

# see if we had a login response.
for r in responses:
if r.get('service') == 'ADMIN' and r.get('command') == 'LOGIN':
return self.connection
Expand Down
51 changes: 51 additions & 0 deletions tests/api_place_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import pprint
from td.client import TDClient
from configparser import ConfigParser

# Grab configuration values.
config = ConfigParser()
config.read('config/config.ini')

CLIENT_ID = config.get('main', 'CLIENT_ID')
REDIRECT_URI = config.get('main', 'REDIRECT_URI')
JSON_PATH = config.get('main', 'JSON_PATH')
ACCOUNT_NUMBER = config.get('main', 'ACCOUNT_NUMBER')

# Create a new session
td_session = TDClient(
client_id=CLIENT_ID,
redirect_uri=REDIRECT_URI,
credentials_path=JSON_PATH,
account_number=ACCOUNT_NUMBER
)

# Login to the session
td_session.login()

# Define the Order.
order_template = buy_limit_enter = {
"orderType": "LIMIT",
"session": "NORMAL",
"duration": "DAY",
"price": 10.0,
"orderStrategyType": "SINGLE",
"orderLegCollection": [
{
"instruction": "BUY",
"quantity": 1,
"instrument": {
"symbol": "AAL",
"assetType": "EQUITY"
}
}
]
}

# Place the Order.
order_response = td_session.place_order(
account=ACCOUNT_NUMBER,
order=order_template
)

# Print the Response.
pprint.pprint(order_response)

0 comments on commit 5c9d1ac

Please sign in to comment.