Skip to content

Commit b0f0547

Browse files
committed
Add client changes
1 parent 8c11b0a commit b0f0547

2 files changed

Lines changed: 73 additions & 44 deletions

File tree

ibw/client.py

Lines changed: 68 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,15 @@ def _headers(self, mode: str = 'json') -> Dict:
309309
"""
310310
Returns a dictionary of default HTTP headers for calls to TD Ameritrade API,
311311
in the headers we defined the Authorization and access token.
312+
313+
Arguments:
314+
----
315+
mode {str} -- Defines the content-type for the headers dictionary.
316+
default is 'json'. Possible values are ['json','form']
312317
313-
NAME: mode
314-
DESC: Defines the content-type for the headers dictionary.
315-
default is 'json'. Possible values are ['json','form']
316-
TYPE: String
317-
318+
Returns:
319+
----
320+
Dict
318321
"""
319322

320323
if mode == 'json':
@@ -326,41 +329,43 @@ def _headers(self, mode: str = 'json') -> Dict:
326329

327330

328331
def _build_url(self, endpoint: str) -> str:
329-
"""
330-
builds a url for a request.
331-
332-
NAME: endpoint
333-
DESC: The URL that needs conversion to a full endpoint URL.
334-
TYPE: String
332+
"""Builds a url for a request.
335333
336-
RTYPE: String
334+
Arguments:
335+
----
336+
endpoint {str} -- The URL that needs conversion to a full endpoint URL.
337337
338+
Returns:
339+
----
340+
{srt} -- A full URL path.
338341
"""
339342

340343
# otherwise build the URL
341344
return urllib.parse.unquote(urllib.parse.urljoin(self.ib_gateway_path, self.api_version) + r'portal/' + endpoint)
342345

343346

344347
def _make_request(self, endpoint: str, req_type: str, params: Dict = None) -> Dict:
345-
"""
346-
Handles all the requests made by the client and correctly organizes
347-
the information so it is sent correctly. Additionally it will also
348-
build the URL.
348+
"""Handles the request to the client.
349349
350-
NAME: endpoint
351-
DESC: The endpoint we wish to request.
352-
TYPE: String
350+
Handles all the requests made by the client and correctly organizes
351+
the information so it is sent correctly. Additionally it will also
352+
build the URL.
353353
354-
NAME: type
355-
DESC: Defines the type of request to be made. Can be one of four
356-
possible values ['GET','POST','DELETE','PUT']
357-
TYPE: String
354+
Arguments:
355+
----
356+
endpoint {str} -- The endpoint we wish to request.
357+
358+
req_type {str} -- Defines the type of request to be made. Can be one of four
359+
possible values ['GET','POST','DELETE','PUT']
360+
361+
params {dict} -- Any arguments that are to be sent along in the request. That
362+
could be parameters of a 'GET' request, or a data payload of a
363+
'POST' request.
364+
365+
Returns:
366+
----
367+
{Dict} -- A response dictionary.
358368
359-
NAME: params
360-
DESC: Any arguments that are to be sent along in the request. That
361-
could be parameters of a 'GET' request, or a data payload of a
362-
'POST' request.
363-
TYPE: Dictionary
364369
"""
365370

366371
# first build the url
@@ -421,18 +426,24 @@ def _make_request(self, endpoint: str, req_type: str, params: Dict = None) -> Di
421426

422427

423428
def _prepare_arguments_list(self, parameter_list: List[str]) -> str:
424-
"""
425-
Some endpoints can take multiple values for a parameter, this
426-
method takes that list and creates a valid string that can be
427-
used in an API request. The list can have either one index or
428-
multiple indexes.
429+
"""Prepares the arguments for the request.
429430
430-
NAME: parameter_list
431-
DESC: A list of paramater values assigned to an argument.
432-
TYPE: List
431+
Some endpoints can take multiple values for a parameter, this
432+
method takes that list and creates a valid string that can be
433+
used in an API request. The list can have either one index or
434+
multiple indexes.
433435
434-
EXAMPLE:
435-
SessionObject.prepare_arguments_list(parameter_list = ['MSFT', 'SQ'])
436+
Arguments:
437+
----
438+
parameter_list {List} -- A list of paramater values assigned to an argument.
439+
440+
Usage:
441+
----
442+
>>> SessionObject._prepare_arguments_list(parameter_list=['MSFT','SQ'])
443+
444+
Returns:
445+
----
446+
{str} -- The joined list.
436447
437448
"""
438449

@@ -445,7 +456,6 @@ def _prepare_arguments_list(self, parameter_list: List[str]) -> str:
445456

446457
return parameter_list
447458

448-
449459
"""
450460
SESSION ENDPOINTS
451461
"""
@@ -1025,6 +1035,25 @@ def futures_search(self, symbols: List[str]) -> Dict:
10251035

10261036
return content
10271037

1038+
def symbols_search_list(self, symbols: List[str]) -> Dict:
1039+
"""
1040+
Returns a list of non-expired future contracts for given symbol(s).
1041+
1042+
NAME: Symbol
1043+
DESC: List of case-sensitive symbols separated by comma.
1044+
TYPE: List<String>
1045+
1046+
RTYPE: Dictionary
1047+
"""
1048+
1049+
# define the request components
1050+
endpoint = '/trsrv/stocks'
1051+
req_type = 'GET'
1052+
payload = {'symbols':'{}'.format(','.join(symbols))}
1053+
content = self._make_request(endpoint = endpoint, req_type = req_type, params = payload)
1054+
1055+
return content
1056+
10281057
"""
10291058
PORTFOLIO ACCOUNTS ENDPOINTS
10301059
"""
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
# create a new session
2323
ib_client.create_session()
2424

25-
# Logout of the client.
26-
logout_response = ib_client.logout()
27-
print(logout_response)
25+
# # Logout of the client.
26+
# logout_response = ib_client.logout()
27+
# print(logout_response)
2828

29-
# close the current session.
30-
ib_client.close_session()
29+
# # close the current session.
30+
# ib_client.close_session()
3131

3232

3333
# '''

0 commit comments

Comments
 (0)