investfly-sdk 1.0__py3-none-any.whl → 1.1__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.
investfly/__init__.py CHANGED
@@ -0,0 +1,3 @@
1
+ """
2
+ .. include:: ../README.md
3
+ """
@@ -3,21 +3,43 @@ import datetime
3
3
  from investfly.api.MarketDataApiClient import MarketDataApiClient
4
4
  from investfly.api.PortfolioApiClient import PortfolioApiClient
5
5
  from investfly.api.RestApiClient import RestApiClient
6
+ from investfly.api.StrategyApiClient import StrategyApiClient
7
+ from investfly.models import Session
6
8
 
7
9
 
8
10
  class InvestflyApiClient:
11
+ """
12
+ Investfly API Client. This class should be used as the entry point to make all API calls.
13
+ After authentication, access marketApi or portfolioApi to make calls to /market or /portfolio endpoints
14
+ """
9
15
 
10
16
  def __init__(self, baseUrl: str = "https://api.investfly.com"):
11
17
  self.restApiClient = RestApiClient(baseUrl)
12
18
  self.marketApi = MarketDataApiClient(self.restApiClient)
19
+ """Class used to make calls to /market endpoint """
13
20
  self.portfolioApi = PortfolioApiClient(self.restApiClient)
21
+ self.strategyApi = StrategyApiClient(self.restApiClient)
14
22
 
15
- def login(self, username, password):
23
+ def login(self, username, password) -> Session:
24
+ """
25
+ Login to investfly backend.
26
+ :param username: Username
27
+ :param password: Password
28
+ :return: Session object representing authenticated session
29
+ """
16
30
  return self.restApiClient.login(username, password)
17
31
 
18
32
  def logout(self):
19
33
  self.restApiClient.logout()
20
34
 
35
+ def isLoggedIn(self) -> bool:
36
+ return "investfly-client-id" in self.restApiClient.headers
37
+
38
+ def getSession(self) -> Session:
39
+ sessionJson = self.restApiClient.doGet('/user/session')
40
+ session: Session = Session.fromJsonDict(sessionJson)
41
+ return session
42
+
21
43
  @staticmethod
22
44
  def parseDatetime(date_str: str) -> datetime.datetime:
23
45
  return datetime.datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%f%z')
@@ -30,8 +30,8 @@ class RestApiClient:
30
30
 
31
31
  def logout(self):
32
32
  requests.post(self.baseUrl + "/user/logout", verify=False)
33
- self.clientId = None
34
- self.clientToken = None
33
+ del self.headers['investfly-client-id']
34
+ del self.headers['investfly-client-token']
35
35
 
36
36
  def doGet(self, url: str) -> Any:
37
37
  res = requests.get(self.baseUrl + url, headers=self.headers, verify=False)
