p123api 2.0.0__tar.gz → 2.2.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.2.0
4
4
  Summary: Portfolio123 API wrapper
5
5
  Home-page: https://github.com/portfolio-123/p123api-py
6
6
  Author: Portfolio123
@@ -18,8 +18,13 @@ 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")
24
+ STRATEGY_TRADING_SYSTEM_PATH = Template("/strategy/$id/trading-system")
25
+ BOOK_TRADING_SYSTEM_PATH = Template("/strategy/$id/book-trading-system")
26
+ SIM_RERUN_PATH = Template("/strategy/$id/rerun")
27
+ BOOK_SIM_RERUN_PATH = Template("/strategy/$id/book-rerun")
23
28
  STRATEGY_REBALANCE_PATH = Template("/strategy/$id/rebalance")
24
29
  STRATEGY_REBALANCE_COMMIT_PATH = Template("/strategy/$id/rebalance/commit")
25
30
  STRATEGY_TRANS_PATH = Template("/strategy/$id/transactions")
@@ -130,6 +135,7 @@ class Client:
130
135
  name: str,
131
136
  method: str = "POST",
132
137
  url: str,
138
+ json=None,
133
139
  params=None,
134
140
  data=None,
135
141
  headers=None,
@@ -140,6 +146,7 @@ class Client:
140
146
  :param name: request action
141
147
  :param method: request method
142
148
  :param url: request url
149
+ :param json: request json
143
150
  :param params: request params
144
151
  :param data: request data
145
152
  :param headers: request headers
@@ -153,7 +160,8 @@ class Client:
153
160
  self._session.post,
154
161
  self._max_req_retries,
155
162
  url=url,
156
- json=params,
163
+ json=json,
164
+ params=params,
157
165
  verify=self._verify_requests,
158
166
  timeout=self._timeout,
159
167
  data=data,
@@ -167,18 +175,20 @@ class Client:
167
175
  req_type,
168
176
  self._max_req_retries,
169
177
  url=url,
170
- json=params,
178
+ json=json,
179
+ params=params,
171
180
  verify=self._verify_requests,
172
181
  timeout=self._timeout,
173
182
  headers=headers,
174
183
  )
175
- if resp is None or resp.status_code == 403:
184
+ if resp is None or resp.status_code == 401 or resp.status_code == 403:
176
185
  if not stop:
177
186
  self.auth()
