investfly-sdk 1.0__tar.gz → 1.1__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.
- investfly_sdk-1.1/PKG-INFO +175 -0
- investfly_sdk-1.1/README.md +126 -0
- investfly_sdk-1.1/investfly/__init__.py +3 -0
- investfly_sdk-1.1/investfly/api/InvestflyApiClient.py +45 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/api/RestApiClient.py +2 -2
- investfly_sdk-1.1/investfly/api/StrategyApiClient.py +27 -0
- investfly_sdk-1.1/investfly/api/__init__.py +3 -0
- investfly_sdk-1.1/investfly/cli/InvestflyCli.py +194 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/models/MarketDataIds.py +1 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/models/StrategyModels.py +22 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/samples/strategies/SmaCrossOverTemplate.py +1 -1
- investfly_sdk-1.1/investfly_sdk.egg-info/PKG-INFO +175 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly_sdk.egg-info/SOURCES.txt +2 -2
- investfly_sdk-1.1/investfly_sdk.egg-info/entry_points.txt +2 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly_sdk.egg-info/requires.txt +1 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/pyproject.toml +4 -3
- investfly_sdk-1.0/PKG-INFO +0 -53
- investfly_sdk-1.0/README.md +0 -5
- investfly_sdk-1.0/investfly/api/InvestflyApiClient.py +0 -23
- investfly_sdk-1.0/investfly/cli/CliApiClient.py +0 -46
- investfly_sdk-1.0/investfly/cli/commands.py +0 -78
- investfly_sdk-1.0/investfly/samples/indicators/__init__.py +0 -0
- investfly_sdk-1.0/investfly/samples/strategies/__init__.py +0 -0
- investfly_sdk-1.0/investfly_sdk.egg-info/PKG-INFO +0 -53
- investfly_sdk-1.0/investfly_sdk.egg-info/entry_points.txt +0 -2
- {investfly_sdk-1.0 → investfly_sdk-1.1}/LICENSE.txt +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/api/MarketDataApiClient.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/api/PortfolioApiClient.py +0 -0
- {investfly_sdk-1.0/investfly → investfly_sdk-1.1/investfly/cli}/__init__.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/models/CommonModels.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/models/Indicator.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/models/MarketData.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/models/ModelUtils.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/models/PortfolioModels.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/models/SecurityFilterModels.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/models/SecurityUniverseSelector.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/models/TradingStrategy.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/models/__init__.py +0 -0
- {investfly_sdk-1.0/investfly/api → investfly_sdk-1.1/investfly/samples}/__init__.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/samples/indicators/IndicatorTemplate.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/samples/indicators/NewsSentiment.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/samples/indicators/RsiOfSma.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/samples/indicators/SmaEmaAverage.py +0 -0
- {investfly_sdk-1.0/investfly/cli → investfly_sdk-1.1/investfly/samples/indicators}/__init__.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/samples/strategies/SmaCrossOverStrategy.py +0 -0
- {investfly_sdk-1.0/investfly/samples → investfly_sdk-1.1/investfly/samples/strategies}/__init__.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/utils/CommonUtils.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/utils/PercentBasedPortfolioAllocator.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/utils/__init__.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly_sdk.egg-info/dependency_links.txt +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/investfly_sdk.egg-info/top_level.txt +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.1}/setup.cfg +0 -0
@@ -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
|
+
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# About
|
2
|
+
|
3
|
+
Python-SDK to work with Investfly API.
|
4
|
+
[Investfly](https://www.investfly.com)
|
5
|
+
|
6
|
+
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.
|
7
|
+
|
8
|
+
The Investfly SDK contains the API and tools needed to build and deploy Python-based trading strategies on the Investfly platform.
|
9
|
+
|
10
|
+
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.
|
11
|
+
|
12
|
+
# Quickstart
|
13
|
+
|
14
|
+
### SDK Installation and Setup
|
15
|
+
|
16
|
+
Investfly-SDK comes with all required Python classes used for strategy development as well as a command line tool (CLI) called `investfly-cli`
|
17
|
+
|
18
|
+
Using a terminal app, run the following commands.
|
19
|
+
|
20
|
+
**Setup Project and Virtual Environment**
|
21
|
+
|
22
|
+
```commandline
|
23
|
+
mkdir investfly
|
24
|
+
cd investfly
|
25
|
+
python3 -m venv venv
|
26
|
+
source venv/bin/activate
|
27
|
+
```
|
28
|
+
|
29
|
+
**Install investfly-sdk**
|
30
|
+
|
31
|
+
```commandline
|
32
|
+
pip install investfly-sdk
|
33
|
+
```
|
34
|
+
|
35
|
+
**Launch investfly-cli**
|
36
|
+
|
37
|
+
Investfly SDK comes with a command line tool (CLI) called investfly-cli.
|
38
|
+
```commandline
|
39
|
+
investfly-cli
|
40
|
+
|
41
|
+
investfly-cli$ -h
|
42
|
+
usage: investfly-cli [-h] {login,logout,listStrategies,copySamples,exit} ...
|
43
|
+
|
44
|
+
positional arguments:
|
45
|
+
{login,logout,listStrategies,copySamples,exit}
|
46
|
+
Available Commands
|
47
|
+
login Login to Investfly
|
48
|
+
logout Logout from Investfly
|
49
|
+
listStrategies List Python Strategies
|
50
|
+
copySamples Copy Samples from SDK
|
51
|
+
....
|
52
|
+
....
|
53
|
+
exit Stop and Exit CLI
|
54
|
+
|
55
|
+
|
56
|
+
```
|
57
|
+
|
58
|
+
**Test Installation**
|
59
|
+
|
60
|
+
You can test the installation by using the CLI to login and logout of Investfly.
|
61
|
+
```commandline
|
62
|
+
investfly-cli$ login -u <YOUR_USERNAME> -p <YOUR_PASSWORD>
|
63
|
+
Session(username='xxxxxx', clientId='xxxxx-kaj1p3lv', clientToken='b29c9acc-330a-4821-9187-282d827e3e91')
|
64
|
+
|
65
|
+
investfly-cli$ logout
|
66
|
+
```
|
67
|
+
|
68
|
+
|
69
|
+
### Trading Strategy Development
|
70
|
+
|
71
|
+
Investfly-SDK comes with a starter strategy template and many sample strategies to help you get started quickly.
|
72
|
+
|
73
|
+
|
74
|
+
**Copy Samples**
|
75
|
+
|
76
|
+
```commandline
|
77
|
+
investfly-cli$ copySamples
|
78
|
+
Samples copied to ./samples directory
|
79
|
+
```
|
80
|
+
|
81
|
+
**Create New Strategy**
|
82
|
+
|
83
|
+
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.
|
84
|
+
But for now, we'll use the unmodified sample
|
85
|
+
```commandline
|
86
|
+
investfly-cli$ login -u <YOUR_USERNAME> -p <YOUR_PASSWORD>
|
87
|
+
Session(username='xxxxx', clientId='xxxxxx-krfs61aa', clientToken='766fad47-3e1e-4f43-a77a-72a95a395fec')
|
88
|
+
|
89
|
+
investfly-cli$ createStrategy -n MySmaCrossOverStrategy -f ./samples/strategies/SmaCrossOverStrategy.py
|
90
|
+
Created strategy 83
|
91
|
+
|
92
|
+
investfly-cli$ listStrategies
|
93
|
+
{'strategyId': 83, 'strategyName': 'MySmaCrossOverStrategy'}
|
94
|
+
|
95
|
+
```
|
96
|
+
|
97
|
+
**Edit and Update Code**
|
98
|
+
|
99
|
+
Edit and update ./samples/strategies/SmaCrossOverStrategy.py as you like. For testing, change the `StandardSymbolsList.SP_100` to `StandardSymbolsList.SP_500` inside `getSecurityUniverseSelector` function.
|
100
|
+
|
101
|
+
```commandline
|
102
|
+
investfly-cli$ updateStrategyCode --id 83 -f ./samples/strategies/SmaCrossOverStrategy.py
|
103
|
+
Code Updated
|
104
|
+
```
|
105
|
+
|
106
|
+
After the code is updated, next step is to backtest the strategy and deploy it live.
|
107
|
+
You can do them by logging into Investfly with a web browser, navigating to the strategy page and invoking corresponding actions.
|
108
|
+
|
109
|
+
|
110
|
+
### IDE Editor
|
111
|
+
|
112
|
+
The primary reason for publishing this SDK is so that you can use your favorite IDE Editor to write and update Python Code.
|
113
|
+
We recommend using PyCharm community edition:
|
114
|
+
https://www.jetbrains.com/pycharm/download
|
115
|
+
|
116
|
+
Using IDE editor will assist with auto-completion and type hints. Additionally, use type checking tools like mypy to check your code before deploying.
|
117
|
+
|
118
|
+
When using the IDE, open `investfly` directory created above as a project with your IDE.
|
119
|
+
Make sure that Python Interpreter is configured to the virtual environment `investfly/venv/bin/python` created above.
|
120
|
+
|
121
|
+
|
122
|
+
# Getting Help
|
123
|
+
Please email [admin@investfly.com](admin@investfly.com) for any support or bug report
|
124
|
+
|
125
|
+
|
126
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import datetime
|
2
|
+
|
3
|
+
from investfly.api.MarketDataApiClient import MarketDataApiClient
|
4
|
+
from investfly.api.PortfolioApiClient import PortfolioApiClient
|
5
|
+
from investfly.api.RestApiClient import RestApiClient
|
6
|
+
from investfly.api.StrategyApiClient import StrategyApiClient
|
7
|
+
from investfly.models import Session
|
8
|
+
|
9
|
+
|
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
|
+
"""
|
15
|
+
|
16
|
+
def __init__(self, baseUrl: str = "https://api.investfly.com"):
|
17
|
+
self.restApiClient = RestApiClient(baseUrl)
|
18
|
+
self.marketApi = MarketDataApiClient(self.restApiClient)
|
19
|
+
"""Class used to make calls to /market endpoint """
|
20
|
+
self.portfolioApi = PortfolioApiClient(self.restApiClient)
|
21
|
+
self.strategyApi = StrategyApiClient(self.restApiClient)
|
22
|
+
|
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
|
+
"""
|
30
|
+
return self.restApiClient.login(username, password)
|
31
|
+
|
32
|
+
def logout(self):
|
33
|
+
self.restApiClient.logout()
|
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
|
+
|
43
|
+
@staticmethod
|
44
|
+
def parseDatetime(date_str: str) -> datetime.datetime:
|
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.
|
34
|
-
self.
|
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)
|
@@ -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))
|
@@ -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
|
{investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/samples/strategies/SmaCrossOverTemplate.py
RENAMED
@@ -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
|
+
|
@@ -6,10 +6,10 @@ investfly/api/InvestflyApiClient.py
|
|
6
6
|
investfly/api/MarketDataApiClient.py
|
7
7
|
investfly/api/PortfolioApiClient.py
|
8
8
|
investfly/api/RestApiClient.py
|
9
|
+
investfly/api/StrategyApiClient.py
|
9
10
|
investfly/api/__init__.py
|
10
|
-
investfly/cli/
|
11
|
+
investfly/cli/InvestflyCli.py
|
11
12
|
investfly/cli/__init__.py
|
12
|
-
investfly/cli/commands.py
|
13
13
|
investfly/models/CommonModels.py
|
14
14
|
investfly/models/Indicator.py
|
15
15
|
investfly/models/MarketData.py
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "investfly-sdk"
|
7
|
-
version = "1.
|
7
|
+
version = "1.1"
|
8
8
|
description = "Investfly SDK"
|
9
9
|
authors = [
|
10
10
|
{ name = "Investfly.com", email = "admin@investfly.com" },
|
@@ -31,10 +31,11 @@ dependencies = [
|
|
31
31
|
"six==1.16.0",
|
32
32
|
"tzdata==2023.3",
|
33
33
|
"urllib3==1.26.15",
|
34
|
-
"numpy==1.26.4"
|
34
|
+
"numpy==1.26.4",
|
35
|
+
"TA-Lib==0.4.28"
|
35
36
|
]
|
36
37
|
[project.scripts]
|
37
|
-
investfly-cli = "investfly.cli.
|
38
|
+
investfly-cli = "investfly.cli.InvestflyCli:main"
|
38
39
|
|
39
40
|
[project.urls]
|
40
41
|
Homepage = "https://www.investfly.com"
|
investfly_sdk-1.0/PKG-INFO
DELETED
@@ -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
|
-
|
investfly_sdk-1.0/README.md
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
import datetime
|
2
|
-
|
3
|
-
from investfly.api.MarketDataApiClient import MarketDataApiClient
|
4
|
-
from investfly.api.PortfolioApiClient import PortfolioApiClient
|
5
|
-
from investfly.api.RestApiClient import RestApiClient
|
6
|
-
|
7
|
-
|
8
|
-
class InvestflyApiClient:
|
9
|
-
|
10
|
-
def __init__(self, baseUrl: str = "https://api.investfly.com"):
|
11
|
-
self.restApiClient = RestApiClient(baseUrl)
|
12
|
-
self.marketApi = MarketDataApiClient(self.restApiClient)
|
13
|
-
self.portfolioApi = PortfolioApiClient(self.restApiClient)
|
14
|
-
|
15
|
-
def login(self, username, password):
|
16
|
-
return self.restApiClient.login(username, password)
|
17
|
-
|
18
|
-
def logout(self):
|
19
|
-
self.restApiClient.logout()
|
20
|
-
|
21
|
-
@staticmethod
|
22
|
-
def parseDatetime(date_str: str) -> datetime.datetime:
|
23
|
-
return datetime.datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%f%z')
|
@@ -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)
|
@@ -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()
|
File without changes
|
File without changes
|
@@ -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
|
-
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{investfly_sdk-1.0/investfly/cli → investfly_sdk-1.1/investfly/samples/indicators}/__init__.py
RENAMED
File without changes
|
{investfly_sdk-1.0 → investfly_sdk-1.1}/investfly/samples/strategies/SmaCrossOverStrategy.py
RENAMED
File without changes
|
{investfly_sdk-1.0/investfly/samples → investfly_sdk-1.1/investfly/samples/strategies}/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|