p123api 2.0.0__tar.gz → 2.1.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: p123api
3
- Version: 2.0.0
3
+ Version: 2.1.0
4
4
  Summary: Portfolio123 API wrapper
5
5
  Home-page: https://github.com/portfolio-123/p123api-py
6
6
  Author: Portfolio123
@@ -18,6 +18,7 @@ RANK_RANKS_PATH = "/rank/ranks"
18
18
  RANK_PERF_PATH = "/rank/performance"
19
19
  RANK_TOUCH_PATH = Template("/rank/$id/touch")
20
20
  DATA_UNIVERSE_PATH = "/data/universe"
21
+ DATA_PRICES_PATH = Template("/data/prices/$identifier")
21
22
  STRATEGY_DETAILS_PATH = Template("/strategy/$id")
22
23
  STRATEGY_HOLDINGS_PATH = Template("/strategy/$id/holdings")
23
24
  STRATEGY_REBALANCE_PATH = Template("/strategy/$id/rebalance")
@@ -130,6 +131,7 @@ class Client:
130
131
  name: str,
131
132
  method: str = "POST",
132
133
  url: str,
134
+ json=None,
133
135
  params=None,
134
136
  data=None,
135
137
  headers=None,
@@ -140,6 +142,7 @@ class Client:
140
142
  :param name: request action
141
143
  :param method: request method
142
144
  :param url: request url
145
+ :param json: request json
143
146
  :param params: request params
144
147
  :param data: request data
145
148
  :param headers: request headers
@@ -153,7 +156,8 @@ class Client:
153
156
  self._session.post,
154
157
  self._max_req_retries,
155
158
  url=url,
156
- json=params,
159
+ json=json,
160
+ params=params,
157
161
  verify=self._verify_requests,
158
162
  timeout=self._timeout,
159
163
  data=data,
@@ -167,18 +171,20 @@ class Client:
167
171
  req_type,
168
172
  self._max_req_retries,
169
173
  url=url,
170
- json=params,
174
+ json=json,
175
+ params=params,
171
176
  verify=self._verify_requests,
172
177
  timeout=self._timeout,
173
178
  headers=headers,
174
179
  )
175
- if resp is None or resp.status_code == 403:
180
+ if resp is None or resp.status_code == 401 or resp.status_code == 403:
176
181
  if not stop:
177
182
  self.auth()