@@ -0,0 +1,27 @@
1
+ from typing import List, Any, Dict
2
+ from investfly.api.RestApiClient import RestApiClient
3
+ from investfly.models.StrategyModels import TradingStrategyModel
4
+
5
+
6
+ class StrategyApiClient:
7
+
8
+ def __init__(self, restApiClient: RestApiClient) -> None:
9
+ self.restApiClient = restApiClient
10
+
11
+ def getStrategies(self) -> List[TradingStrategyModel]:
12
+ strategiesList: List[Dict[str, Any]] = self.restApiClient.doGet('/strategy/list')
13
+ strategiesList = list(filter(lambda jsonDict: jsonDict['type'] == 'CUSTOM', strategiesList))
14
+ return list(map(lambda jsonDict: TradingStrategyModel.fromDict(jsonDict), strategiesList))
15
+
16
+ def getStrategy(self, strategyId: int) -> TradingStrategyModel:
17
+ strategyDict = self.restApiClient.doGet('/strategy/' + str(strategyId))
18
+ return TradingStrategyModel.fromDict(strategyDict)
19
+
20
+ def createStrategy(self, strategyModel: TradingStrategyModel) -> TradingStrategyModel:
21
+ strategyDict = strategyModel.toDict()
22
+ strategyDict['type'] = 'CUSTOM'
23
+ strategyDict = self.restApiClient.doPost('/strategy/create', strategyDict)
24
+ return TradingStrategyModel.fromDict(strategyDict)
25
+
26
+ def updateStrategyCode(self, strategyId: int, code: str) -> str:
27
+ return self.restApiClient.doPostCode('/strategy/' + str(strategyId) + '/update/code', code)
investfly/api/__init__.py CHANGED
@@ -0,0 +1,3 @@
1
+ """ This package contains REST API Client classes to make REST API calls to Investfly Backend.
2
+ The entry point is `investfly.api.InvestflyApiClient`
3
+ """
@@ -0,0 +1,194 @@
1
+ import argparse
2
+ import pickle
3
+ import os.path
4
+ from typing import List
5
+
6
+ from investfly.api.InvestflyApiClient import InvestflyApiClient
7
+ from investfly.models import Session
8
+ from investfly.models.StrategyModels import TradingStrategyModel
9
+
10
+ from investfly import samples
11
+ import inspect
12
+ from pathlib import Path
13
+ import shutil
14
+
15
+
16
+ class InvestflyCli:
17
+
18
+ def __init__(self):
19
+ self.running: bool = True
20
+ self.investflyApi = InvestflyApiClient()
21
+
22
+
23
+ def __loginAction(self, args: argparse.Namespace) -> Session:
24
+ username = args.username
25
+ password = args.password
26
+ session = self.investflyApi.login(username, password)
27
+ return session
28
+
29
+ def __logoutAction(self, args: argparse.Namespace) -> None:
30
+ self.investflyApi.logout()
31
+
32
+ def __listStrategies(self, args: argparse.Namespace) -> str:
33
+ strategies: List[TradingStrategyModel] = self.investflyApi.strategyApi.getStrategies()
34
+ strategiesDictList = list(map(lambda model: str({'strategyId': model.strategyId, 'strategyName': model.strategyName}), strategies))
35
+ return "\n".join(strategiesDictList)
36
+
37
+ def __copySamples(self, args: argparse.Namespace) -> str:
38
+ samplesPath = inspect.getfile(samples)
39
+ path = Path(samplesPath)
40
+ parentPath = path.parent
41
+ shutil.copytree(parentPath, './samples', dirs_exist_ok=True)
42
+ return "Samples copied to ./samples directory"
43
+
44
+ def __createStrategy(self, args: argparse.Namespace) -> str:
45
+ name = args.name
46
+ path = args.file
47
+ with open(path, 'r') as source_file:
48
+ code = source_file.read()
49
+ tradingStrategyModel = TradingStrategyModel(strategyName=name, strategyDesc=name, pythonCode=code)
50
+ tradingStrategyModel = self.investflyApi.strategyApi.createStrategy(tradingStrategyModel)
51
+ return f'Created strategy {tradingStrategyModel.strategyId}'
52
+
53
+ def __updateCode(self, args: argparse.Namespace) -> str:
54
+ strategyId = int(args.id)
55
+ path = args.file
56
+ with open(path, 'r') as source_file:
57
+ code = source_file.read()
58
+ self.investflyApi.strategyApi.updateStrategyCode(strategyId, code)
59
+ return 'Code Updated'
60
+
61
+ def __exitAction(self, args: argparse.Namespace|None) -> None:
62
+ if self.investflyApi.isLoggedIn():
63
+ self.investflyApi.logout()
64
+ self.running = False
65
+
66
+ def runCli(self) -> None:
67
+ parser = argparse.ArgumentParser(prog="investfly-cli")
68
+ subparser = parser.add_subparsers(help='Available Commands', dest="command")
69
+
70
+ parser_login = subparser.add_parser('login', help='Login to Investfly')
71
+ parser_login.add_argument('-u', '--username', required=True, help='Input username')
72
+ parser_login.add_argument('-p', '--password', required=True, help='Input user password')
73
+ parser_login.set_defaults(func=self.__loginAction)
74
+
75
+ parser_logout = subparser.add_parser('logout', help="Logout from Investfly")
76
+ parser_logout.set_defaults(func=self.__logoutAction)
77
+
78
+ parser_listStrategies = subparser.add_parser('listStrategies', help='List Python Strategies')
79
+ parser_listStrategies.set_defaults(func=self.__listStrategies)
80
+
81
+ parser_copySamples = subparser.add_parser('copySamples', help='Copy Samples from SDK')
82
+ parser_copySamples.set_defaults(func=self.__copySamples)
83
+
84
+ parser_createStrategy = subparser.add_parser('createStrategy', help='Create a new trading strategy')
85
+ parser_createStrategy.add_argument('-n', '--name', required=True, help='Strategy Name')
86
+ parser_createStrategy.add_argument('-f', '--file', required=True, help='Python File Path relative to the project root that contains strategy code')
87
+ parser_createStrategy.set_defaults(func=self.__createStrategy)
88
+
89
+ parser_updateCode = subparser.add_parser('updateStrategyCode', help='Update strategy Python Code')
90
+ parser_updateCode.add_argument('-i', '--id', required=True, help='Strategy ID')
91
+ parser_updateCode.add_argument('-f', '--file', required=True, help='Python File Path relative to the project root that contains strategy code')
92
+ parser_updateCode.set_defaults(func=self.__updateCode)
93
+
94
+
95
+ parser_exit = subparser.add_parser('exit', help='Stop and Exit CLI')
96
+ parser_exit.set_defaults(func = self.__exitAction)
97
+
98
+ while self.running:
99
+ try:
100
+ data = input("\ninvestfly-cli$ ")
101
+ args = parser.parse_args(data.split())
102
+ if args.command is None:
103
+ # When user hits Enter without any command
104
+ parser.print_help()
105
+ else:
106
+ result = args.func(args)
107
+ if result is not None:
108
+ print(result)
109
+ except SystemExit:
110
+ # System exit is caught because when -h is used, argparser displays help and exists the apputils with SystemExit
111
+ pass
112
+ except KeyboardInterrupt:
113
+ self.__exitAction(None)
114
+ except Exception as e:
115
+ print("Received exception " + str(e))
116
+
117
+
118
+
119
+ def main():
120
+ investflyCli = InvestflyCli()
121
+ investflyCli.runCli()
122
+
123
+ # # Check to see if user already has a session active
124
+ # if os.path.exists('/tmp/loginSession'):
125
+ # tmpfile = open('/tmp/loginSession', 'rb')
126
+ # restApi = pickle.load(tmpfile)
127
+ # tmpfile.close()
128
+ # else:
129
+ # restApi = StrategyApiClient("https://api.investfly.com")
130
+ #
131
+ # # CLI Commands
132
+ # parser = argparse.ArgumentParser()
133
+ # subparser = parser.add_subparsers(dest='command')
134
+ #
135
+ # parser_login = subparser.add_parser('login', help='Login to Investfly')
136
+ # parser_login.add_argument('-u', '--username', required='true', help='Input username')
137
+ # parser_login.add_argument('-p', '--password', required='true', help='Input user password')
138
+ #
139
+ # subparser.add_parser('whoami', help='View your user information')
140
+ #
141
+ # subparser.add_parser('logout', help='Logout')
142
+ #
143
+ # parser_strategy = subparser.add_parser('strategy', help='View all your current strategies')
144
+ # parser_strategy.add_argument('-id', help='Provide the Strategy ID')
145
+ # parser_strategy.add_argument('-o', '--output-file', help='Provide a location to save the output file of a custom strategy (Requires Strategy ID)')
146
+ # parser_strategy.add_argument('-u', '--update-file', help='Provide the file location to update the script of a custom strategy (Requires Strategy ID)')
147
+ #
148
+ # args = parser.parse_args()
149
+ #
150
+ # # If user is logging in, create a new login session and save it locally
151
+ # if args.command == 'login':
152
+ # restApi.login(args.username, args.password)
153
+ # tmpFile = open('/tmp/loginSession', 'ab')
154
+ # pickle.dump(restApi, tmpFile)
155
+ # tmpFile.close()
156
+ #
157
+ # elif args.command == 'logout':
158
+ # restApi.logout()
159
+ # os.remove('/tmp/loginSession')
160
+ #
161
+ # elif args.command == 'whoami':
162
+ # restApi.getStatus()
163
+ #
164
+ # elif args.command == 'strategy':
165
+ # if all(e is None for e in [args.id, args.output_file, args.update_file]):
166
+ # restApi.getStrategies()
167
+ # elif (args.output_file is not None) and (args.id is not None):
168
+ # try:
169
+ # code = restApi.saveStrategy(args.id)
170
+ # file = open(args.output_file, "w")
171
+ # file.write(code)
172
+ # file.close()
173
+ # print('File successfully saved to '+args.output_file)
174
+ # except Exception as e:
175
+ # print(e)
176
+ # elif (args.update_file is not None) and (args.id is not None):
177
+ # try:
178
+ # file = open(args.update_file, "r")
179
+ # code = file.read()
180
+ # restApi.updateStrategy(args.id, code)
181
+ # file.close()
182
+ # except Exception as e:
183
+ # print(e)
184
+ # else:
185
+ # parser_strategy.print_help()
186
+ #
187
+ #
188
+ # else:
189
+ # parser.print_help()
190
+
191
+
192
+ if __name__ == '__main__':
193
+ #main()
194
+ print(inspect.getfile(samples))
@@ -2,6 +2,7 @@ from enum import Enum
2
2
 
