investfly-sdk 1.0__tar.gz → 1.2__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.2/PKG-INFO +194 -0
- investfly_sdk-1.2/README.md +145 -0
- investfly_sdk-1.2/investfly/__init__.py +5 -0
- investfly_sdk-1.2/investfly/api/IndicatorApiClient.py +24 -0
- investfly_sdk-1.2/investfly/api/InvestflyApiClient.py +49 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/api/MarketDataApiClient.py +4 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/api/PortfolioApiClient.py +4 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/api/RestApiClient.py +7 -2
- investfly_sdk-1.2/investfly/api/StrategyApiClient.py +45 -0
- investfly_sdk-1.2/investfly/api/__init__.py +17 -0
- investfly_sdk-1.2/investfly/cli/InvestflyCli.py +217 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/models/CommonModels.py +31 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/models/Indicator.py +89 -14
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/models/MarketData.py +13 -2
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/models/MarketDataIds.py +3 -1
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/models/PortfolioModels.py +11 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/models/SecurityUniverseSelector.py +9 -1
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/models/StrategyModels.py +62 -1
- investfly_sdk-1.2/investfly/models/TradingStrategy.py +110 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/models/__init__.py +9 -1
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/samples/strategies/SmaCrossOverTemplate.py +1 -1
- investfly_sdk-1.2/investfly_sdk.egg-info/PKG-INFO +194 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly_sdk.egg-info/SOURCES.txt +3 -2
- investfly_sdk-1.2/investfly_sdk.egg-info/entry_points.txt +2 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly_sdk.egg-info/requires.txt +1 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/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/models/TradingStrategy.py +0 -59
- 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.2}/LICENSE.txt +0 -0
- {investfly_sdk-1.0/investfly → investfly_sdk-1.2/investfly/cli}/__init__.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/models/ModelUtils.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/models/SecurityFilterModels.py +0 -0
- {investfly_sdk-1.0/investfly/api → investfly_sdk-1.2/investfly/samples}/__init__.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/samples/indicators/IndicatorTemplate.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/samples/indicators/NewsSentiment.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/samples/indicators/RsiOfSma.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/samples/indicators/SmaEmaAverage.py +0 -0
- {investfly_sdk-1.0/investfly/cli → investfly_sdk-1.2/investfly/samples/indicators}/__init__.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/samples/strategies/SmaCrossOverStrategy.py +0 -0
- {investfly_sdk-1.0/investfly/samples → investfly_sdk-1.2/investfly/samples/strategies}/__init__.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/utils/CommonUtils.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/utils/PercentBasedPortfolioAllocator.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly/utils/__init__.py +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly_sdk.egg-info/dependency_links.txt +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/investfly_sdk.egg-info/top_level.txt +0 -0
- {investfly_sdk-1.0 → investfly_sdk-1.2}/setup.cfg +0 -0
@@ -0,0 +1,194 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: investfly-sdk
|
3
|
+
Version: 1.2
|
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
|
+
Install investfly-sdk also adds investfly-cli in your path inside the virtual environment. It can be launched simply by using `investfly-cli` command in the virtual env.
|
87
|
+
|
88
|
+
```commandline
|
89
|
+
(venv) user@host$ investfly-cli
|
90
|
+
|
91
|
+
investfly-cli$ -h
|
92
|
+
usage: investfly-cli [-h]
|
93
|
+
{login,logout,strategy.list,strategy.copysamples,strategy.create,strategy.download,strategy.update,strategy.backtest.start,strategy.backtest.stop,strategy.backtest.result,exit}
|
94
|
+
...
|
95
|
+
|
96
|
+
positional arguments:
|
97
|
+
{login,logout,strategy.list,strategy.copysamples,strategy.create,strategy.download,strategy.update,strategy.backtest.start,strategy.backtest.stop,strategy.backtest.result,exit}
|
98
|
+
Available Commands
|
99
|
+
login Login to Investfly
|
100
|
+
logout Logout from Investfly
|
101
|
+
strategy.list List Python Strategies
|
102
|
+
strategy.copysamples
|
103
|
+
Copy Samples from SDK
|
104
|
+
strategy.create Create a new trading strategy
|
105
|
+
strategy.download Download one of your strategy and save it to a file
|
106
|
+
strategy.update Update strategy Python Code
|
107
|
+
strategy.backtest.start
|
108
|
+
Start backtest for strategy
|
109
|
+
strategy.backtest.stop
|
110
|
+
Stop backtest for strategy
|
111
|
+
strategy.backtest.result
|
112
|
+
Get backtest result, waiting if backtest is still
|
113
|
+
running
|
114
|
+
exit Stop and Exit CLI
|
115
|
+
|
116
|
+
options:
|
117
|
+
-h, --help show this help message and exit
|
118
|
+
|
119
|
+
investfly-cli$
|
120
|
+
```
|
121
|
+
|
122
|
+
**Test Installation**
|
123
|
+
|
124
|
+
You can test the installation by using the CLI to login and logout of Investfly.
|
125
|
+
```commandline
|
126
|
+
investfly-cli$ login -u <YOUR_USERNAME> -p <YOUR_PASSWORD>
|
127
|
+
Session(username='xxxxxx', clientId='xxxxx-kaj1p3lv', clientToken='b29c9acc-330a-4821-9187-282d827e3e91')
|
128
|
+
|
129
|
+
investfly-cli$ logout
|
130
|
+
```
|
131
|
+
|
132
|
+
|
133
|
+
### Trading Strategy Development
|
134
|
+
|
135
|
+
Investfly-SDK comes with a starter strategy template and many sample strategies to help you get started quickly.
|
136
|
+
|
137
|
+
|
138
|
+
**Copy Samples**
|
139
|
+
|
140
|
+
```commandline
|
141
|
+
investfly-cli$ copysamples
|
142
|
+
Samples copied to ./samples directory
|
143
|
+
```
|
144
|
+
|
145
|
+
**Create New Strategy**
|
146
|
+
|
147
|
+
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.
|
148
|
+
But for now, we'll use the unmodified sample
|
149
|
+
```commandline
|
150
|
+
investfly-cli$ login -u <YOUR_USERNAME> -p <YOUR_PASSWORD>
|
151
|
+
Session(username='xxxxx', clientId='xxxxxx-krfs61aa', clientToken='766fad47-3e1e-4f43-a77a-72a95a395fec')
|
152
|
+
|
153
|
+
investfly-cli$ strategy.create -n MySmaCrossOverStrategy -f ./samples/strategies/SmaCrossOverStrategy.py
|
154
|
+
Created strategy 83
|
155
|
+
|
156
|
+
investfly-cli$ strategy.list
|
157
|
+
{'strategyId': 83, 'strategyName': 'MySmaCrossOverStrategy'}
|
158
|
+
|
159
|
+
```
|
160
|
+
|
161
|
+
**Edit and Update Code**
|
162
|
+
|
163
|
+
Edit and update ./samples/strategies/SmaCrossOverStrategy.py as you like. For testing, change the `StandardSymbolsList.SP_100` to `StandardSymbolsList.SP_500` inside `getSecurityUniverseSelector` function.
|
164
|
+
|
165
|
+
```commandline
|
166
|
+
investfly-cli$ strategy.update --id 83 -f ./samples/strategies/SmaCrossOverStrategy.py
|
167
|
+
Code Updated
|
168
|
+
```
|
169
|
+
|
170
|
+
After the code is updated, next step is to backtest the strategy and deploy it live.
|
171
|
+
You can do them by logging into Investfly with a web browser, navigating to the strategy page and invoking corresponding actions.
|
172
|
+
|
173
|
+
|
174
|
+
### IDE Editor
|
175
|
+
|
176
|
+
The primary reason for publishing this SDK is so that you can use your favorite IDE Editor to write and update Python Code.
|
177
|
+
We recommend using PyCharm community edition:
|
178
|
+
https://www.jetbrains.com/pycharm/download
|
179
|
+
|
180
|
+
Using IDE editor will assist with auto-completion and type hints. Additionally, use type checking tools like mypy to check your code before deploying.
|
181
|
+
|
182
|
+
When using the IDE, open `investfly` directory created above as a project with your IDE.
|
183
|
+
Make sure that Python Interpreter is configured to the virtual environment `investfly/venv/bin/python` created above.
|
184
|
+
|
185
|
+
|
186
|
+
# API Docs
|
187
|
+
|
188
|
+
API Docs are published at https://www.investfly.com/guides/docs/index.html
|
189
|
+
|
190
|
+
# Getting Help
|
191
|
+
Please email [admin@investfly.com](admin@investfly.com) for any support or bug report
|
192
|
+
|
193
|
+
|
194
|
+
|
@@ -0,0 +1,145 @@
|
|
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
|
+
Install investfly-sdk also adds investfly-cli in your path inside the virtual environment. It can be launched simply by using `investfly-cli` command in the virtual env.
|
38
|
+
|
39
|
+
```commandline
|
40
|
+
(venv) user@host$ investfly-cli
|
41
|
+
|
42
|
+
investfly-cli$ -h
|
43
|
+
usage: investfly-cli [-h]
|
44
|
+
{login,logout,strategy.list,strategy.copysamples,strategy.create,strategy.download,strategy.update,strategy.backtest.start,strategy.backtest.stop,strategy.backtest.result,exit}
|
45
|
+
...
|
46
|
+
|
47
|
+
positional arguments:
|
48
|
+
{login,logout,strategy.list,strategy.copysamples,strategy.create,strategy.download,strategy.update,strategy.backtest.start,strategy.backtest.stop,strategy.backtest.result,exit}
|
49
|
+
Available Commands
|
50
|
+
login Login to Investfly
|
51
|
+
logout Logout from Investfly
|
52
|
+
strategy.list List Python Strategies
|
53
|
+
strategy.copysamples
|
54
|
+
Copy Samples from SDK
|
55
|
+
strategy.create Create a new trading strategy
|
56
|
+
strategy.download Download one of your strategy and save it to a file
|
57
|
+
strategy.update Update strategy Python Code
|
58
|
+
strategy.backtest.start
|
59
|
+
Start backtest for strategy
|
60
|
+
strategy.backtest.stop
|
61
|
+
Stop backtest for strategy
|
62
|
+
strategy.backtest.result
|
63
|
+
Get backtest result, waiting if backtest is still
|
64
|
+
running
|
65
|
+
exit Stop and Exit CLI
|
66
|
+
|
67
|
+
options:
|
68
|
+
-h, --help show this help message and exit
|
69
|
+
|
70
|
+
investfly-cli$
|
71
|
+
```
|
72
|
+
|
73
|
+
**Test Installation**
|
74
|
+
|
75
|
+
You can test the installation by using the CLI to login and logout of Investfly.
|
76
|
+
```commandline
|
77
|
+
investfly-cli$ login -u <YOUR_USERNAME> -p <YOUR_PASSWORD>
|
78
|
+
Session(username='xxxxxx', clientId='xxxxx-kaj1p3lv', clientToken='b29c9acc-330a-4821-9187-282d827e3e91')
|
79
|
+
|
80
|
+
investfly-cli$ logout
|
81
|
+
```
|
82
|
+
|
83
|
+
|
84
|
+
### Trading Strategy Development
|
85
|
+
|
86
|
+
Investfly-SDK comes with a starter strategy template and many sample strategies to help you get started quickly.
|
87
|
+
|
88
|
+
|
89
|
+
**Copy Samples**
|
90
|
+
|
91
|
+
```commandline
|
92
|
+
investfly-cli$ copysamples
|
93
|
+
Samples copied to ./samples directory
|
94
|
+
```
|
95
|
+
|
96
|
+
**Create New Strategy**
|
97
|
+
|
98
|
+
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.
|
99
|
+
But for now, we'll use the unmodified sample
|
100
|
+
```commandline
|
101
|
+
investfly-cli$ login -u <YOUR_USERNAME> -p <YOUR_PASSWORD>
|
102
|
+
Session(username='xxxxx', clientId='xxxxxx-krfs61aa', clientToken='766fad47-3e1e-4f43-a77a-72a95a395fec')
|
103
|
+
|
104
|
+
investfly-cli$ strategy.create -n MySmaCrossOverStrategy -f ./samples/strategies/SmaCrossOverStrategy.py
|
105
|
+
Created strategy 83
|
106
|
+
|
107
|
+
investfly-cli$ strategy.list
|
108
|
+
{'strategyId': 83, 'strategyName': 'MySmaCrossOverStrategy'}
|
109
|
+
|
110
|
+
```
|
111
|
+
|
112
|
+
**Edit and Update Code**
|
113
|
+
|
114
|
+
Edit and update ./samples/strategies/SmaCrossOverStrategy.py as you like. For testing, change the `StandardSymbolsList.SP_100` to `StandardSymbolsList.SP_500` inside `getSecurityUniverseSelector` function.
|
115
|
+
|
116
|
+
```commandline
|
117
|
+
investfly-cli$ strategy.update --id 83 -f ./samples/strategies/SmaCrossOverStrategy.py
|
118
|
+
Code Updated
|
119
|
+
```
|
120
|
+
|
121
|
+
After the code is updated, next step is to backtest the strategy and deploy it live.
|
122
|
+
You can do them by logging into Investfly with a web browser, navigating to the strategy page and invoking corresponding actions.
|
123
|
+
|
124
|
+
|
125
|
+
### IDE Editor
|
126
|
+
|
127
|
+
The primary reason for publishing this SDK is so that you can use your favorite IDE Editor to write and update Python Code.
|
128
|
+
We recommend using PyCharm community edition:
|
129
|
+
https://www.jetbrains.com/pycharm/download
|
130
|
+
|
131
|
+
Using IDE editor will assist with auto-completion and type hints. Additionally, use type checking tools like mypy to check your code before deploying.
|
132
|
+
|
133
|
+
When using the IDE, open `investfly` directory created above as a project with your IDE.
|
134
|
+
Make sure that Python Interpreter is configured to the virtual environment `investfly/venv/bin/python` created above.
|
135
|
+
|
136
|
+
|
137
|
+
# API Docs
|
138
|
+
|
139
|
+
API Docs are published at https://www.investfly.com/guides/docs/index.html
|
140
|
+
|
141
|
+
# Getting Help
|
142
|
+
Please email [admin@investfly.com](admin@investfly.com) for any support or bug report
|
143
|
+
|
144
|
+
|
145
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
from typing import List, Dict, Any
|
2
|
+
|
3
|
+
from investfly.api.RestApiClient import RestApiClient
|
4
|
+
from investfly.models import IndicatorSpec
|
5
|
+
|
6
|
+
|
7
|
+
class IndicatorApiClient:
|
8
|
+
|
9
|
+
def __init__(self, restApiClient: RestApiClient) -> None:
|
10
|
+
self.restApiClient = restApiClient
|
11
|
+
|
12
|
+
def listIndicators(self) -> List[IndicatorSpec]:
|
13
|
+
indicatorsListDict = self.restApiClient.doGet('/indicator/list/custom')
|
14
|
+
result: List[IndicatorSpec] = []
|
15
|
+
for indicatorDict in indicatorsListDict:
|
16
|
+
result.append(IndicatorSpec.fromDict(indicatorDict))
|
17
|
+
return result
|
18
|
+
|
19
|
+
def getIndicatorCode(self, indicatorId: str) -> str:
|
20
|
+
return self.restApiClient.doGet(f'/indicator/custom/{indicatorId}/code')
|
21
|
+
|
22
|
+
def createUpdateIndicator(self, code: str) -> IndicatorSpec:
|
23
|
+
specDict: Dict[str, Any] = self.restApiClient.doPostCode('/indicator/custom/update', code)
|
24
|
+
return IndicatorSpec.fromDict(specDict)
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import datetime
|
2
|
+
|
3
|
+
from investfly.api.IndicatorApiClient import IndicatorApiClient
|
4
|
+
from investfly.api.MarketDataApiClient import MarketDataApiClient
|
5
|
+
from investfly.api.PortfolioApiClient import PortfolioApiClient
|
6
|
+
from investfly.api.RestApiClient import RestApiClient
|
7
|
+
from investfly.api.StrategyApiClient import StrategyApiClient
|
8
|
+
from investfly.models import Session
|
9
|
+
|
10
|
+
|
11
|
+
class InvestflyApiClient:
|
12
|
+
"""
|
13
|
+
Investfly API Client. This class should be used as the entry point to make all API calls.
|
14
|
+
After authentication, access marketApi or portfolioApi to make calls to /market or /portfolio endpoints
|
15
|
+
"""
|
16
|
+
|
17
|
+
def __init__(self, baseUrl: str = "https://api.investfly.com"):
|
18
|
+
self.restApiClient = RestApiClient(baseUrl)
|
19
|
+
self.marketApi = MarketDataApiClient(self.restApiClient)
|
20
|
+
"""Class used to make calls to /marketdata and /symbol endpoint to get market and symbol data"""
|
21
|
+
self.portfolioApi = PortfolioApiClient(self.restApiClient)
|
22
|
+
"""Class used to make calls to /portfolio endpoint to get portfolio and brokerage account data"""
|
23
|
+
self.strategyApi = StrategyApiClient(self.restApiClient)
|
24
|
+
"""Class used to make calls to /strategy endpoint to operate on trading strategies"""
|
25
|
+
self.indicatorApi = IndicatorApiClient(self.restApiClient)
|
26
|
+
|
27
|
+
def login(self, username, password) -> Session:
|
28
|
+
"""
|
29
|
+
Login to investfly backend.
|
30
|
+
:param username: Username
|
31
|
+
:param password: Password
|
32
|
+
:return: Session object representing authenticated session
|
33
|
+
"""
|
34
|
+
return self.restApiClient.login(username, password)
|
35
|
+
|
36
|
+
def logout(self):
|
37
|
+
self.restApiClient.logout()
|
38
|
+
|
39
|
+
def isLoggedIn(self) -> bool:
|
40
|
+
return "investfly-client-id" in self.restApiClient.headers
|
41
|
+
|
42
|
+
def getSession(self) -> Session:
|
43
|
+
sessionJson = self.restApiClient.doGet('/user/session')
|
44
|
+
session: Session = Session.fromJsonDict(sessionJson)
|
45
|
+
return session
|
46
|
+
|
47
|
+
@staticmethod
|
48
|
+
def parseDatetime(date_str: str) -> datetime.datetime:
|
49
|
+
return datetime.datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%f%z')
|
@@ -4,6 +4,10 @@ from investfly.api.RestApiClient import RestApiClient
|
|
4
4
|
|
5
5
|
|
6
6
|
class MarketDataApiClient:
|
7
|
+
"""
|
8
|
+
MarketDataApiClient is intended to make calls to /marketdata and /symbol endpoint to get market and symbol data
|
9
|
+
from Investfly
|
10
|
+
"""
|
7
11
|
|
8
12
|
def __init__(self, restApiClient: RestApiClient) -> None:
|
9
13
|
self.restApiClient = restApiClient
|
@@ -6,6 +6,10 @@ from investfly.models.PortfolioModels import Broker, Portfolio, Balances, OpenPo
|
|
6
6
|
|
7
7
|
|
8
8
|
class PortfolioApiClient:
|
9
|
+
"""
|
10
|
+
This class is intended to make REST API calls to /portfolio endpoint to get information on virtual portfolio
|
11
|
+
and connected brokerage account
|
12
|
+
"""
|
9
13
|
|
10
14
|
def __init__(self, restApiClient: RestApiClient) -> None:
|
11
15
|
self.restApiClient = restApiClient
|
@@ -12,6 +12,11 @@ warnings.simplefilter("ignore")
|
|
12
12
|
|
13
13
|
class RestApiClient:
|
14
14
|
|
15
|
+
"""
|
16
|
+
Internal class to make REST API requests. Users of the SDK do not use this class directly.
|
17
|
+
Please use investfly.api.InvestflyApiClient` instead
|
18
|
+
"""
|
19
|
+
|
15
20
|
def __init__(self, baseUrl: str) -> None:
|
16
21
|
self.headers: Dict[str, str] = {}
|
17
22
|
self.baseUrl = baseUrl
|
@@ -30,8 +35,8 @@ class RestApiClient:
|
|
30
35
|
|
31
36
|
def logout(self):
|
32
37
|
requests.post(self.baseUrl + "/user/logout", verify=False)
|
33
|
-
self.
|
34
|
-
self.
|
38
|
+
del self.headers['investfly-client-id']
|
39
|
+
del self.headers['investfly-client-token']
|
35
40
|
|
36
41
|
def doGet(self, url: str) -> Any:
|
37
42
|
res = requests.get(self.baseUrl + url, headers=self.headers, verify=False)
|
@@ -0,0 +1,45 @@
|
|
1
|
+
from typing import List, Any, Dict
|
2
|
+
from investfly.api.RestApiClient import RestApiClient
|
3
|
+
from investfly.models.CommonModels import Message
|
4
|
+
from investfly.models.StrategyModels import TradingStrategyModel, BacktestResult
|
5
|
+
|
6
|
+
|
7
|
+
class StrategyApiClient:
|
8
|
+
|
9
|
+
"""
|
10
|
+
Class used to make calls to /strategy endpoint to operate on trading strategies.
|
11
|
+
"""
|
12
|
+
|
13
|
+
def __init__(self, restApiClient: RestApiClient) -> None:
|
14
|
+
self.restApiClient = restApiClient
|
15
|
+
|
16
|
+
def listStrategies(self) -> List[TradingStrategyModel]:
|
17
|
+
strategiesList: List[Dict[str, Any]] = self.restApiClient.doGet('/strategy/list')
|
18
|
+
strategiesList = list(filter(lambda jsonDict: jsonDict['type'] == 'CUSTOM', strategiesList))
|
19
|
+
return list(map(lambda jsonDict: TradingStrategyModel.fromDict(jsonDict), strategiesList))
|
20
|
+
|
21
|
+
def getStrategy(self, strategyId: int) -> TradingStrategyModel:
|
22
|
+
strategyDict = self.restApiClient.doGet('/strategy/' + str(strategyId))
|
23
|
+
return TradingStrategyModel.fromDict(strategyDict)
|
24
|
+
|
25
|
+
def createStrategy(self, strategyModel: TradingStrategyModel) -> TradingStrategyModel:
|
26
|
+
strategyDict = strategyModel.toDict()
|
27
|
+
strategyDict['type'] = 'CUSTOM'
|
28
|
+
strategyDict = self.restApiClient.doPost('/strategy/create', strategyDict)
|
29
|
+
return TradingStrategyModel.fromDict(strategyDict)
|
30
|
+
|
31
|
+
def updateStrategyCode(self, strategyId: int, code: str) -> str:
|
32
|
+
return self.restApiClient.doPostCode('/strategy/' + str(strategyId) + '/update/code', code)
|
33
|
+
|
34
|
+
def startBacktest(self, strategyId: int) -> Message:
|
35
|
+
message = self.restApiClient.doPost(f'/backtest/{strategyId}/start', {})
|
36
|
+
return Message.fromDict(message)
|
37
|
+
|
38
|
+
def stopBacktest(self, strategyId: int) -> Message:
|
39
|
+
message = self.restApiClient.doPost(f'/backtest/{strategyId}/stop', {})
|
40
|
+
return Message.fromDict(message)
|
41
|
+
|
42
|
+
def getBacktestResult(self, strategyId: int) -> BacktestResult:
|
43
|
+
resultDict: Dict[str, Any] = self.restApiClient.doGet(f'/backtest/{strategyId}/result')
|
44
|
+
return BacktestResult.fromDict(resultDict)
|
45
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
""" This package contains REST API Client classes to make REST API calls to Investfly server.
|
2
|
+
The entry point is `investfly.api.InvestflyApiClient`
|
3
|
+
|
4
|
+
InvestflyApiClient has members to access specific endpoints such as strategyApi, portfolioApi etc
|
5
|
+
|
6
|
+
For now, only those API methods that are commonly used during in strategy development are added in the clients.
|
7
|
+
|
8
|
+
```
|
9
|
+
from investfly.api.InvestflyApiClient import InvestflyApiClient
|
10
|
+
api = InvestflyApiClient()
|
11
|
+
api.login("<YOUR USERNAME>", "<YOUR PASSWORD>")
|
12
|
+
pythonStrategies = api.strategyApi.getStrategies()
|
13
|
+
print(pythonStrategies)
|
14
|
+
api.logout()
|
15
|
+
```
|
16
|
+
|
17
|
+
"""
|