p123api 2.1.0__tar.gz → 2.3.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.1.0
3
+ Version: 2.3.0
4
4
  Summary: Portfolio123 API wrapper
5
5
  Home-page: https://github.com/portfolio-123/p123api-py
6
6
  Author: Portfolio123
@@ -3,7 +3,7 @@ import requests
3
3
  import time
4
4
  import pandas
5
5
  from string import Template
6
- from typing import IO, Callable, List, Literal, Optional, Union
6
+ from typing import IO, Any, Callable, List, Literal, Optional, Union, overload
7
7
 
8
8
 
9
9
  ENDPOINT = "https://api.portfolio123.com"
@@ -21,6 +21,10 @@ DATA_UNIVERSE_PATH = "/data/universe"
21
21
  DATA_PRICES_PATH = Template("/data/prices/$identifier")
22
22
  STRATEGY_DETAILS_PATH = Template("/strategy/$id")
23
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")
24
28
  STRATEGY_REBALANCE_PATH = Template("/strategy/$id/rebalance")
25
29
  STRATEGY_REBALANCE_COMMIT_PATH = Template("/strategy/$id/rebalance/commit")
26
30
  STRATEGY_TRANS_PATH = Template("/strategy/$id/transactions")
@@ -28,6 +32,7 @@ STOCK_FACTOR_UPLOAD_PATH = Template("/stockFactor/upload/$id")
28
32
  STOCK_FACTOR_CREATE_UPDATE_PATH = "/stockFactor"
29
33
  STOCK_FACTOR_DOWNLOAD_PATH = Template("/stockFactor/$id")
30
34
  STOCK_FACTOR_DELETE_PATH = STOCK_FACTOR_DOWNLOAD_PATH
35
+ STOCK_FACTOR_INFO_PATH = STOCK_FACTOR_CREATE_UPDATE_PATH
31
36
  DATA_SERIES_UPLOAD_PATH = Template("/dataSeries/upload/$id")
32
37
  DATA_SERIES_CREATE_UPDATE_PATH = "/dataSeries"
33
38
  DATA_SERIES_DELETE_PATH = Template("/dataSeries/$id")
@@ -625,6 +630,77 @@ class Client:
625
630
  ).json()
626
631
 
627
632
  return pandas.DataFrame(ret["holdings"]) if to_pandas else ret
633
+
634
+ def strategy_trading_system(
635
+ self, strategy_id: int
636
+ ):
637
+ """
638
+ Strategy trading system
639
+ :param strategy_id:
640
+ :return:
641
+ """
642
+
643
+ return self._req_with_auth_fallback(
644
+ name="strategy trading system",
645
+ method="GET",
646
+ url=self._endpoint + STRATEGY_TRADING_SYSTEM_PATH.substitute(id=strategy_id)
647
+ ).json()
648
+
649
+ def strategy_trading_system_update(self, strategy_id: int, params: dict):
650
+ """
651
+ Live strategy trading system update
652
+ :param strategy_id:
653
+ :param params:
654
+ :return:
655
+ """
656
+
657
+ return self._req_with_auth_fallback(
658
+ name="live strategy trading system update",
659
+ url=self._endpoint + STRATEGY_TRADING_SYSTEM_PATH.substitute(id=strategy_id),
660
+ json=params,
661
+ ).json()
662
+
663
+ def book_trading_system_update(self, strategy_id: int, params: dict):
664
+ """
665
+ Live book trading system update
666
+ :param strategy_id:
667
+ :param params:
668
+ :return:
669
+ """
670
+
671
+ return self._req_with_auth_fallback(
672
+ name="live book trading system update",
673
+ url=self._endpoint + BOOK_TRADING_SYSTEM_PATH.substitute(id=strategy_id),
674
+ json=params,
675
+ ).json()
676
+
677
+ def strategy_rerun(self, strategy_id: int, params: dict):
678
+ """
679
+ Simulated strategy rerun
680
+ :param strategy_id:
681
+ :param params:
682
+ :return:
683
+ """
684
+
685
+ return self._req_with_auth_fallback(
686
+ name="simulated strategy rerun",
687
+ url=self._endpoint + SIM_RERUN_PATH.substitute(id=strategy_id),
688
+ json=params,
689
+ ).json()
690
+
691
+ def book_rerun(self, strategy_id: int, params: dict):
692
+ """
693
+ Simulated book rerun
694
+ :param strategy_id:
695
+ :param params:
696
+ :return:
697
+ """
698
+
699
+ return self._req_with_auth_fallback(
700
+ name="simulated book rerun",
701
+ url=self._endpoint + BOOK_SIM_RERUN_PATH.substitute(id=strategy_id),
702
+ json=params,
703
+ ).json()
628
704
 
629
705
  def strategy_rebalance(self, strategy_id: int, params: dict):
630
706
  """
@@ -868,6 +944,24 @@ class Client:
868
944
  params=get_params
869
945
  ).json()
870
946
  return pandas.DataFrame(ret["prices"]) if to_pandas else ret
947
+
948
+
949
+ @overload
950
+ def stock_factor_info(self, *, factor_id: int) -> Any:
951
+ ...
952
+ @overload
953
+ def stock_factor_info(self, *, name: str) -> Any:
954
+ ...
955
+ def stock_factor_info(self, *, factor_id: Optional[int] = None, name: Optional[str] = None):
956
+ """
957
+ Stock factor info, only specify factor_id or name
958
+ """
959
+ return self._req_with_auth_fallback(
960
+ name="stock factor info",
961
+ method="GET",
962
+ url=self._endpoint + STOCK_FACTOR_INFO_PATH,
963
+ params={"name": name} if factor_id is None else {"id": factor_id}
964
+ ).json()
871
965
 
872
966
 
873
967
  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.1.0
3
+ Version: 2.3.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.1.0",
8
+ version="2.3.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