3
3
 
4
4
  class QuoteField(str, Enum):
5
+ """ Enum of all valid fields on Quote object """
5
6
  # ------ Quote ---
6
7
  LASTPRICE = "LASTPRICE"
7
8
  DAY_OPEN = "DAY_OPEN"
@@ -122,3 +122,25 @@ class DeploymentLog:
122
122
  def fromDict(json_dict: Dict[str, Any]) -> DeploymentLog:
123
123
  return DeploymentLog(ModelUtils.parseDatetime(json_dict['date']), LogLevel(json_dict['level']), json_dict['message'])
124
124
 
125
+ class StandardOrCustom(str, Enum):
126
+ STANDARD = "STANDARD"
127
+ CUSTOM = "CUSTOM"
128
+
129
+ @dataclass
130
+ class TradingStrategyModel:
131
+ strategyName: str
132
+ strategyId: int | None = None
133
+ pythonCode: str | None = None
134
+ strategyDesc: str | None = None
135
+
136
+ @staticmethod
137
+ def fromDict(json_dict: Dict[str, Any]) -> TradingStrategyModel:
138
+ strategyId = json_dict['strategyId']
139
+ strategyName = json_dict['strategyName']
140
+ pythonCode = json_dict['pythonCode']
141
+ strategyDesc = json_dict.get('strategyDesc')
142
+ return TradingStrategyModel(strategyId=strategyId, strategyName=strategyName, pythonCode=pythonCode, strategyDesc=strategyDesc)
143
+
144
+ def toDict(self) -> Dict[str, Any]:
145
+ dict = self.__dict__.copy()
146
+ return dict
@@ -12,7 +12,7 @@ from typing import Any, List, Dict
12
12
  import math
