p123api 1.4.2__tar.gz → 1.4.4__tar.gz
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.
- {p123api-1.4.2 → p123api-1.4.4}/PKG-INFO +1 -1
- {p123api-1.4.2 → p123api-1.4.4}/p123api/client.py +32 -17
- {p123api-1.4.2 → p123api-1.4.4}/p123api.egg-info/PKG-INFO +1 -1
- {p123api-1.4.2 → p123api-1.4.4}/setup.py +1 -1
- {p123api-1.4.2 → p123api-1.4.4}/LICENSE +0 -0
- {p123api-1.4.2 → p123api-1.4.4}/README.md +0 -0
- {p123api-1.4.2 → p123api-1.4.4}/p123api/__init__.py +0 -0
- {p123api-1.4.2 → p123api-1.4.4}/p123api.egg-info/SOURCES.txt +0 -0
- {p123api-1.4.2 → p123api-1.4.4}/p123api.egg-info/dependency_links.txt +0 -0
- {p123api-1.4.2 → p123api-1.4.4}/p123api.egg-info/top_level.txt +0 -0
- {p123api-1.4.2 → p123api-1.4.4}/setup.cfg +0 -0
|
@@ -44,12 +44,21 @@ class Client(object):
|
|
|
44
44
|
class for interfacing with P123 API
|
|
45
45
|
"""
|
|
46
46
|
|
|
47
|
-
def __init__(
|
|
47
|
+
def __init__(
|
|
48
|
+
self,
|
|
49
|
+
*,
|
|
50
|
+
api_id,
|
|
51
|
+
api_key,
|
|
52
|
+
auth_param_name: str = None,
|
|
53
|
+
auth_param_value=None,
|
|
54
|
+
):
|
|
48
55
|
self._endpoint = ENDPOINT
|
|
49
56
|
self._verify_requests = True
|
|
50
57
|
self._max_req_retries = 5
|
|
51
58
|
self._timeout = 300
|
|
52
59
|
self._token = None
|
|
60
|
+
self._auth_param_name = auth_param_name
|
|
61
|
+
self._auth_param_value = auth_param_value
|
|
53
62
|
|
|
54
63
|
if not isinstance(api_id, str) or not api_id:
|
|
55
64
|
raise ClientException("api_id needs to be a non empty str")
|
|
@@ -89,11 +98,14 @@ class Client(object):
|
|
|
89
98
|
if session expires.
|
|
90
99
|
:return: bool
|
|
91
100
|
"""
|
|
101
|
+
json = {"apiId": self._api_id, "apiKey": self._api_key}
|
|
102
|
+
if self._auth_param_name is not None and self._auth_param_value is not None:
|
|
103
|
+
json[self._auth_param_name] = self._auth_param_value
|
|
92
104
|
resp = req_with_retry(
|
|
93
105
|
self._session.post,
|
|
94
106
|
self._max_req_retries,
|
|
95
107
|
url=self._endpoint + AUTH_PATH,
|
|
96
|
-
|
|
108
|
+
json=json,
|
|
97
109
|
verify=self._verify_requests,
|
|
98
110
|
timeout=30,
|
|
99
111
|
)
|
|
@@ -183,7 +195,7 @@ class Client(object):
|
|
|
183
195
|
message = ": " + message
|
|
184
196
|
raise ClientException(f"API request failed{message}", resp=resp)
|
|
185
197
|
|
|
186
|
-
def screen_rolling_backtest(self, params: dict, to_pandas
|
|
198
|
+
def screen_rolling_backtest(self, params: dict, to_pandas=False):
|
|
187
199
|
"""
|
|
188
200
|
Screen rolling backtest
|
|
189
201
|
:param params:
|
|
@@ -208,7 +220,7 @@ class Client(object):
|
|
|
208
220
|
|
|
209
221
|
return ret
|
|
210
222
|
|
|
211
|
-
def screen_backtest(self, params: dict, to_pandas
|
|
223
|
+
def screen_backtest(self, params: dict, to_pandas=False):
|
|
212
224
|
"""
|
|
213
225
|
Screen backtest
|
|
214
226
|
:param params:
|
|
@@ -304,7 +316,7 @@ class Client(object):
|
|
|
304
316
|
|
|
305
317
|
return ret
|
|
306
318
|
|
|
307
|
-
def screen_run(self, params: dict, to_pandas
|
|
319
|
+
def screen_run(self, params: dict, to_pandas=False):
|
|
308
320
|
"""
|
|
309
321
|
Screen run
|
|
310
322
|
:param params:
|
|
@@ -340,7 +352,7 @@ class Client(object):
|
|
|
340
352
|
name="ranking system update", url=self._endpoint + RANK_PATH, params=params
|
|
341
353
|
).json()
|
|
342
354
|
|
|
343
|
-
def data(self, params: dict, to_pandas
|
|
355
|
+
def data(self, params: dict, to_pandas=False):
|
|
344
356
|
"""
|
|
345
357
|
Data
|
|
346
358
|
:param params:
|
|
@@ -378,7 +390,7 @@ class Client(object):
|
|
|
378
390
|
|
|
379
391
|
return ret
|
|
380
392
|
|
|
381
|
-
def data_universe(self, params: dict, to_pandas
|
|
393
|
+
def data_universe(self, params: dict, to_pandas=False):
|
|
382
394
|
"""
|
|
383
395
|
Universe data
|
|
384
396
|
:param params:
|
|
@@ -392,8 +404,9 @@ class Client(object):
|
|
|
392
404
|
if to_pandas:
|
|
393
405
|
raw_obj = ret
|
|
394
406
|
names = params.get("names")
|
|
407
|
+
f_indices = range(len(params["formulas"]))
|
|
395
408
|
if params.get("asOfDt"):
|
|
396
|
-
for formula_idx
|
|
409
|
+
for formula_idx in f_indices:
|
|
397
410
|
name = (
|
|
398
411
|
names[formula_idx]
|
|
399
412
|
if names is not None
|
|
@@ -414,16 +427,18 @@ class Client(object):
|
|
|
414
427
|
includeFigi = True
|
|
415
428
|
formulas = defaultdict(list)
|
|
416
429
|
for dtObj in ret["dates"]:
|
|
417
|
-
data["dates"]
|
|
418
|
-
|
|
419
|
-
|
|
430
|
+
data["dates"].extend(
|
|
431
|
+
dtObj["dt"] for _ in range(len(dtObj["p123Uids"]))
|
|
432
|
+
)
|
|
433
|
+
data["p123Uids"].extend(dtObj["p123Uids"])
|
|
434
|
+
data["tickers"].extend(dtObj["tickers"])
|
|
420
435
|
if includeNames:
|
|
421
|
-
data["names"]
|
|
436
|
+
data["names"].extend(dtObj["names"])
|
|
422
437
|
if includeFigi:
|
|
423
|
-
data["figi"]
|
|
424
|
-
for formula_idx
|
|
425
|
-
formulas[formula_idx]
|
|
426
|
-
for formula_idx
|
|
438
|
+
data["figi"].extend(dtObj["figi"])
|
|
439
|
+
for formula_idx in f_indices:
|
|
440
|
+
formulas[formula_idx].extend(dtObj["data"][formula_idx])
|
|
441
|
+
for formula_idx in f_indices:
|
|
427
442
|
name = (
|
|
428
443
|
names[formula_idx]
|
|
429
444
|
if names is not None
|
|
@@ -435,7 +450,7 @@ class Client(object):
|
|
|
435
450
|
|
|
436
451
|
return ret
|
|
437
452
|
|
|
438
|
-
def rank_ranks(self, params: dict, to_pandas
|
|
453
|
+
def rank_ranks(self, params: dict, to_pandas=False):
|
|
439
454
|
"""
|
|
440
455
|
Ranking system ranks
|
|
441
456
|
:param params:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|