178
187
  return self._req_with_auth_fallback(
179
188
  name=name,
180
189
  method=method,
181
190
  url=url,
191
+ json=json,
182
192
  params=params,
183
193
  data=data,
184
194
  headers=headers,
@@ -204,7 +214,7 @@ class Client:
204
214
  ret = self._req_with_auth_fallback(
205
215
  name="screen rolling backtest",
206
216
  url=self._endpoint + SCREEN_ROLLING_BACKTEST_PATH,
207
- params=params,
217
+ json=params,
208
218
  ).json()
209
219
 
210
220
  if to_pandas:
@@ -229,7 +239,7 @@ class Client:
229
239
  ret = self._req_with_auth_fallback(
230
240
  name="screen backtest",
231
241
  url=self._endpoint + SCREEN_BACKTEST_PATH,
232
- params=params,
242
+ json=params,
233
243
  ).json()
234
244
 
235
245
  if to_pandas:
@@ -323,7 +333,7 @@ class Client:
323
333
  :return:
324
334
  """
325
335
  ret = self._req_with_auth_fallback(
326
- name="screen backtest", url=self._endpoint + SCREEN_RUN_PATH, params=params
336
+ name="screen backtest", url=self._endpoint + SCREEN_RUN_PATH, json=params
327
337
  ).json()
328
338
 
329
339
  if to_pandas:
@@ -338,7 +348,7 @@ class Client:
338
348
  :return:
339
349
  """
340
350
  return self._req_with_auth_fallback(
341
- name="universe update", url=self._endpoint + UNIVERSE_PATH, params=params
351
+ name="universe update", url=self._endpoint + UNIVERSE_PATH, json=params
342
352
  ).json()
343
353
 
344
354
  def rank_update(self, params: dict):
@@ -348,7 +358,7 @@ class Client:
348
358
  :return:
349
359
  """
350
360
  return self._req_with_auth_fallback(
351
- name="ranking system update", url=self._endpoint + RANK_PATH, params=params
361
+ name="ranking system update", url=self._endpoint + RANK_PATH, json=params
352
362
  ).json()
353
363
 
354
364
  def data(self, params: dict, to_pandas=False):
@@ -359,7 +369,7 @@ class Client:
359
369
  :return:
360
370
  """
361
371
  ret = self._req_with_auth_fallback(
362
- name="data", url=self._endpoint + DATA_PATH, params=params
372
+ name="data", url=self._endpoint + DATA_PATH, json=params
363
373
  ).json()
364
374
 
365
375
  if to_pandas:
@@ -397,7 +407,7 @@ class Client:
397
407
  :return:
398
408
  """
399
409
  ret = self._req_with_auth_fallback(
400
- name="data universe", url=self._endpoint + DATA_UNIVERSE_PATH, params=params
410
+ name="data universe", url=self._endpoint + DATA_UNIVERSE_PATH, json=params
401
411
  ).json()
402
412
 
403
413
  if to_pandas:
@@ -459,7 +469,7 @@ class Client:
459
469
  ret = self._req_with_auth_fallback(
460
470
  name="ranking system ranks",
461
471
  url=self._endpoint + RANK_RANKS_PATH,
462
- params=params,
472
+ json=params,
463
473
  ).json()
464
474
 
465
475
  if to_pandas:
@@ -503,7 +513,7 @@ class Client:
503
513
  return self._req_with_auth_fallback(
504
514
  name="ranking system performance",
505
515
  url=self._endpoint + RANK_PERF_PATH,
506
- params=params,
516
+ json=params,
507
517
  ).json()
508
518
 
509
519
  def rank_touch(self, rank_id: int):
@@ -596,7 +606,7 @@ class Client:
596
606
  name="strategy transaction delete",
597
607
  method="DELETE",
598
608
  url=self._endpoint + STRATEGY_TRANS_PATH.substitute(id=strategy_id),
599
- params=params,
609
+ json=params,
600
610
  ).json()
601
611
 
602
612
  def strategy_holdings(
@@ -619,6 +629,77 @@ class Client:
619
629
  ).json()
620
630
 
621
631
  return pandas.DataFrame(ret["holdings"]) if to_pandas else ret
632
+
633
+ def strategy_trading_system(
634
+ self, strategy_id: int
635
+ ):
636
+ """
637
+ Strategy trading system
638
+ :param strategy_id:
639
+ :return:
640
+ """
641
+
642
+ return self._req_with_auth_fallback(
643
+ name="strategy trading system",
644
+ method="GET",
645
+ url=self._endpoint + STRATEGY_TRADING_SYSTEM_PATH.substitute(id=strategy_id)
646
+ ).json()
647
+
648
+ def strategy_trading_system_update(self, strategy_id: int, params: dict):
649
+ """
650
+ Live strategy trading system update
651
+ :param strategy_id:
652
+ :param params:
653
+ :return:
654
+ """
655
+
656
+ return self._req_with_auth_fallback(
657
+ name="live strategy trading system update",
658
+ url=self._endpoint + STRATEGY_TRADING_SYSTEM_PATH.substitute(id=strategy_id),
659
+ json=params,
660
+ ).json()
661
+
662
+ def book_trading_system_update(self, strategy_id: int, params: dict):
663
+ """
664
+ Live book trading system update
665
+ :param strategy_id:
666
+ :param params:
667
+ :return:
668
+ """
669
+
670
+ return self._req_with_auth_fallback(
671
+ name="live book trading system update",
672
+ url=self._endpoint + BOOK_TRADING_SYSTEM_PATH.substitute(id=strategy_id),
673
+ json=params,
674
+ ).json()
675
+
676
+ def strategy_rerun(self, strategy_id: int, params: dict):
677
+ """
678
+ Simulated strategy rerun
679
+ :param strategy_id:
680
+ :param params:
681
+ :return:
682
+ """
683
+
684
+ return self._req_with_auth_fallback(
685
+ name="simulated strategy rerun",
686
+ url=self._endpoint + SIM_RERUN_PATH.substitute(id=strategy_id),
687
+ json=params,
688
+ ).json()
689
+
690
+ def book_rerun(self, strategy_id: int, params: dict):
691
+ """
692
+ Simulated book rerun
693
+ :param strategy_id:
694
+ :param params:
695
+ :return:
696
+ """
697
+
698
+ return self._req_with_auth_fallback(
699
+ name="simulated book rerun",
700
+ url=self._endpoint + BOOK_SIM_RERUN_PATH.substitute(id=strategy_id),
701
+ json=params,
702
+ ).json()
622
703
 
623
704
  def strategy_rebalance(self, strategy_id: int, params: dict):
624
705
  """
@@ -631,7 +712,7 @@ class Client:
631
712
  ret = self._req_with_auth_fallback(
632
713
  name="strategy rebalance",
633
714
  url=self._endpoint + STRATEGY_REBALANCE_PATH.substitute(id=strategy_id),
634
- params=params,
715
+ json=params,
635
716
  ).json()
636
717
 
637
718
  return ret
@@ -648,7 +729,7 @@ class Client:
648
729
  name="strategy rebalance commit",
649
730
  url=self._endpoint
650
731
  + STRATEGY_REBALANCE_COMMIT_PATH.substitute(id=strategy_id),
651
- params=params,
732
+ json=params,
652
733
  ).json()
