kwess 0.0.5__py3-none-any.whl → 0.0.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
kwess/__init__.py CHANGED
@@ -35,7 +35,7 @@ class Trader:
35
35
  - server_type could be 2 possible values: "live" or "test". "live" will allow you to
36
36
  interact with your real Questrade account. "test" is for interacting with your test
37
37
  account.
38
- - timeout number of seconds to wait for the API server to respond before giving up.
38
+ - timeout number of seconds to wait for the server to respond before giving up.
39
39
  Defaults to 15 seconds. Set timeout to None if you wish to wait forever for a response.
40
40
  - verbose level of verbosity represented by the number of characters in a string.
41
41
  Defaults to empty string. Maximum verbosity is 1 or "v".
@@ -88,7 +88,7 @@ class Trader:
88
88
  def get_new_refresh_token(self, token, verbose=''):
89
89
  """
90
90
  Description:
91
- Obtains a new refresh token (and new access token) from the API server.
91
+ Obtains a new refresh token (and new access token) from the Authorization server.
92
92
  You generally would not need to call this method, as it is potentially called by Trader
93
93
  during initialization.
94
94
  Trader will only call this method if the access token has expired.
@@ -231,8 +231,8 @@ class Trader:
231
231
  datetime objects.
232
232
  Parameters:
233
233
  - startdatetime datetime object specifying the start of a range.
234
- - enddatetime optional datetime object specifying the end of a range. Defaults to
235
- now (datetime.datetime.now()) if not specified.
234
+ - enddatetime optional datetime object specifying the end of a range.
235
+ Defaults to now (datetime.datetime.now()) if not specified.
236
236
  - accounttype type of Questrade account. Defaults to "tfsa".
237
237
  - verbose level of verbosity represented by the number of characters in a string.
238
238
  Defaults to empty string. Maximum verbosity is 3 or "vvv".
@@ -334,7 +334,7 @@ class Trader:
334
334
  Description:
335
335
  Higher level helper method used to build a Questrade datetime string.
336
336
  Parameters:
337
- - adatetime a datetime object.
337
+ - adatetime a datetime object. Defaults to now.
338
338
  - gmt optional boolean indicating if datetime is Greenwich Mean Time.
339
339
  Default value is False.
340
340
  Returns:
@@ -454,7 +454,7 @@ class Trader:
454
454
 
455
455
 
456
456
  @get_all
457
- def get_account_executions(self, accounttype="TFSA", startdatetime=None, enddatetime=None, verbose=''):
457
+ def get_account_executions(self, startdatetime, enddatetime=None, accounttype="TFSA", verbose=''):
458
458
  """
459
459
  Description:
460
460
  Generator that provides account executions from the account related to account type
@@ -588,7 +588,7 @@ class Trader:
588
588
 
589
589
 
590
590
  @get_all