13
13
  import statistics
14
14
  import numpy as np
15
- import talib
15
+ import talib # https://pypi.org/project/TA-Lib/
16
16
  import pandas
17
17
  # ! WARN ! Imports other than listed above are disallowed and won't pass validation
18
18
 
@@ -0,0 +1,175 @@
1
+ Metadata-Version: 2.1
2
+ Name: investfly-sdk
3
+ Version: 1.1
4
+ Summary: Investfly SDK
5
+ Author-email: "Investfly.com" <admin@investfly.com>
6
+ License: The MIT License (MIT)
7
+
8
+ Copyright (c) 2023+ Investfly, Finverse LLC
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ Project-URL: Homepage, https://www.investfly.com
28
+ Classifier: Programming Language :: Python :: 3
29
+ Classifier: License :: OSI Approved :: MIT License
30
+ Classifier: Operating System :: OS Independent
31
+ Requires-Python: >=3.7
32
+ Description-Content-Type: text/markdown
33
+ License-File: LICENSE.txt
34
+ Requires-Dist: certifi ==2023.7.22
35
+ Requires-Dist: charset-normalizer ==3.2.0
36
+ Requires-Dist: idna ==3.4
37
+ Requires-Dist: pandas ==2.0.3
38
+ Requires-Dist: pandas-stubs ==2.0.3.230814
39
+ Requires-Dist: pandas-ta ==0.3.14b0
40
+ Requires-Dist: python-dateutil ==2.8.2
41
+ Requires-Dist: pytz ==2023.3
42
+ Requires-Dist: requests ==2.31.0
43
+ Requires-Dist: types-requests ==2.31.0.2
44
+ Requires-Dist: six ==1.16.0
45
+ Requires-Dist: tzdata ==2023.3
46
+ Requires-Dist: urllib3 ==1.26.15
47
+ Requires-Dist: numpy ==1.26.4
48
+ Requires-Dist: TA-Lib ==0.4.28
49
+
50
+ # About
51
+
52
+ Python-SDK to work with Investfly API.
53
+ [Investfly](https://www.investfly.com)
54
+
55
+ Investfly offers a platform for developing automated stock trading strategies. Users can create trading strategies through an intuitive drag-and-drop interface or by coding in Python.
56
+
57
+ The Investfly SDK contains the API and tools needed to build and deploy Python-based trading strategies on the Investfly platform.
58
+
59
+ Although you can edit Python code in our browser-based editor, writing code in a familiar IDE (Pycharm, VSCode) is recommended due to all the benefits that rich IDE offers. This SDK and CLI that comes with it makes it possible to develop trading strategy locally using your favorite IDE and upload it your Investfly account.
60
+
61
+ # Quickstart
62
+
63
+ ### SDK Installation and Setup
64
+
65
+ Investfly-SDK comes with all required Python classes used for strategy development as well as a command line tool (CLI) called `investfly-cli`
66
+
67
+ Using a terminal app, run the following commands.
68
+
69
+ **Setup Project and Virtual Environment**
70
+
71
+ ```commandline
72
+ mkdir investfly
73
+ cd investfly
74
+ python3 -m venv venv
75
+ source venv/bin/activate
76
+ ```
77
+
78
+ **Install investfly-sdk**
79
+
80
+ ```commandline
81
+ pip install investfly-sdk
82
+ ```
83
+
84
+ **Launch investfly-cli**
85
+
86
+ Investfly SDK comes with a command line tool (CLI) called investfly-cli.
87
+ ```commandline
88
+ investfly-cli
89
+
90
+ investfly-cli$ -h
91
+ usage: investfly-cli [-h] {login,logout,listStrategies,copySamples,exit} ...
92
+
93
+ positional arguments:
94
+ {login,logout,listStrategies,copySamples,exit}
95
+ Available Commands
96
+ login Login to Investfly
97
+ logout Logout from Investfly
98
+ listStrategies List Python Strategies
99
+ copySamples Copy Samples from SDK
100
+ ....
101
+ ....
102
+ exit Stop and Exit CLI
103
+
104
+
105
+ ```
106
+
107
+ **Test Installation**
108
+
109
+ You can test the installation by using the CLI to login and logout of Investfly.
110
+ ```commandline
111
+ investfly-cli$ login -u <YOUR_USERNAME> -p <YOUR_PASSWORD>
112
+ Session(username='xxxxxx', clientId='xxxxx-kaj1p3lv', clientToken='b29c9acc-330a-4821-9187-282d827e3e91')
113
+
114
+ investfly-cli$ logout
115
+ ```
116
+
117
+
118
+ ### Trading Strategy Development
119
+
120
+ Investfly-SDK comes with a starter strategy template and many sample strategies to help you get started quickly.
121
+
122
+
123
+ **Copy Samples**
124
+
125
+ ```commandline
126
+ investfly-cli$ copySamples
127
+ Samples copied to ./samples directory
128
+ ```
129
+
130
+ **Create New Strategy**
131
+
132
+ You can use one of the samples to create a new strategy. Normally, you would make a copy of the sample strategy, edit the copy using your favorite IDE to create a new strategy.
133
+ But for now, we'll use the unmodified sample
134
+ ```commandline
135
+ investfly-cli$ login -u <YOUR_USERNAME> -p <YOUR_PASSWORD>
136
+ Session(username='xxxxx', clientId='xxxxxx-krfs61aa', clientToken='766fad47-3e1e-4f43-a77a-72a95a395fec')
137
+
138
+ investfly-cli$ createStrategy -n MySmaCrossOverStrategy -f ./samples/strategies/SmaCrossOverStrategy.py
139
+ Created strategy 83
140
+
141
+ investfly-cli$ listStrategies
142
+ {'strategyId': 83, 'strategyName': 'MySmaCrossOverStrategy'}
143
+
144
+ ```
145
+
146
+ **Edit and Update Code**
147
+
148
+ Edit and update ./samples/strategies/SmaCrossOverStrategy.py as you like. For testing, change the `StandardSymbolsList.SP_100` to `StandardSymbolsList.SP_500` inside `getSecurityUniverseSelector` function.
149
+
150
+ ```commandline
151
+ investfly-cli$ updateStrategyCode --id 83 -f ./samples/strategies/SmaCrossOverStrategy.py
152
+ Code Updated
153
+ ```
154
+
155
+ After the code is updated, next step is to backtest the strategy and deploy it live.
156
+ You can do them by logging into Investfly with a web browser, navigating to the strategy page and invoking corresponding actions.
157
+
158
+
159
+ ### IDE Editor
160
+
161
+ The primary reason for publishing this SDK is so that you can use your favorite IDE Editor to write and update Python Code.
162
+ We recommend using PyCharm community edition:
163
+ https://www.jetbrains.com/pycharm/download
164
+
165
+ Using IDE editor will assist with auto-completion and type hints. Additionally, use type checking tools like mypy to check your code before deploying.
166
+
167
+ When using the IDE, open `investfly` directory created above as a project with your IDE.
168
+ Make sure that Python Interpreter is configured to the virtual environment `investfly/venv/bin/python` created above.
169
+
170
+
171
+ # Getting Help
172
+ Please email [admin@investfly.com](admin@investfly.com) for any support or bug report
173
+
174
+
175
+
@@ -1,21 +1,21 @@
1
- investfly/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- investfly/api/InvestflyApiClient.py,sha256=dHAWBaMPCPLVYvpzHGAwHisUeDcGN0yDwZC3Jl4LYew,799
1
+ investfly/__init__.py,sha256=SpTl-Tg1B1HTyjNOE-8ue-N2wGnXN_2zl7RFUSxlkiM,33
2
+ investfly/api/InvestflyApiClient.py,sha256=WBbI6i3ma09oOy6nUQO1amahV3WeorCHR0WLyaDjzw8,1735
3
3
  investfly/api/MarketDataApiClient.py,sha256=XmGIt5RK0-70cHTDF24g3YXqqxCNyzMzBIVhz1-7ZqY,460
4
4
  investfly/api/PortfolioApiClient.py,sha256=FVPjFz_eVLVXs-yPRefIcPoNiR3_WWzG7L0Dht60Z2o,1693
5
- investfly/api/RestApiClient.py,sha256=QRLkvsnzmIgBRnh1_sBxKJtS8oE03YcT3FUA1LRFkuo,3029
6
- investfly/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- investfly/cli/CliApiClient.py,sha256=PJe85_9jkMFBtKH5PNw3jtWjjk14DNTR089LA_IT5Fg,1482
5
+ investfly/api/RestApiClient.py,sha256=lnBJRlNKUZtBJ0x69oTDMHKxcZqdF2qevKjGUI0-ybo,3067
6
+ investfly/api/StrategyApiClient.py,sha256=jsZpuSDNj5HFTAquiRmx3TgG4sO1_Un0kHdmtfJuDdg,1342
7
+ investfly/api/__init__.py,sha256=tOUcAnM3zOUewVJ6jr-cZphc8hiFwWfR1kPVaWNJtwQ,152
8
+ investfly/cli/InvestflyCli.py,sha256=RI3DMInpKRMgtiacAymKuxcURNJ3-4ctDrSllJNu5ic,8144
8
9
  investfly/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- investfly/cli/commands.py,sha256=foVs0kXuFCWRFOgvk_iWxdIB-xODVjal00pIWCw_0Mg,2826
10
10
  investfly/models/CommonModels.py,sha256=OrwgqCiDL_HJfZTJeeVVsHUuRSDm6Ehk9xpnFy5AB5I,1663
11
11
  investfly/models/Indicator.py,sha256=FqiuiJJXCHUQtxf1AGUhIv2oYy3705D9MT3aVrJpX_s,6879
12
12
  investfly/models/MarketData.py,sha256=h7mefNLmAtLL8z75CQy0FZsSazKnsaWULt4B4Bh2uhw,5786
13
- investfly/models/MarketDataIds.py,sha256=ITrMVC0EjC58Xf7nlLG-GIwN46vWmNzegFZFW8GXT0E,3124
13
+ investfly/models/MarketDataIds.py,sha256=8IsJmQWpi-TooQMjKDMfbZzJjzYOXGss-g10WzoMQyg,3177
14
14
  investfly/models/ModelUtils.py,sha256=pnrVIDM26LqK0Wuw7gTs0c97lCLIV_fm0EUtlEfT7j4,964
15
15
  investfly/models/PortfolioModels.py,sha256=JvqZiH0g3w9qGqEXywpgqasM9olV3n6kjH7bfy9t0Z0,8462
16
16
  investfly/models/SecurityFilterModels.py,sha256=4baTBBI-XOKh8uTpvqVvk3unD-xHoyooO3dd5lKWbXA,5806
17
17
  investfly/models/SecurityUniverseSelector.py,sha256=z4V5Ng0DQ8DVy8FeuB_7swAYO7rmSK6HfJc7vA1NCq8,8111
18
- investfly/models/StrategyModels.py,sha256=j9IuGnLO0g_po95-6AteZnvy9wdNR4EJ_lF-rkn3Q3w,3585
18
+ investfly/models/StrategyModels.py,sha256=MjDziuLNoL25kzEYsOvqyetxGAMYNRFIYOB-I8OqJg8,4346
19
19
  investfly/models/TradingStrategy.py,sha256=dbsQ0wAY7M6s3yUpjp5cXp2X3tZwaUFB48pW-79C5D8,2825
20
20
  investfly/models/__init__.py,sha256=YVr7PakHt-g7pRmihFqYrvxNMwYE-rlDymFGp4neUdE,1071
21
21
  investfly/samples/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -25,14 +25,14 @@ investfly/samples/indicators/RsiOfSma.py,sha256=kiLvMhrsbc_lV0EEpERGW2im19u5XmyJ
25
25
  investfly/samples/indicators/SmaEmaAverage.py,sha256=9pp3TtEKJADD_bfufwrWlwMswlTLoN7Nj6BC_jJ1sRs,1749
26
26
  investfly/samples/indicators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  investfly/samples/strategies/SmaCrossOverStrategy.py,sha256=szjmnqQN8O7CRIS1vc-fRONKg4Dy1d59dZhiSEpEJAI,1699
28
- investfly/samples/strategies/SmaCrossOverTemplate.py,sha256=UUQjDkwQ4sn_ohMcW_J3rIietMIx69CX6gK6HuIFF-A,8164
28
+ investfly/samples/strategies/SmaCrossOverTemplate.py,sha256=HSyVh89_d-k1aAzqs_WFt8EDxs809OjWq6V3VJVUNQw,8200
29
29
  investfly/samples/strategies/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
30
30
  investfly/utils/CommonUtils.py,sha256=lCXAdI8-6PgbutcXJqUmSfuuLXp82FcnlxNVjCJpqLU,2631
31
31
  investfly/utils/PercentBasedPortfolioAllocator.py,sha256=oKaSjq5L_3NfRo2iayepCZtZnCevsx4XpsxFfZMTnV8,1684
32
32
  investfly/utils/__init__.py,sha256=2BqXoOQElv-GIU6wvmf2aaAABAcNny2TETcj7kf9rzM,129
33
- investfly_sdk-1.0.dist-info/LICENSE.txt,sha256=Jmd2U7G7Z1oNdnRERRzFXN6C--bEo_K56j4v9EpJSTg,1090
34
- investfly_sdk-1.0.dist-info/METADATA,sha256=sjsQYBDhYkB77JBgbIFhj9sIr9KqffIropVjo0miif8,2239
35
- investfly_sdk-1.0.dist-info/WHEEL,sha256=mguMlWGMX-VHnMpKOjjQidIo1ssRlCFu4a4mBpz1s2M,91
36
- investfly_sdk-1.0.dist-info/entry_points.txt,sha256=4PPHKy66mm-HrogzgqGKP7l9zCury-wY84H4KAymloY,62
37
- investfly_sdk-1.0.dist-info/top_level.txt,sha256=dlEJ2OGWA3prqMvXELeydS5RTdpSzh7hz1LwR3NMc7A,10
38
- investfly_sdk-1.0.dist-info/RECORD,,
33
+ investfly_sdk-1.1.dist-info/LICENSE.txt,sha256=Jmd2U7G7Z1oNdnRERRzFXN6C--bEo_K56j4v9EpJSTg,1090
34
+ investfly_sdk-1.1.dist-info/METADATA,sha256=2kmXPPwk_sXD0ralI7pOGdkMi-KKCcl2CYTSzgFSfGk,6514
35
+ investfly_sdk-1.1.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
36
+ investfly_sdk-1.1.dist-info/entry_points.txt,sha256=GDRF4baJQXTh90DvdJJx1DeRezWfPt26E567lTs3g6U,66
37
+ investfly_sdk-1.1.dist-info/top_level.txt,sha256=dlEJ2OGWA3prqMvXELeydS5RTdpSzh7hz1LwR3NMc7A,10
38
+ investfly_sdk-1.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (70.1.1)
2
+ Generator: setuptools (70.2.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ investfly-cli = investfly.cli.InvestflyCli:main
@@ -1,46 +0,0 @@
1
- import requests
2
- from investfly.api.RestApiClient import RestApiClient
3
-
4
- class CliApiClient:
5
-
6
- def __init__(self, baseUrl: str) -> None:
7
- self.restApi = RestApiClient(baseUrl)
8
-
9
- def login(self, username: str, password: str):
10
- try:
11
- user = self.restApi.login(username, password)
12
- print("Successfully logged in as: "+user.username)
13
- except Exception as e:
14
- print(e)
15
-
16
- def logout(self):
17
- self.restApi.logout()
18
-
19
- def getStatus(self):
20
- try:
21
- userInfo = self.restApi.doGet('/user/session')
22
- print("Currently logged in as "+userInfo['username'])
23
- except Exception as e:
24
- print(e)
25
-
26
- def getStrategies(self):
27
- try:
28
- strategies = self.restApi.doGet('/strategy/list')
29
- for strategy in strategies:
30
- print(str(strategy['strategyId'])+'\t'+strategy['strategyName']+'\n'+strategy['strategyDesc']+'\n')
31
- except Exception as e:
32
- print(e)
33
-
34
- def saveStrategy(self, strategyId: int):
35
- try:
36
- strategy = self.restApi.doGet('/strategy/'+str(strategyId))
37
- return strategy['pythonCode']
38
- except Exception as e:
39
- return e
40
-
41
- def updateStrategy(self, id: int, code: str):
42
- try:
43
- self.restApi.doPostCode('/strategy/'+id+'/update/code', code)
44
- print('Strategy successfully updated')
45
- except Exception as e:
46
- print(e)
investfly/cli/commands.py DELETED
@@ -1,78 +0,0 @@
1
- import argparse
2
- import pickle
3
- import os.path
4
-
5
- from investfly.cli.CliApiClient import CliApiClient
6
-
7
- def main():
8
- # Check to see if user already has a session active
9
- if os.path.exists('/tmp/loginSession'):
10
- tmpfile = open('/tmp/loginSession', 'rb')
11
- restApi = pickle.load(tmpfile)
12
- tmpfile.close()
13
- else:
14
- restApi = CliApiClient("https://api.investfly.com")
15
-
16
- # CLI Commands
17
- parser = argparse.ArgumentParser()
18
- subparser = parser.add_subparsers(dest='command')
19
-
20
- parser_login = subparser.add_parser('login', help='Login to Investfly')
21
- parser_login.add_argument('-u', '--username', required='true', help='Input username')
22
- parser_login.add_argument('-p', '--password', required='true', help='Input user password')
23
-
24
- subparser.add_parser('whoami', help='View your user information')
25
-
26
- subparser.add_parser('logout', help='Logout')
27
-
28
- parser_strategy = subparser.add_parser('strategy', help='View all your current strategies')
29
- parser_strategy.add_argument('-id', help='Provide the Strategy ID')
30
- parser_strategy.add_argument('-o', '--output-file', help='Provide a location to save the output file of a custom strategy (Requires Strategy ID)')
31
- parser_strategy.add_argument('-u', '--update-file', help='Provide the file location to update the script of a custom strategy (Requires Strategy ID)')
32
-
33
- args = parser.parse_args()
34
-
35
- # If user is logging in, create a new login session and save it locally
36
- if args.command == 'login':
37
- restApi.login(args.username, args.password)
38
- tmpFile = open('/tmp/loginSession', 'ab')
39
- pickle.dump(restApi, tmpFile)
40
- tmpFile.close()
41
-
42
- elif args.command == 'logout':
43
- restApi.logout()
44
- os.remove('/tmp/loginSession')
45
-
46
- elif args.command == 'whoami':
47
- restApi.getStatus()
48
-
49
- elif args.command == 'strategy':
50
- if all(e is None for e in [args.id, args.output_file, args.update_file]):
51
- restApi.getStrategies()
52
- elif (args.output_file is not None) and (args.id is not None):
53
- try:
54
- code = restApi.saveStrategy(args.id)
55
- file = open(args.output_file, "w")
56
- file.write(code)
57
- file.close()
58
- print('File successfully saved to '+args.output_file)
59
- except Exception as e:
60
- print(e)
61
- elif (args.update_file is not None) and (args.id is not None):
62
- try:
63
- file = open(args.update_file, "r")
64
- code = file.read()
65
- restApi.updateStrategy(args.id, code)
66
- file.close()
67
- except Exception as e:
68
- print(e)
69
- else:
70
- parser_strategy.print_help()
71
-
72
-
73
- else:
74
- parser.print_help()
75
-
76
-
77
- if __name__ == '__main__':
78
- main()
@@ -1,53 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: investfly-sdk
3
- Version: 1.0
4
- Summary: Investfly SDK
5
- Author-email: "Investfly.com" <admin@investfly.com>
6
- License: The MIT License (MIT)
7
-
8
- Copyright (c) 2023+ Investfly, Finverse LLC
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining a copy
11
- of this software and associated documentation files (the "Software"), to deal
12
- in the Software without restriction, including without limitation the rights
13
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
- copies of the Software, and to permit persons to whom the Software is
15
- furnished to do so, subject to the following conditions:
16
-
17
- The above copyright notice and this permission notice shall be included in all
18
- copies or substantial portions of the Software.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
- SOFTWARE.
27
- Project-URL: Homepage, https://www.investfly.com
28
- Classifier: Programming Language :: Python :: 3
29
- Classifier: License :: OSI Approved :: MIT License
30
- Classifier: Operating System :: OS Independent
31
- Requires-Python: >=3.7
32
- Description-Content-Type: text/markdown
33
- License-File: LICENSE.txt
34
- Requires-Dist: certifi ==2023.7.22
35
- Requires-Dist: charset-normalizer ==3.2.0
36
- Requires-Dist: idna ==3.4
37
- Requires-Dist: pandas ==2.0.3
38
- Requires-Dist: pandas-stubs ==2.0.3.230814
39
- Requires-Dist: pandas-ta ==0.3.14b0
40
- Requires-Dist: python-dateutil ==2.8.2
41
- Requires-Dist: pytz ==2023.3
42
- Requires-Dist: requests ==2.31.0
43
- Requires-Dist: types-requests ==2.31.0.2
44
- Requires-Dist: six ==1.16.0
45
- Requires-Dist: tzdata ==2023.3
46
- Requires-Dist: urllib3 ==1.26.15
47
- Requires-Dist: numpy ==1.26.4
48
-
49
- # About
50
-
51
- Python-SDK to work with Investfly API.
52
- [Investfly](https://www.investfly.com)
53
-
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- investfly-cli = investfly.cli.commands:main