653
734
 
654
735
  return ret
@@ -707,7 +788,7 @@ class Client:
707
788
  return self._req_with_auth_fallback(
708
789
  name="stock factor create/update",
709
790
  url=self._endpoint + STOCK_FACTOR_CREATE_UPDATE_PATH,
710
- params=params,
791
+ json=params,
711
792
  ).json()
712
793
 
713
794
  def stock_factor_delete(self, factor_id: int):
@@ -776,7 +857,7 @@ class Client:
776
857
  return self._req_with_auth_fallback(
777
858
  name="data series create/update",
778
859
  url=self._endpoint + DATA_SERIES_CREATE_UPDATE_PATH,
779
- params=params,
860
+ json=params,
780
861
  ).json()
781
862
 
782
863
  def data_series_delete(self, series_id: int):
@@ -804,7 +885,7 @@ class Client:
804
885
  ret = self._req_with_auth_fallback(
805
886
  name="AI Factor predict",
806
887
  url=self._endpoint + AIFACTOR_PREDICT_PATH.substitute(id=predictor_id),
807
- params=params,
888
+ json=params,
808
889
  ).json()
809
890
 
810
891
  if to_pandas:
@@ -848,6 +929,20 @@ class Client:
848
929
  method="GET",
849
930
  url=self._endpoint + STOCK_FACTOR_DOWNLOAD_PATH.substitute(id=factor_id),
850
931
  ).json()
932
+
933
+ def data_prices(self, identifier: Union[int, str], start: str, end: Optional[str], to_pandas=False):
934
+ """
935
+ """
936
+ get_params = [("start", start)]
937
+ if end is not None:
938
+ get_params.append(("end", end))
939
+ ret = self._req_with_auth_fallback(
940
+ name="download security prices",
941
+ method="GET",
942
+ url=self._endpoint + DATA_PRICES_PATH.substitute(identifier=identifier),
943
+ params=get_params
944
+ ).json()
945
+ return pandas.DataFrame(ret["prices"]) if to_pandas else ret
851
946
 
852
947
 
853
948
  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.2.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.2.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