591
- def get_market_candles(self, sid, interval, startdatetime=None, enddatetime=None, verbose=''):
591
+ def get_market_candles(self, sid, interval, startdatetime, enddatetime=None, verbose=''):
592
592
  """
593
593
  Description:
594
594
  Provides a list of json formatted market candles.
@@ -0,0 +1,505 @@
1
+ Metadata-Version: 2.1
2
+ Name: kwess
3
+ Version: 0.0.7
4
+ Summary: Questrade API wrapper.
5
+ Home-page: https://github.com/kaiyoux/kwess
6
+ Author: Issa Lompo
7
+ Author-email: kaiyoux@gmail.com
8
+ Maintainer: Issa Lompo
9
+ Maintainer-email: kaiyoux@gmail.com
10
+ License: GNU General Public License v3 (GPLv3)
11
+ Project-URL: Bug Tracker, https://github.com/kaiyoux/kwess/issues
12
+ Keywords: Questrade,api,REST,wrapper
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Development Status :: 5 - Production/Stable
17
+ Classifier: Intended Audience :: Developers
18
+ Requires-Python: >=3.6
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE.txt
21
+ Requires-Dist: requests >=2.28.1
22
+
23
+ # Introduction
24
+
25
+ Yet another Questrade API wrapper.
26
+
27
+ For details about the input parameters and output results, please visit
28
+ the [Questrade API documentation](https://www.questrade.com/api/home).
29
+
30
+ ### To install:
31
+ **python -m pip install kwess**
32
+
33
+
34
+ # Usage Example
35
+
36
+ ```
37
+ import kwess
38
+ from datetime import datetime as dt
39
+ from pprint import pprint
40
+
41
+ # It is assumed that your manually generated token has been saved in local file
42
+ # my_token.txt
43
+ qs = kwess.Trader(rt_file="my_token.txt", verbose="v")
44
+
45
+ accs = qs.get_accounts()
46
+ for acc in accs:
47
+ print(acc, "\n")
48
+
49
+ accn = qs.find_account_number("tfsa")
50
+ print(accn)
51
+
52
+ # Get account activities from 1/12/1999 to 28/9/2022
53
+ accs = qs.get_account_activities(startdatetime=dt(year=1999, month=12, day=1), \
54
+ enddatetime=dt(year=2022, month=9, day=28), verbose="xxx")
55
+ for acc in accs:
56
+ print(acc, "\n")
57
+
58
+ # Get (all types of) TFSA account orders from 17/8/2022 to now
59
+ # Questrade does not seem to keep old account orders - only the most recent
60
+ accs = qs.get_account_orders(startdatetime=dt(year=2022, month=8, day=17), \
61
+ verbose="vv")
62
+ for acc in accs:
63
+ print(acc, "\n")
64
+
65
+ # Get margin account orders that are still open
66
+ accs = qs.get_account_orders(accounttype="margin", startdatetime=dt(year=2022, \
67
+ month=7, day=28), enddatetime=dt.now(), statefilter="opened", verbose="333")
68
+ for acc in accs:
69
+ print(acc, "\n")
70
+
71
+ ords = qs.get_account_orders_by_ids(accounttype="tfsa", orderid="1088713788", \
72
+ verbose="b")
73
+ pprint(ords)
74
+
75
+ ords = qs.get_account_orders_by_ids(orderid="1098747429,1088752426,1088713788", \
76
+ verbose="aa")
77
+ pprint(ords)
78
+
79
+ ords = qs.get_account_orders_by_ids(orderid=1098747429)
80
+ pprint(ords)
81
+
82
+ # Get the current time from the API server
83
+ dto = qs.get_server_time()
84
+ print(dto[0])
85
+ print(dto[1])
86
+
87
+ # Questrade does not seem to keep old account executions - only the most recent
88
+ excs = qs.get_account_executions(startdatetime=dt(year=2022, month=1, day=28), \
89
+ enddatetime=dt(year=2022, month=9, day=30), verbose="o")
90
+ for exc in excs:
91
+ print(exc, "\n")
92
+
93
+ accs = qs.get_account_balances()
94
+ print(accs)
95
+
96
+ accs = qs.get_account_positions(verbose="d")
97
+ print(accs)
98
+
99
+ sim = qs.search_symbols("vfv", verbose="88")
100
+ print(sim)
101
+
102
+ sim = qs.get_symbols_by_names("xdiv.to,xuu.to,cve.to", verbose="**")
103
+ print(sim)
104
+
105
+ sim = qs.get_symbols_by_names("hom.un.to")
106
+ print(sim)
107
+
108
+ sim = qs.get_symbols_by_ids(26070347, verbose="e")
109
+ print(sim)
110
+
111
+ sim = qs.get_symbols_by_ids("26070347,12890,8953192,18070692", verbose="ee")
112
+ print(sim)
113
+
114
+ sim = qs.get_symbol_options(12890, verbose="s")
115
+ pprint(sim)
116
+
117
+ mks = qs.get_markets()
118
+ pprint(mks)
119
+
120
+ mks = qs.get_market_quotes(12890,verbose="zz")
121
+ print(mks)
122
+
123
+ mks = qs.get_market_quotes("26070347,12890,8953192,18070692", verbose="h")
124
+ print(mks)
125
+
126
+ ops = qs.get_market_quotes_options(option_ids=[9907637,9907638])
127
+ pprint(ops)
128
+
129
+ ```
130
+
131
+
132
+ # API Class And Methods
133
+
134
+ class Trader
135
+ ```
136
+ __init__(self, rt_file='refreshToken', server_type='live', timeout=15, verbose='')
137
+ Description:
138
+ Initializer of a Trader object. Before creating a Trader object (for the very
139
+ first time or when the present token has expired), you must generate a new
140
+ token for manual authorization from your Questrade APP HUB, and save that
141
+ manually generated token in a local file. That local file's filename
142
+ (or pathname) is passed to rt_file.
143
+ When Trader creates a Trader object, it exchanges that manually obtained token
144
+ for an access token and a refresh token. The access token expires in 30 minutes
145
+ and the refresh token expires in three days.
146
+ As long as the refresh token has not expired, creating Trader objects or
147
+ calling method get_new_refresh_token will obtain a new access token (if the
148
+ current access token has expired) and obtain a new replacement refresh token
149
+ that will last for another 3 days.
150
+ Technically, as long as the current refresh token has not expired, it is
151
+ possible to keep exchanging the current refresh token for a new access token and
152
+ new refresh token pair indefinitely (by creating Trader objects or calling
153
+ method get_new_refresh_token).
154
+ If the refresh token ever expires, you must log back into your Questrade account,
155
+ generate a new token for manual authorization under APP HUB, and save that token
156
+ in the local file referred to by rt_file.
157
+ Parameters:
158
+ - rt_file name of your local file containing your refresh token.
159
+ Defaults to "refreshToken".
160
+ - server_type could be 2 possible values: "live" or "test".
161
+ "live" will allow you to interact with your real Questrade account.
162
+ "test" is for interacting with your test account.
163
+ - timeout number of seconds to wait for the server to respond before
164
+ giving up.
165
+ Defaults to 15 seconds. Set timeout to None if you wish to wait forever
166
+ for a response.
167
+ - verbose level of verbosity represented by the number of characters in a string.
168
+ Defaults to empty string. Maximum verbosity is 1 or "v".
169
+ Returns:
170
+ Trader object.
171
+
172
+
173
+ build_datetime_string(self, adatetime=None, gmt=False)
174
+ Description:
175
+ Higher level helper method used to build a Questrade datetime string.
176
+ Parameters:
177
+ - adatetime a datetime object. Defaults to now.
178
+ - gmt optional boolean indicating if datetime is Greenwich Mean Time.
179
+ Default value is False.
180
+ Returns:
181
+ A Questrade datetime string.
182
+
183
+
184
+ find_account_number(self, accounttype)
185
+ Description:
186
+ Finds the account number corresponding to account type.
187
+ Parameters:
188
+ - accounttype the type of account. Example "tfsa", "margin", etc.
189
+ Returns:
190
+ An account number in string format.
191
+
192
+
193
+ get_account_activities(self, startdatetime, enddatetime=None, accounttype='TFSA',
194
+ verbose='')
195
+ Description:
196
+ Generator that returns the account activities from the account related to account
197
+ type accounttype, between the range specified by startdatetime and enddatetime.
198
+ Both objects are datetime objects.
199
+ Parameters:
200
+ - startdatetime datetime object specifying the start of a range.
201
+ - enddatetime optional datetime object specifying the end of a range.
202
+ Defaults to now (datetime.datetime.now()) if not specified.
203
+ - accounttype type of Questrade account.
204
+ Defaults to "tfsa".
205
+ - verbose level of verbosity represented by the number of characters in a string.
206
+ Defaults to empty string. Maximum verbosity is 3 or "vvv".
207
+ Yields:
208
+ The account activities as a Python object representation of the returned json,
209
+ between the range startdatetime and enddatetime, in chunks of 30 days.
210
+
211
+
212
+ get_account_balances(self, accounttype='TFSA', verbose='')
213
+ Definition:
214
+ Provides the account balances for the account related to account type
215
+ accounttype.
216
+ Paramaters:
217
+ - accounttype type of Questrade account.
218
+ Defaults to "tfsa".
219
+ - verbose level of verbosity represented by the number of characters in
220
+ a string.
221
+ Defaults to empty string. Maximum verbosity is 2 or "vv".
222
+ Returns:
223
+ Account balances as a Python object representation of the returned json.
224
+
225
+
226
+ get_account_executions(self, startdatetime, enddatetime=None,
227
+ accounttype='TFSA', verbose='')
228
+ Description:
229
+ Generator that provides account executions from the account related to
230
+ account type accounttype, between the range specified by startdatetime and
231
+ enddatetime. Both objects are datetime objects.
232
+ Parameters:
233
+ - startdatetime datetime object representing the beginning of a range.
234
+ - enddatetime datetime object representing the end of a range.
235
+ Defaults to now (datetime.datetime.now()) if not specified.
236
+ - accounttype type of Questrade account.
237
+ Defaults to "tfsa".
238
+ - verbose level of verbosity represented by the number of characters in
239
+ a string.
240
+ Defaults to empty string. Maximum verbosity is 3 or "vvv".
241
+ Yields:
242
+ Account executions as a Python object representation of the returned json,
243
+ between the range startdatetime and enddatetime, in chunks of 30 days.
244
+
245
+
246
+ get_account_orders(self, startdatetime, enddatetime=None, accounttype='TFSA',
247
+ statefilter='All', verbose='')
248
+ Description:
249
+ Generator that provides the account orders from the account related to
250
+ account type accounttype, between the range specified by startdatetime and
251
+ enddatetime. Both objects are datetime objects.
252
+ Parameters:
253
+ - startdatetime datetime object representing the beginning of a range.
254
+ - enddatetime optional datetime object representing the end of a range.
255
+ Defaults to now (datetime.datetime.now()) if not specified.
256
+ - accounttype type of Questrade account.
257
+ Defaults to "tfsa".
258
+ - statefilter can be used to specify the state of orders.
259
+ It has 3 possible values: Opened, Closed, or All.
260
+ Defaults to "All".
261
+ - verbose level of verbosity represented by the number of characters in a string.
262
+ Defaults to empty string. Maximum verbosity is 3 or "vvv".
263
+ Yields:
264
+ Account orders as a Python object representation of the returned json,
265
+ between the range startdatetime and enddatetime, in chunks of 30 days.
266
+
267
+
268
+ get_account_orders_by_ids(self, orderid, accounttype='TFSA', verbose='')
269
+ Description:
270
+ Provides the account orders, specified by orderid, from the account related to
271
+ account type accounttype.
272
+ Parameters:
273
+ - orderid is a string of one or many orderid numbers. Several orderid numbers are
274
+ seperated by commas (with no spaces). A single orderid could be passed as
275
+ a numeral instead of a string.
276
+ - accounttype type of Questrade account.
277
+ Defaults to "tfsa".
278
+ - verbose level of verbosity represented by the number of characters in a string.
279
+ Defaults to empty string. Maximum verbosity is 2 or "vv".
280
+ Returns:
281
+ Account orders as a Python object representation of the returned json.
282
+
283
+
284
+ get_account_positions(self, accounttype='TFSA', verbose='')
285
+ Definition:
286
+ Provides the account positions for the account related to account type
287
+ accounttype.
288
+ Paramaters:
289
+ - accounttype type of Questrade account.
290
+ Defaults to "tfsa".
291
+ - verbose level of verbosity represented by the number of characters in a string.
292
+ Defaults to empty string. Maximum verbosity is 2 or "vv".
293
+ Returns:
294
+ Account positions as a Python object representation of the returned json.
295
+
296
+
297
+ get_accounts(self, verbose='')
298
+ Description:
299
+ Generator that provides the accounts.
300
+ Parameters:
301
+ - verbose level of verbosity represented by the number of characters in a string.
302
+ Defaults to empty string. Maximum verbosity is 1 or "v".
303
+ Yields:
304
+ All your Questrade accounts as a Python object representation of the returned
305
+ json.
306
+
307
+
308
+ get_market_candles(self, sid, interval, startdatetime, enddatetime=None,
309
+ verbose='')
310
+ Description:
311
+ Provides a list of json formatted market candles.
312
+ Parameters:
313
+ - sid symbol id as a string or numeral.
314
+ - interval is the Historical Data Granularity.
315
+ Examples: "OneMinute", "HalfHour", "OneYear".
316
+ - startdatetime datetime object representing the beginning of a range.
317
+ - enddatetime datetime object representing the end of a range.
318
+ Defaults to now if not specified.
319
+ - verbose level of verbosity represented by the number of characters in a string.
320
+ Defaults to empty string. Maximum verbosity is 2 or "vv".
321
+ Returns:
322
+ Historical market data in the form of OHLC candlesticks for a specified symbol
323
+ as a Python object representation of the returned json.
324
+ This call is limited to returning 2,000 candlesticks in a single response.
325
+ sid is a symbol id.
326
+
327
+
328
+ get_market_quotes(self, ids, verbose='')
329
+ Definition:
330
+ Provides market quotes data.
331
+ Parameter:
332
+ - ids Internal symbol identifier. Could be a single value or a string of values.
333
+ - verbose level of verbosity represented by the number of characters in a string.
334
+ Defaults to empty string. Maximum verbosity is 2 or "vv".
335
+ Returns:
336
+ A single Level 1 market data quote for one or more symbols in json string format
337
+ as a Python object representation of the returned json.
338
+ IMPORTANT NOTE: Questrade user needs to be subscribed to a real-time data
339
+ package, to receive market quotes in real-time, otherwise call to get quote
340
+ is considered snap quote and limit per market can be quickly reached.
341
+ Without real-time data package, once limit is reached, the response will return
342
+ delayed data. (Please check "delay" parameter in response always).
343
+
344
+
345
+ get_market_quotes_options(self, option_ids, filters=None, verbose='')
346
+ Definition:
347
+ Provides market quotes options.
348
+ Parameters:
349
+ - option_ids is a list of stock option ids.
350
+ - filters optional list of dictionary items.
351
+ - verbose level of verbosity represented by the number of characters in a string.
352
+ Defaults to empty string. Maximum verbosity is 2 or "vv".
353
+ Returns:
354
+ A single Level 1 market data quote and Greek data for one or more option symbols
355
+ as a Python object representation of the returned json.
356
+
357
+
358
+ get_market_quotes_strategies(self, variants, verbose='')
359
+ Definition:
360
+ Provides a calculated L1 market data quote for a single or many multi-leg
361
+ strategies.
362
+ Parameter:
363
+ - variants is a list of dictionary items.
364
+ - verbose level of verbosity represented by the number of characters in a string.
365
+ Defaults to empty string. Maximum verbosity is 2 or "vv".
366
+ Returns:
367
+ A calculated L1 market data quote for a single or many multi-leg strategies
368
+ as a Python object representation of the returned json.
369
+
370
+
371
+ get_markets(self, verbose='')
372
+ Description:
373
+ Provides market data.
374
+ Parameters:
375
+ - verbose level of verbosity represented by the number of characters in a string.
376
+ Defaults to empty string. Maximum verbosity is 2 or "vv".
377
+ Returns:
378
+ Information about supported markets as a Python object representation of
379
+ the returned json.
380
+
381
+
382
+ get_new_refresh_token(self, token, server_type, verbose='')
383
+ Description:
384
+ Obtains a new refresh token (and new access token) from the Authorization server.
385
+ You generally would not need to call this method, as it is potentially called by
386
+ Trader during initialization.
387
+ Trader will only call this method if the access token has expired.
388
+ Parameters:
389
+ - token the refresh token that is stored in the local file pointed to by rt_file.
390
+ - server_type should be "live" or "test" for your live Questrade account or
391
+ your test Questrade account, respectively.
392
+ - verbose level of verbosity represented by the number of characters in a string.
393
+ Defaults to empty string. Maximum verbosity is 1 or "v".
394
+
395
+
396
+ get_server_time(self, verbose='')
397
+ Description:
398
+ Provides the time from the Questrade API server.
399
+ Parameters:
400
+ - verbose level of verbosity represented by the number of characters in a string.
401
+ Defaults to empty string. Maximum verbosity is 2 or "vv".
402
+ Returns:
403
+ The time on the server as a tuple made of a simple datetime object,
404
+ as well as in the expected Python object representation of the returned json.
405
+
406
+
407
+ get_symbol_options(self, sid, verbose='')
408
+ Definition:
409
+ Provides symbol options data.
410
+ Parameter:
411
+ - sid Internal symbol identifier.
412
+ - verbose level of verbosity represented by the number of characters in a string.
413
+ Defaults to empty string. Maximum verbosity is 2 or "vv".
414
+ Returns:
415
+ An option chain for a particular underlying symbol as a Python object
416
+ representation of the returned json.
417
+
418
+
419
+ get_symbols_by_ids(self, ids, verbose='')
420
+ Definition:
421
+ Provides symbols data from symbol id(s).
422
+ Parameter:
423
+ - ids Internal symbol identifier(s). Could be a single numeric value or a string
424
+ of comma-seperated values (with no spaces).
425
+ - verbose level of verbosity represented by the number of characters in a string.
426
+ Defaults to empty string. Maximum verbosity is 2 or "vv".
427
+ Returns:
428
+ Detailed information about one or more symbol as a Python object representation
429
+ of the returned json.
430
+
431
+
432
+ get_symbols_by_names(self, names, verbose='')
433
+ Definition:
434
+ Provides symbols data from name(s).
435
+ Parameter:
436
+ - names is a string of names seperated by commas (with no spaces).
437
+ - verbose level of verbosity represented by the number of characters in a string.
438
+ Defaults to empty string. Maximum verbosity is 2 or "vv".
439
+ Returns:
440
+ Detailed information about one or more symbol as a Python object representation
441
+ of the returned json.
442
+
443
+
444
+ object_to_qdstr(self, dto, gmt=False)
445
+ Description:
446
+ Converts a datetime object to a Questrade datetime string.
447
+ Parameters:
448
+ - dto datetime object.
449
+ - gmt optional boolean indicating if datetime is Greenwich Mean Time.
450
+ Default value is False.
451
+ Returns:
452
+ The provided datetime object in Questrade API compatible string format.
453
+ Example: "2011-02-01T00:00:00-05:00".
454
+ If gmt is set to False, time will be in local time.
455
+ If gmt is True, the returned time will be considered as gmt time.
456
+
457
+
458
+ search_symbols(self, prefix, offset=0, verbose='')
459
+ Definition:
460
+ Provides symbol(s) data using several search criteria.
461
+ Parameters:
462
+ - prefix Prefix of a symbol or any word in the description.
463
+ - offset Offset in number of records from the beginning of a result set.
464
+ Default is not to offset.
465
+ - verbose level of verbosity represented by the number of characters in a string.
466
+ Defaults to empty string. Maximum verbosity is 2 or "vv".
467
+ Returns:
468
+ Symbol(s) data as a Python object representation of the returned json.
469
+
470
+
471
+ values_to_dobj(self, y, m, d, h=0, mi=0, s=0)
472
+ Description:
473
+ Helper method that builds a datetime object.
474
+ Parameters:
475
+ - y integer to be set as the year.
476
+ - m intiger to be set as the month.
477
+ - d integer to be set as the day.
478
+ - h optional integer to be set as the hour. Default value is 0.
479
+ - mi optional integer to be set as the minutes. Default value is 0.
480
+ - s optional integer to be set as the seconds. Default value is 0.
481
+ Returns:
482
+ A datetime object from the values provided as parameters.
483
+
484
+
485
+ values_to_qdstr(self, y, m, d, h=0, mi=0, s=0, gmt=False)
486
+ Description:
487
+ Helper method that builds a Questrade datetime string.
488
+ - y integer to be set as the year.
489
+ - m intiger to be set as the month.
490
+ - d integer to be set as the day.
491
+ - h optional integer to be set as the hour. Default value is 0.
492
+ - mi optional integer to be set as the minutes. Default value is 0.
493
+ - s optional integer to be set as the seconds. Default value is 0.
494
+ - gmt optional boolean indicating if datetime is Greenwich Mean Time.
495
+ Default value is False.
496
+ Returns:
497
+ The date time and timezone values provided as parameters in Questrade API
498
+ compatible string format.
499
+ Example: "2011-02-01T00:00:00-05:00".
500
+ If gmt is set to False, time will be in local time.
501
+ If gmt is True, the returned time will be considered as gmt time.
502
+ ```
503
+
504
+
505
+ Let me know if you have any questions: <kaiyoux@gmail.com>
@@ -0,0 +1,7 @@
1
+ kwess/__init__.py,sha256=hG0J_zyNPRCVd-_VEbg9a26HvtfcbdnkUHpRJ0PhyGI,43967
2
+ kwess-0.0.7.dist-info/LICENSE.txt,sha256=gcuuhKKc5-dwvyvHsXjlC9oM6N5gZ6umYbC8ewW1Yvg,35821
3
+ kwess-0.0.7.dist-info/METADATA,sha256=MbNWz6np_171fBoycthEz60AQ7kqj3APbDS7sykUpH0,19940
4
+ kwess-0.0.7.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
5
+ kwess-0.0.7.dist-info/top_level.txt,sha256=jdYzcYQHwnZajr9CyHMIRBi6MrEGYTJ-uaAT3M50kP0,6
6
+ kwess-0.0.7.dist-info/zip-safe,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
7
+ kwess-0.0.7.dist-info/RECORD,,
@@ -1,480 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: kwess
3
- Version: 0.0.5
4
- Summary: Questrade API wrapper.
5
- Home-page: https://github.com/kaiyoux/kwess
6
- Author: Issa Lompo
7
- Author-email: kaiyoux@gmail.com
8
- Maintainer: Issa Lompo
9
- Maintainer-email: kaiyoux@gmail.com
10
- License: GNU General Public License v3 (GPLv3)
11
- Project-URL: Bug Tracker, https://github.com/kaiyoux/kwess/issues
12
- Keywords: Questrade,api,REST,wrapper
13
- Classifier: Programming Language :: Python :: 3
14
- Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
15
- Classifier: Operating System :: OS Independent
16
- Classifier: Development Status :: 5 - Production/Stable
17
- Classifier: Intended Audience :: Developers
18
- Requires-Python: >=3.6
19
- Description-Content-Type: text/markdown
20
- License-File: LICENSE.txt
21
- Requires-Dist: requests >=2.28.1
22
-
23
- # Introduction
24
-
25
- Yet another Questrade API wrapper.
26
-
27
- For details about the input parameters and output results, please visit
28
- the [Questrade API documentation](https://www.questrade.com/api/home).
29
-
30
- ### To install:
31
- **python -m pip install kwess**
32
-
33
-
34
- # Usage Example
35
-
36
- ```
37
- import kwess
38
- from datetime import datetime as dt
39
- from pprint import pprint
40
-
41
- # It is assumed that your manually generated token has been saved in local file my_token.txt
42
- qs = kwess.Trader(rt_file="my_token.txt", verbose="v")
43
-
44
- accs = qs.get_accounts()
45
- for acc in accs:
46
- print(acc, "\n")
47
-
48
- accn = qs.find_account_number("tfsa")
49
- print(accn)
50
-
51
- # Get account activities from 1/12/1999 to 28/9/2022
52
- accs = qs.get_account_activities(startdatetime=dt(year=1999, month=12, day=1), enddatetime=dt(year=2022, month=9, day=28), verbose="xxx")
53
- for acc in accs:
54
- print(acc, "\n")
55
-
56
- # Get (all types of) TFSA account orders from 17/8/2022 to now
57
- accs = qs.get_account_orders(startdatetime=dt(year=2022, month=8, day=17), verbose="vv")
58
- for acc in accs:
59
- print(acc, "\n")
60
-
61
- # Get margin account orders that are still open
62
- accs = qs.get_account_orders(accounttype="margin", startdatetime=dt(year=2022, month=7, day=28), enddatetime=dt.now(), statefilter="opened", verbose="333")
63
- for acc in accs:
64
- print(acc, "\n")
65
-
66
- ords = qs.get_account_orders_by_ids(accounttype="tfsa", orderid="1088713788", verbose="b")
67
- pprint(ords)
68
-
69
- ords = qs.get_account_orders_by_ids(orderid="1098747429,1088752426,1088713788", verbose="aa")
70
- pprint(ords)
71
-
72
- ords = qs.get_account_orders_by_ids(orderid=1098747429)
73
- pprint(ords)
74
-
75
- # Get the current time from the API server
76
- dto = qs.get_server_time()
77
- print(dto[0])
78
- print(dto[1])
79
-
80
- # Questrade does not seem to keep old account executions - only the most recent
81
- excs = qs.get_account_executions(startdatetime=dt(year=2022, month=1, day=28), enddatetime=dt(year=2022, month=9, day=30), verbose="o")
82
- for exc in excs:
83
- print(exc, "\n")
84
-
85
- accs = qs.get_account_balances()
86
- print(accs)
87
-
88
- accs = qs.get_account_positions(verbose="d")
89
- print(accs)
90
-
91
- sim = qs.search_symbols("vfv", verbose="88")
92
- print(sim)
93
-
94
- sim = qs.get_symbols_by_names("xdiv.to,xuu.to,cve.to", verbose="**")
95
- print(sim)
96
-
97
- sim = qs.get_symbols_by_names("hom.un.to")
98
- print(sim)
99
-
100
- sim = qs.get_symbols_by_ids(26070347, verbose="e")
101
- print(sim)
102
-
103
- sim = qs.get_symbols_by_ids("26070347,12890,8953192,18070692", verbose="ee")
104
- print(sim)
105
-
106
- sim = qs.get_symbol_options(12890, verbose="s")
107
- pprint(sim)
108
-
109
- mks = qs.get_markets()
110
- pprint(mks)
111
-
112
- mks = qs.get_market_quotes(12890,verbose="zz")
113
- print(mks)
114
-
115
- mks = qs.get_market_quotes("26070347,12890,8953192,18070692", verbose="h")
116
- print(mks)
117
-
118
- ops = qs.get_market_quotes_options(option_ids=[9907637,9907638])
119
- pprint(ops)
120
-
121
- ```
122
-
123
-
124
- # API Class And Methods
125
-
126
- class Trader
127
- ```
128
- __init__(self, rt_file='refreshToken', server_type='live', timeout=15, verbose='')
129
- Description:
130
- Initializer of a Trader object. Before creating a Trader object
131
- (for the very first time or when the present token has expired),
132
- you must generate a new token for manual authorization from your Questrade APP HUB,
133
- and save that manually generated token in a local file. That local file's filename
134
- (or pathname) is passed to rt_file.
135
- When Trader creates a Trader object, it exchanges that manually obtained token for an
136
- access token and a refresh token. The access token expires in 30 minutes and
137
- the refresh token expires in three days.
138
- As long as the refresh token has not expired, creating Trader objects or calling method
139
- get_new_refresh_token will obtain a new access token (if the current access token has
140
- expired) and obtain a new replacement refresh token that will last for another 3 days.
141
- Technically, as long as the current refresh token has not expired, it is possible
142
- to keep exchanging the current refresh token for a new access token and new refresh
143
- token pair indefinitely (by creating Trader objects or calling method
144
- get_new_refresh_token).
145
- If the refresh token ever expires, you must log back into your Questrade account,
146
- generate a new token for manual authorization under APP HUB, and save that token
147
- in the local file referred to by rt_file.
148
- Parameters:
149
- - rt_file name of your local file containing your refresh token.
150
- Defaults to "refreshToken".
151
- - server_type could be 2 possible values: "live" or "test". "live" will allow you to
152
- interact with your real Questrade account. "test" is for interacting with your test
153
- account.
154
- - timeout number of seconds to wait for the API server to respond before giving up.
155
- Defaults to 15 seconds. Set timeout to None if you wish to wait forever for a response.
156
- - verbose level of verbosity represented by the number of characters in a string.
157
- Defaults to empty string. Maximum verbosity is 1 or "v".
158
- Returns:
159
- Trader object.
160
-
161
-
162
- build_datetime_string(self, adatetime=None, gmt=False)
163
- Description:
164
- Higher level helper method used to build a Questrade datetime string.
165
- Parameters:
166
- - adatetime a datetime object.
167
- - gmt optional boolean indicating if datetime is Greenwich Mean Time.
168
- Default value is False.
169
- Returns:
170
- A Questrade datetime string.
171
-
172
-
173
- find_account_number(self, accounttype)
174
- Description:
175
- Finds the account number corresponding to account type.
176
- Parameters:
177
- - accounttype the type of account. Example "tfsa", "margin", etc.
178
- Returns:
179
- An account number in string format.
180
-
181
-
182
- get_account_activities(self, startdatetime, enddatetime=None, accounttype='TFSA', verbose='')
183
- Description:
184
- Generator that returns the account activities from the account related to account
185
- type accounttype,
186
- between the range specified by startdatetime and enddatetime. Both objects are
187
- datetime objects.
188
- Parameters:
189
- - startdatetime datetime object specifying the start of a range.
190
- - enddatetime optional datetime object specifying the end of a range. Defaults to
191
- now (datetime.datetime.now()) if not specified.
192
- - accounttype type of Questrade account. Defaults to "tfsa".
193
- - verbose level of verbosity represented by the number of characters in a string.
194
- Defaults to empty string. Maximum verbosity is 3 or "vvv".
195
- Yields:
196
- The account activities as a Python object representation of the returned json,
197
- between the range startdatetime and enddatetime, in chunks of 30 days.
198
-
199
-
200
- get_account_balances(self, accounttype='TFSA', verbose='')
201
- Definition:
202
- Provides the account balances for the account related to account type accounttype.
203
- Paramaters:
204
- - accounttype type of Questrade account. Defaults to "tfsa".
205
- - verbose level of verbosity represented by the number of characters in a string.
206
- Defaults to empty string. Maximum verbosity is 2 or "vv".
207
- Returns:
208
- Account balances as a Python object representation of the returned json.
209
-
210
-
211
- get_account_executions(self, accounttype='TFSA', startdatetime=None, enddatetime=None, verbose='')
212
- Description:
213
- Generator that provides account executions from the account related to account type
214
- accounttype,
215
- between the range specified by startdatetime and enddatetime.
216
- Both objects are datetime objects.
217
- Parameters:
218
- - startdatetime datetime object representing the beginning of a range.
219
- - enddatetime datetime object representing the end of a range.
220
- Defaults to now (datetime.datetime.now()) if not specified.
221
- - accounttype type of Questrade account. Defaults to "tfsa".
222
- - verbose level of verbosity represented by the number of characters in a string.
223
- Defaults to empty string. Maximum verbosity is 3 or "vvv".
224
- Yields:
225
- Account executions as a Python object representation of the returned json,
226
- between the range startdatetime and enddatetime, in chunks of 30 days.
227
-
228
-
229
- get_account_orders(self, startdatetime, enddatetime=None, accounttype='TFSA', statefilter='All', verbose='')
230
- Description:
231
- Generator that provides the account orders from the account related to account type
232
- accounttype,
233
- between the range specified by startdatetime and enddatetime. Both objects are
234
- datetime objects.
235
- Parameters:
236
- - startdatetime datetime object representing the beginning of a range.
237
- - enddatetime optional datetime object representing the end of a range.
238
- Defaults to now (datetime.datetime.now()) if not specified.
239
- - accounttype type of Questrade account. Defaults to "tfsa".
240
- - statefilter can be used to specify the state of orders.
241
- It has 3 possible values: Opened, Closed, or All. Defaults to "All".
242
- - verbose level of verbosity represented by the number of characters in a string.
243
- Defaults to empty string. Maximum verbosity is 3 or "vvv".
244
- Yields:
245
- Account orders as a Python object representation of the returned json,
246
- between the range startdatetime and enddatetime, in chunks of 30 days.
247
-
248
-
249
- get_account_orders_by_ids(self, orderid, accounttype='TFSA', verbose='')
250
- Description:
251
- Provides the account orders, specified by orderid, from the account related to account
252
- type accounttype,
253
- Parameters:
254
- - orderid is a string of one or many orderid numbers. Several orderid numbers are
255
- seperated by commas (with no spaces).
256
- a single orderid could be passed as a numeral instead of a string.
257
- - accounttype type of Questrade account. Defaults to "tfsa".
258
- - verbose level of verbosity represented by the number of characters in a string.
259
- Defaults to empty string. Maximum verbosity is 2 or "vv".
260
- Returns:
261
- Account orders as a Python object representation of the returned json.
262
-
263
-
264
- get_account_positions(self, accounttype='TFSA', verbose='')
265
- Definition:
266
- Provides the account positions for the account related to account type accounttype.
267
- Paramaters:
268
- - accounttype type of Questrade account. Defaults to "tfsa".
269
- - verbose level of verbosity represented by the number of characters in a string.
270
- Defaults to empty string. Maximum verbosity is 2 or "vv".
271
- Returns:
272
- Account positions as a Python object representation of the returned json.
273
-
274
-
275
- get_accounts(self, verbose='')
276
- Description:
277
- Generator that provides the accounts.
278
- Parameters:
279
- - verbose level of verbosity represented by the number of characters in a string.
280
- Defaults to empty string. Maximum verbosity is 1 or "v".
281
- Yields:
282
- All your Questrade accounts as a Python object representation of the returned json.
283
-
284
-
285
- get_market_candles(self, sid, interval, startdatetime=None, enddatetime=None, verbose='')
286
- Description:
287
- Provides a list of json formatted market candles.
288
- Parameters:
289
- - sid symbol id as a string or numeral.
290
- - interval is the Historical Data Granularity.
291
- Examples: "OneMinute", "HalfHour", "OneYear".
292
- - startdatetime datetime object representing the beginning of a range.
293
- - enddatetime datetime object representing the end of a range.
294
- Defaults to now if not specified.
295
- - verbose level of verbosity represented by the number of characters in a string.
296
- Defaults to empty string. Maximum verbosity is 2 or "vv".
297
- Returns:
298
- Historical market data in the form of OHLC candlesticks for a specified symbol
299
- as a Python object representation of the returned json.
300
- This call is limited to returning 2,000 candlesticks in a single response.
301
- sid is a symbol id.
302
-
303
-
304
- get_market_quotes(self, ids, verbose='')
305
- Definition:
306
- Provides market quotes data.
307
- Parameter:
308
- - ids Internal symbol identifier. Could be a single value or a string of values.
309
- - verbose level of verbosity represented by the number of characters in a string.
310
- Defaults to empty string. Maximum verbosity is 2 or "vv".
311
- Returns:
312
- A single Level 1 market data quote for one or more symbols in json string format
313
- as a Python object representation of the returned json.
314
- IMPORTANT NOTE: Questrade user needs to be subscribed to a real-time data package,
315
- to receive market quotes in real-time, otherwise call to get quote is considered
316
- snap quote and limit per market can be quickly reached. Without real-time data package,
317
- once limit is reached, the response will return delayed data.
318
- (Please check "delay" parameter in response always).
319
-
320
-
321
- get_market_quotes_options(self, option_ids, filters=None, verbose='')
322
- Definition:
323
- Provides market quotes options.
324
- Parameters:
325
- - option_ids is a list of stock option ids.
326
- - filters optional list of dictionary items.
327
- - verbose level of verbosity represented by the number of characters in a string.
328
- Defaults to empty string. Maximum verbosity is 2 or "vv".
329
- Returns:
330
- A single Level 1 market data quote and Greek data for one or more option symbols
331
- as a Python object representation of the returned json.
332
-
333
-
334
- get_market_quotes_strategies(self, variants, verbose='')
335
- Definition:
336
- Provides a calculated L1 market data quote for a single or many multi-leg strategies.
337
- Parameter:
338
- - variants is a list of dictionary items.
339
- - verbose level of verbosity represented by the number of characters in a string.
340
- Defaults to empty string. Maximum verbosity is 2 or "vv".
341
- Returns:
342
- A calculated L1 market data quote for a single or many multi-leg strategies
343
- as a Python object representation of the returned json.
344
-
345
-
346
- get_markets(self, verbose='')
347
- Description:
348
- Provides market data.
349
- Parameters:
350
- - verbose level of verbosity represented by the number of characters in a string.
351
- Defaults to empty string. Maximum verbosity is 2 or "vv".
352
- Returns:
353
- Information about supported markets as a Python object representation
354
- of the returned json.
355
-
356
-
357
- get_new_refresh_token(self, token, server_type, verbose='')
358
- Description:
359
- Obtains a new refresh token (and new access token) from the API server.
360
- You generally would not need to call this method, as it is potentially called by Trader
361
- during initialization.
362
- Trader will only call this method if the access token has expired.
363
- Parameters:
364
- - token the refresh token that is stored in the local file pointed to by rt_file.
365
- - server_type should be "live" or "test" for your live Questrade account or your test
366
- Questrade account, respectively.
367
- - verbose level of verbosity represented by the number of characters in a string.
368
- Defaults to empty string. Maximum verbosity is 1 or "v".
369
-
370
-
371
- get_server_time(self, verbose='')
372
- Description:
373
- Provides the time from the Questrade API server.
374
- Parameters:
375
- - verbose level of verbosity represented by the number of characters in a string.
376
- Defaults to empty string. Maximum verbosity is 2 or "vv".
377
- Returns:
378
- The time on the server as a tuple made of a simple datetime object,
379
- as well as in the expected Python object representation of the returned json.
380
-
381
-
382
- get_symbol_options(self, sid, verbose='')
383
- Definition:
384
- Provides symbol options data.
385
- Parameter:
386
- - sid Internal symbol identifier.
387
- - verbose level of verbosity represented by the number of characters in a string.
388
- Defaults to empty string. Maximum verbosity is 2 or "vv".
389
- Returns:
390
- An option chain for a particular underlying symbol as a Python object representation
391
- of the returned json.
392
-
393
-
394
- get_symbols_by_ids(self, ids, verbose='')
395
- Definition:
396
- Provides symbols data from symbol id(s).
397
- Parameter:
398
- - ids Internal symbol identifier(s). Could be a single numeric value or a string of
399
- comma-seperated values (with no spaces).
400
- - verbose level of verbosity represented by the number of characters in a string.
401
- Defaults to empty string. Maximum verbosity is 2 or "vv".
402
- Returns:
403
- Detailed information about one or more symbol as a Python object representation
404
- of the returned json.
405
-
406
-
407
- get_symbols_by_names(self, names, verbose='')
408
- Definition:
409
- Provides symbols data from name(s).
410
- Parameter:
411
- - names is a string of names seperated by commas (with no spaces).
412
- - verbose level of verbosity represented by the number of characters in a string.
413
- Defaults to empty string. Maximum verbosity is 2 or "vv".
414
- Returns:
415
- Detailed information about one or more symbol as a Python object representation
416
- of the returned json.
417
-
418
-
419
- object_to_qdstr(self, dto, gmt=False)
420
- Description:
421
- Converts a datetime object to a Questrade datetime string.
422
- Parameters:
423
- - dto datetime object.
424
- - gmt optional boolean indicating if datetime is Greenwich Mean Time.
425
- Default value is False.
426
- Returns:
427
- The provided datetime object in Questrade API compatible string format.
428
- Example: "2011-02-01T00:00:00-05:00".
429
- If gmt is set to False, time will be in local time.
430
- If gmt is True, the returned time will be considered as gmt time.
431
-
432
-
433
- search_symbols(self, prefix, offset=0, verbose='')
434
- Definition:
435
- Provides symbol(s) data using several search criteria.
436
- Parameters:
437
- - prefix Prefix of a symbol or any word in the description.
438
- - offset Offset in number of records from the beginning of a result set.
439
- Default is not to offset.
440
- - verbose level of verbosity represented by the number of characters in a string.
441
- Defaults to empty string. Maximum verbosity is 2 or "vv".
442
- Returns:
443
- Symbol(s) data as a Python object representation of the returned json.
444
-
445
-
446
- values_to_dobj(self, y, m, d, h=0, mi=0, s=0)
447
- Description:
448
- Helper method that builds a datetime object.
449
- Parameters:
450
- - y integer to be set as the year.
451
- - m intiger to be set as the month.
452
- - d integer to be set as the day.
453
- - h optional integer to be set as the hour. Default value is 0.
454
- - mi optional integer to be set as the minutes. Default value is 0.
455
- - s optional integer to be set as the seconds. Default value is 0.
456
- Returns:
457
- A datetime object from the values provided as parameters.
458
-
459
-
460
- values_to_qdstr(self, y, m, d, h=0, mi=0, s=0, gmt=False)
461
- Description:
462
- Helper method that builds a Questrade datetime string.
463
- - y integer to be set as the year.
464
- - m intiger to be set as the month.
465
- - d integer to be set as the day.
466
- - h optional integer to be set as the hour. Default value is 0.
467
- - mi optional integer to be set as the minutes. Default value is 0.
468
- - s optional integer to be set as the seconds. Default value is 0.
469
- - gmt optional boolean indicating if datetime is Greenwich Mean Time.
470
- Default value is False.
471
- Returns:
472
- The date time and timezone values provided as parameters in Questrade API compatible
473
- string format.
474
- Example: "2011-02-01T00:00:00-05:00".
475
- If gmt is set to False, time will be in local time.
476
- If gmt is True, the returned time will be considered as gmt time.
477
- ```
478
-
479
-
480
- Let me know if you have any questions: <kaiyoux@gmail.com>
@@ -1,7 +0,0 @@
1
- kwess/__init__.py,sha256=x2-XF-Ny8fma8AyaBzPAtuBso2c8Zfjh4WfGSqJheKU,43954
2
- kwess-0.0.5.dist-info/LICENSE.txt,sha256=gcuuhKKc5-dwvyvHsXjlC9oM6N5gZ6umYbC8ewW1Yvg,35821
3
- kwess-0.0.5.dist-info/METADATA,sha256=aE1Xy4z3tvIVR3xvD7SXhCJKqdn57O-NM8hl4OB8IhA,20396
4
- kwess-0.0.5.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
5
- kwess-0.0.5.dist-info/top_level.txt,sha256=jdYzcYQHwnZajr9CyHMIRBi6MrEGYTJ-uaAT3M50kP0,6
6
- kwess-0.0.5.dist-info/zip-safe,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
7
- kwess-0.0.5.dist-info/RECORD,,
File without changes