178
183
  return self._req_with_auth_fallback(
179
184
  name=name,
180
185
  method=method,
181
186
  url=url,
187
+ json=json,
182
188
  params=params,
183
189
  data=data,
184
190
  headers=headers,
@@ -204,7 +210,7 @@ class Client:
204
210
  ret = self._req_with_auth_fallback(
205
211
  name="screen rolling backtest",
206
212
  url=self._endpoint + SCREEN_ROLLING_BACKTEST_PATH,
207
- params=params,
213
+ json=params,
208
214
  ).json()
209
215
 
210
216
  if to_pandas:
@@ -229,7 +235,7 @@ class Client:
229
235
  ret = self._req_with_auth_fallback(
230
236
  name="screen backtest",
231
237
  url=self._endpoint + SCREEN_BACKTEST_PATH,
232
- params=params,
238
+ json=params,
233
239
  ).json()
234
240
 
235
241
  if to_pandas:
@@ -323,7 +329,7 @@ class Client:
323
329
  :return:
324
330
  """
325
331
  ret = self._req_with_auth_fallback(
326
- name="screen backtest", url=self._endpoint + SCREEN_RUN_PATH, params=params
332
+ name="screen backtest", url=self._endpoint + SCREEN_RUN_PATH, json=params
327
333
  ).json()
328
334
 
329
335
  if to_pandas:
@@ -338,7 +344,7 @@ class Client:
338
344
  :return:
339
345
  """
340
346
  return self._req_with_auth_fallback(
341
- name="universe update", url=self._endpoint + UNIVERSE_PATH, params=params
347
+ name="universe update", url=self._endpoint + UNIVERSE_PATH, json=params
342
348
  ).json()
343
349
 
344
350
  def rank_update(self, params: dict):
@@ -348,7 +354,7 @@ class Client:
348
354
  :return:
349
355
  """
350
356
  return self._req_with_auth_fallback(
351
- name="ranking system update", url=self._endpoint + RANK_PATH, params=params
357
+ name="ranking system update", url=self._endpoint + RANK_PATH, json=params
352
358
  ).json()
353
359
 
354
360
  def data(self, params: dict, to_pandas=False):
@@ -359,7 +365,7 @@ class Client:
359
365
  :return:
360
366
  """
361
367
  ret = self._req_with_auth_fallback(
362
- name="data", url=self._endpoint + DATA_PATH, params=params
368
+ name="data", url=self._endpoint + DATA_PATH, json=params
363
369
  ).json()
364
370
 
365
371
  if to_pandas:
@@ -397,7 +403,7 @@ class Client:
397
403
  :return:
398
404
  """
399
405
  ret = self._req_with_auth_fallback(
400
- name="data universe", url=self._endpoint + DATA_UNIVERSE_PATH, params=params
406
+ name="data universe", url=self._endpoint + DATA_UNIVERSE_PATH, json=params
401
407
  ).json()
402
408
 
403
409
  if to_pandas:
@@ -459,7 +465,7 @@ class Client:
459
465
  ret = self._req_with_auth_fallback(
460
466
  name="ranking system ranks",
461
467
  url=self._endpoint + RANK_RANKS_PATH,
462
- params=params,
468
+ json=params,
463
469
  ).json()
464
470
 
465
471
  if to_pandas:
@@ -503,7 +509,7 @@ class Client:
503
509
  return self._req_with_auth_fallback(
504
510
  name="ranking system performance",
505
511
  url=self._endpoint + RANK_PERF_PATH,
506
- params=params,
512
+ json=params,
507
513
  ).json()
508
514
 
509
515
  def rank_touch(self, rank_id: int):
@@ -596,7 +602,7 @@ class Client:
596
602
  name="strategy transaction delete",
597
603
  method="DELETE",
598
604
  url=self._endpoint + STRATEGY_TRANS_PATH.substitute(id=strategy_id),
599
- params=params,
605
+ json=params,
600
606
  ).json()
601
607
 
602
608
  def strategy_holdings(
@@ -631,7 +637,7 @@ class Client:
631
637
  ret = self._req_with_auth_fallback(
632
638
  name="strategy rebalance",
633
639
  url=self._endpoint + STRATEGY_REBALANCE_PATH.substitute(id=strategy_id),
634
- params=params,
640
+ json=params,
635
641
  ).json()
636
642
 
637
643
  return ret
@@ -648,7 +654,7 @@ class Client:
648
654
  name="strategy rebalance commit",
649
655
  url=self._endpoint
650
656
  + STRATEGY_REBALANCE_COMMIT_PATH.substitute(id=strategy_id),
651
- params=params,
657
+ json=params,
652
658
  ).json()
653
659
 
654
660
  return ret
@@ -707,7 +713,7 @@ class Client:
707
713
  return self._req_with_auth_fallback(
708
714
  name="stock factor create/update",
709
715
  url=self._endpoint + STOCK_FACTOR_CREATE_UPDATE_PATH,
710
- params=params,
716
+ json=params,
711
717
  ).json()
712
718
 
713
719
  def stock_factor_delete(self, factor_id: int):
@@ -776,7 +782,7 @@ class Client:
776
782
  return self._req_with_auth_fallback(
777
783
  name="data series create/update",
778
784
  url=self._endpoint + DATA_SERIES_CREATE_UPDATE_PATH,
779
- params=params,
785
+ json=params,
780
786
  ).json()
781
787
 
782
788
  def data_series_delete(self, series_id: int):
@@ -804,7 +810,7 @@ class Client:
804
810
  ret = self._req_with_auth_fallback(
805
811
  name="AI Factor predict",
806
812
  url=self._endpoint + AIFACTOR_PREDICT_PATH.substitute(id=predictor_id),
807
- params=params,
813
+ json=params,
808
814
  ).json()
809
815
 
810
816
  if to_pandas:
@@ -848,6 +854,20 @@ class Client:
848
854
  method="GET",
849
855
  url=self._endpoint + STOCK_FACTOR_DOWNLOAD_PATH.substitute(id=factor_id),
850
856
  ).json()
857
+
858
+ def data_prices(self, identifier: Union[int, str], start: str, end: Optional[str], to_pandas=False):
859
+ """
860
+ """
861
+ get_params = [("start", start)]
862
+ if end is not None:
863
+ get_params.append(("end", end))
864
+ ret = self._req_with_auth_fallback(
865
+ name="download security prices",
866
+ method="GET",
867
+ url=self._endpoint + DATA_PRICES_PATH.substitute(identifier=identifier),
868
+ params=get_params
869
+ ).json()
870
+ return pandas.DataFrame(ret["prices"]) if to_pandas else ret
851
871
 
852
872
 
853
873
  def req_with_retry(req: Callable[..., requests.Response], max_tries=None, **kwargs):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: p123api
3
- Version: 2.0.0
3
+ Version: 2.1.0
4
4
  Summary: Portfolio123 API wrapper
5
5
  Home-page: https://github.com/portfolio-123/p123api-py
6
6
  Author: Portfolio123
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="p123api",
8
- version="2.0.0",
8
+ version="2.1.0",
9
9
  author="Portfolio123",
10
10
  author_email="info@portfolio123.com",
11
11
  description="Portfolio123 API wrapper",
File without changes
File without changes
File without changes
File without changes