finterion-investing-algorithm-framework 0.23.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- finterion_investing_algorithm_framework-0.23.0/LICENSE +201 -0
- finterion_investing_algorithm_framework-0.23.0/PKG-INFO +70 -0
- finterion_investing_algorithm_framework-0.23.0/README.md +55 -0
- finterion_investing_algorithm_framework-0.23.0/finterion_investing_algorithm_framework/__init__.py +9 -0
- finterion_investing_algorithm_framework-0.23.0/finterion_investing_algorithm_framework/order_executor.py +112 -0
- finterion_investing_algorithm_framework-0.23.0/finterion_investing_algorithm_framework/ping_hook.py +39 -0
- finterion_investing_algorithm_framework-0.23.0/finterion_investing_algorithm_framework/portfolio_provider.py +123 -0
- finterion_investing_algorithm_framework-0.23.0/finterion_investing_algorithm_framework/utils.py +56 -0
- finterion_investing_algorithm_framework-0.23.0/pyproject.toml +19 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2020 Coding Kitties
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: finterion-investing-algorithm-framework
|
|
3
|
+
Version: 0.23.0
|
|
4
|
+
Summary: This is the official finterion plugin for the investing algorithm framework open source project.
|
|
5
|
+
Author: Marc van Duyn
|
|
6
|
+
Author-email: marc@finterion.com
|
|
7
|
+
Requires-Python: >=3.10,<4.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Requires-Dist: finterion (>=0.8.9,<0.9.0)
|
|
13
|
+
Requires-Dist: investing-algorithm-framework (>=6.5.2)
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# Finterion Investing Algorithm Framework Plugin
|
|
17
|
+
|
|
18
|
+
<a href="https://www.finterion.com/" target="_blank">
|
|
19
|
+
<picture style="height: 30px;">
|
|
20
|
+
<source media="(prefers-color-scheme: dark)" srcset="static/sponsors/finterion-dark.png">
|
|
21
|
+
<source media="(prefers-color-scheme: light)" srcset="static/sponsors/finterion-light.png">
|
|
22
|
+
<img src="static/sponsors/finterion-light.png" alt="Finterion Logo" width="200px" height="50px">
|
|
23
|
+
</picture>
|
|
24
|
+
</a>
|
|
25
|
+
|
|
26
|
+
This is the official plugin for the [investing algorithm framework](https://investing-algorithm-framework.com) open source project.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
You can install the plugin with pip.
|
|
30
|
+
```shell
|
|
31
|
+
pip install finterion-investing-algorithm-framework
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
In order to use the plugin you must register the following components in your investing algorithm framework application:
|
|
36
|
+
- **FinterionOrderExecutor**: This component is responsible for executing orders on the finterion platform.
|
|
37
|
+
- **FinterionPortfolioProvider**: This component is responsible for connecting the portfolio and syncing positions.
|
|
38
|
+
- **FinterionPingHook**: This component is responsible for pinging the finterion platform.
|
|
39
|
+
|
|
40
|
+
> **Note:** You must provide the API key of your algorithm in order to use
|
|
41
|
+
> the plugin. You can find your API keys in the developer dashboard of
|
|
42
|
+
> your algorithm on the finterion platform.
|
|
43
|
+
|
|
44
|
+
## Example
|
|
45
|
+
```python
|
|
46
|
+
import logging.config
|
|
47
|
+
from dotenv import load_dotenv
|
|
48
|
+
|
|
49
|
+
from investing_algorithm_framework import create_app, DEFAULT_LOGGING_CONFIG
|
|
50
|
+
|
|
51
|
+
from finterion_investing_algorithm_framework import \
|
|
52
|
+
FinterionPortfolioProvider, FinterionOrderExecutor, FinterionPingAction
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
load_dotenv()
|
|
56
|
+
logging.config.dictConfig(DEFAULT_LOGGING_CONFIG)
|
|
57
|
+
|
|
58
|
+
app = create_app()
|
|
59
|
+
app.on_strategy_run(FinterionPingAction)
|
|
60
|
+
app.add_order_executor(FinterionOrderExecutor)
|
|
61
|
+
app.add_portfolio_provider(FinterionPortfolioProvider)
|
|
62
|
+
app.add_market(
|
|
63
|
+
market="Finterion",
|
|
64
|
+
api_key="<FINTERION_API_KEY>", # Or set the environment variable FINTERION_API_KEY
|
|
65
|
+
trading_symbol="EUR",
|
|
66
|
+
)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Documentation
|
|
70
|
+
You can find the official documentation at our [documentation website](https://docs.finterion.com/)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Finterion Investing Algorithm Framework Plugin
|
|
2
|
+
|
|
3
|
+
<a href="https://www.finterion.com/" target="_blank">
|
|
4
|
+
<picture style="height: 30px;">
|
|
5
|
+
<source media="(prefers-color-scheme: dark)" srcset="static/sponsors/finterion-dark.png">
|
|
6
|
+
<source media="(prefers-color-scheme: light)" srcset="static/sponsors/finterion-light.png">
|
|
7
|
+
<img src="static/sponsors/finterion-light.png" alt="Finterion Logo" width="200px" height="50px">
|
|
8
|
+
</picture>
|
|
9
|
+
</a>
|
|
10
|
+
|
|
11
|
+
This is the official plugin for the [investing algorithm framework](https://investing-algorithm-framework.com) open source project.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
You can install the plugin with pip.
|
|
15
|
+
```shell
|
|
16
|
+
pip install finterion-investing-algorithm-framework
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
In order to use the plugin you must register the following components in your investing algorithm framework application:
|
|
21
|
+
- **FinterionOrderExecutor**: This component is responsible for executing orders on the finterion platform.
|
|
22
|
+
- **FinterionPortfolioProvider**: This component is responsible for connecting the portfolio and syncing positions.
|
|
23
|
+
- **FinterionPingHook**: This component is responsible for pinging the finterion platform.
|
|
24
|
+
|
|
25
|
+
> **Note:** You must provide the API key of your algorithm in order to use
|
|
26
|
+
> the plugin. You can find your API keys in the developer dashboard of
|
|
27
|
+
> your algorithm on the finterion platform.
|
|
28
|
+
|
|
29
|
+
## Example
|
|
30
|
+
```python
|
|
31
|
+
import logging.config
|
|
32
|
+
from dotenv import load_dotenv
|
|
33
|
+
|
|
34
|
+
from investing_algorithm_framework import create_app, DEFAULT_LOGGING_CONFIG
|
|
35
|
+
|
|
36
|
+
from finterion_investing_algorithm_framework import \
|
|
37
|
+
FinterionPortfolioProvider, FinterionOrderExecutor, FinterionPingAction
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
load_dotenv()
|
|
41
|
+
logging.config.dictConfig(DEFAULT_LOGGING_CONFIG)
|
|
42
|
+
|
|
43
|
+
app = create_app()
|
|
44
|
+
app.on_strategy_run(FinterionPingAction)
|
|
45
|
+
app.add_order_executor(FinterionOrderExecutor)
|
|
46
|
+
app.add_portfolio_provider(FinterionPortfolioProvider)
|
|
47
|
+
app.add_market(
|
|
48
|
+
market="Finterion",
|
|
49
|
+
api_key="<FINTERION_API_KEY>", # Or set the environment variable FINTERION_API_KEY
|
|
50
|
+
trading_symbol="EUR",
|
|
51
|
+
)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Documentation
|
|
55
|
+
You can find the official documentation at our [documentation website](https://docs.finterion.com/)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
from logging import getLogger
|
|
2
|
+
|
|
3
|
+
from investing_algorithm_framework import OrderExecutor, OrderType, \
|
|
4
|
+
OrderSide, Order, OperationalException
|
|
5
|
+
from finterion import Finterion
|
|
6
|
+
|
|
7
|
+
from .utils import convert_finterion_order_to_order
|
|
8
|
+
|
|
9
|
+
logger = getLogger("investing_algorithm_framework")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class FinterionOrderExecutor(OrderExecutor):
|
|
13
|
+
"""
|
|
14
|
+
FinterionOrderExecutor is a class that implements the OrderExecutor
|
|
15
|
+
interface for executing and canceling orders using the Finterion API.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def execute_order(self, portfolio, order, market_credential) -> Order:
|
|
19
|
+
"""
|
|
20
|
+
Executes an order for a given portfolio on Finterion.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
order: The order to be executed
|
|
24
|
+
portfolio: The portfolio in which the order will be executed
|
|
25
|
+
market_credential: The market credential to use for the order
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
Order: Instance of the executed order. The order instance
|
|
29
|
+
should copy the id of the order that has been provided as a
|
|
30
|
+
"""
|
|
31
|
+
finterion_client = self.initialize(market_credential)
|
|
32
|
+
target_symbol = order.get_target_symbol()
|
|
33
|
+
amount = order.get_amount()
|
|
34
|
+
price = order.get_price()
|
|
35
|
+
order_type = order.get_order_type()
|
|
36
|
+
order_side = order.get_order_side()
|
|
37
|
+
|
|
38
|
+
try:
|
|
39
|
+
if OrderType.LIMIT.equals(order_type):
|
|
40
|
+
if OrderSide.BUY.equals(order_side):
|
|
41
|
+
external_order = finterion_client.create_limit_order(
|
|
42
|
+
order_side="buy",
|
|
43
|
+
amount=str(amount),
|
|
44
|
+
target_symbol=target_symbol,
|
|
45
|
+
price=price
|
|
46
|
+
)
|
|
47
|
+
external_order = (
|
|
48
|
+
convert_finterion_order_to_order(external_order)
|
|
49
|
+
)
|
|
50
|
+
else:
|
|
51
|
+
external_order = finterion_client.create_limit_order(
|
|
52
|
+
order_side="sell",
|
|
53
|
+
amount=str(amount),
|
|
54
|
+
target_symbol=target_symbol,
|
|
55
|
+
price=price
|
|
56
|
+
)
|
|
57
|
+
external_order = (
|
|
58
|
+
convert_finterion_order_to_order(external_order)
|
|
59
|
+
)
|
|
60
|
+
else:
|
|
61
|
+
raise OperationalException(
|
|
62
|
+
f"Order type {order_type} not supported "
|
|
63
|
+
f"by CCXT OrderExecutor"
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
external_order.id = order.id
|
|
67
|
+
return external_order
|
|
68
|
+
except Exception as e:
|
|
69
|
+
logger.exception(e)
|
|
70
|
+
raise OperationalException("Could not create finterion order")
|
|
71
|
+
|
|
72
|
+
def cancel_order(self, portfolio, order, market_credential) -> Order:
|
|
73
|
+
"""
|
|
74
|
+
Cancels an order for a given portfolio on a CCXT exchange.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
order: The order to be canceled
|
|
78
|
+
portfolio: The portfolio in which the order was executed
|
|
79
|
+
market_credential: The market credential to use for the order
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
Order: Instance of the canceled order.
|
|
83
|
+
"""
|
|
84
|
+
raise OperationalException("Cancel order not supported")
|
|
85
|
+
|
|
86
|
+
@staticmethod
|
|
87
|
+
def initialize(market_credential) -> Finterion:
|
|
88
|
+
"""
|
|
89
|
+
Function to initialize the finterion api client.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
market_credential (MarketCredential): The market credential to use
|
|
93
|
+
with the finterion api client
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
Finterion: Instance of the Finterion API client
|
|
97
|
+
"""
|
|
98
|
+
api_key = market_credential.api_key
|
|
99
|
+
return Finterion(api_key)
|
|
100
|
+
|
|
101
|
+
def supports_market(self, market):
|
|
102
|
+
"""
|
|
103
|
+
Function to check if the market is supported by the portfolio
|
|
104
|
+
provider.
|
|
105
|
+
|
|
106
|
+
Args:
|
|
107
|
+
market: Market object
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
bool: True if the market is supported, False otherwise
|
|
111
|
+
"""
|
|
112
|
+
return market.lower() == "finterion"
|
finterion_investing_algorithm_framework-0.23.0/finterion_investing_algorithm_framework/ping_hook.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from logging import getLogger
|
|
2
|
+
from investing_algorithm_framework import AppHook
|
|
3
|
+
from finterion import Finterion
|
|
4
|
+
|
|
5
|
+
logger = getLogger("investing_algorithm_framework")
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class FinterionPingAction(AppHook):
|
|
9
|
+
"""
|
|
10
|
+
A class that implements the AppHook interface to perform a ping action
|
|
11
|
+
on the Finterion API.
|
|
12
|
+
"""
|
|
13
|
+
def on_run(self, context):
|
|
14
|
+
"""
|
|
15
|
+
Method to be called when the algorithm is run.
|
|
16
|
+
It pings the Finterion API and prints the response.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
context: The context of the framework
|
|
20
|
+
"""
|
|
21
|
+
logger.info("Pinging Finterion")
|
|
22
|
+
market_credential = context.get_market_credential("finterion")
|
|
23
|
+
finterion_client = self.initialize(market_credential)
|
|
24
|
+
finterion_client.ping()
|
|
25
|
+
|
|
26
|
+
@staticmethod
|
|
27
|
+
def initialize(market_credential) -> Finterion:
|
|
28
|
+
"""
|
|
29
|
+
Function to initialize the finterion api client.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
market_credential (MarketCredential): The market credential to use
|
|
33
|
+
with the finterion api client
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
Finterion: Instance of the Finterion API client
|
|
37
|
+
"""
|
|
38
|
+
api_key = market_credential.api_key
|
|
39
|
+
return Finterion(api_key)
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
from logging import getLogger
|
|
2
|
+
from typing import Union
|
|
3
|
+
|
|
4
|
+
from investing_algorithm_framework.domain import PortfolioProvider, \
|
|
5
|
+
OperationalException, Order, Position
|
|
6
|
+
from finterion import Finterion
|
|
7
|
+
|
|
8
|
+
from .utils import convert_finterion_order_to_order, \
|
|
9
|
+
convert_finterion_position_to_position
|
|
10
|
+
|
|
11
|
+
logger = getLogger("investing_algorithm_framework")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class FinterionPortfolioProvider(PortfolioProvider):
|
|
15
|
+
"""
|
|
16
|
+
Implementation of Portfolio Provider for Finterion.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def get_order(
|
|
20
|
+
self, portfolio, order, market_credential
|
|
21
|
+
) -> Union[Order, None]:
|
|
22
|
+
"""
|
|
23
|
+
Method to check if there are any pending orders for the portfolio.
|
|
24
|
+
This method will retrieve the open orders from the exchange and
|
|
25
|
+
check if there are any pending orders for the portfolio.
|
|
26
|
+
|
|
27
|
+
!IMPORTANT: This function should return None if the order is
|
|
28
|
+
not found or if the order is not available on the
|
|
29
|
+
exchange or broker. Please do not throw an exception if the
|
|
30
|
+
order is not found.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
portfolio: Portfolio object
|
|
34
|
+
order: Order object from the database
|
|
35
|
+
market_credential: Market credential object
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
None
|
|
39
|
+
"""
|
|
40
|
+
finterion_client = self.initialize(market_credential)
|
|
41
|
+
|
|
42
|
+
try:
|
|
43
|
+
external_order = finterion_client.get_order(
|
|
44
|
+
order.get_external_id()
|
|
45
|
+
)
|
|
46
|
+
external_order = (
|
|
47
|
+
convert_finterion_order_to_order(external_order)
|
|
48
|
+
)
|
|
49
|
+
external_order.id = order.id
|
|
50
|
+
return external_order
|
|
51
|
+
except Exception as e:
|
|
52
|
+
logger.exception(e)
|
|
53
|
+
raise OperationalException(
|
|
54
|
+
"Could not retrieve order from Finterion"
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
def get_position(
|
|
58
|
+
self, portfolio, symbol, market_credential
|
|
59
|
+
) -> Union[Position, None]:
|
|
60
|
+
"""
|
|
61
|
+
Function to get the position for a given symbol in the portfolio.
|
|
62
|
+
The returned position should be an object that reflects the current
|
|
63
|
+
state of the position on the exchange or broker.
|
|
64
|
+
|
|
65
|
+
!IMPORTANT: This function should return None if the position is
|
|
66
|
+
not found or if the position is not available on the
|
|
67
|
+
exchange or broker. Please do not throw an exception if the
|
|
68
|
+
position is not found.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
portfolio (Portfolio): Portfolio object
|
|
72
|
+
symbol (str): Symbol object
|
|
73
|
+
market_credential (MarketCredential): MarketCredential object
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
Position: Position for the given symbol in the portfolio
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
finterion_client = self.initialize(market_credential)
|
|
80
|
+
symbol = symbol
|
|
81
|
+
|
|
82
|
+
try:
|
|
83
|
+
external_positions = finterion_client.get_positions(
|
|
84
|
+
symbol=symbol
|
|
85
|
+
)
|
|
86
|
+
external_position = (
|
|
87
|
+
convert_finterion_position_to_position(external_positions[0])
|
|
88
|
+
)
|
|
89
|
+
external_position.portfolio_id = portfolio.id
|
|
90
|
+
return external_position
|
|
91
|
+
except Exception as e:
|
|
92
|
+
logger.exception(e)
|
|
93
|
+
raise OperationalException(
|
|
94
|
+
"Could not retrieve position from Finterion"
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
@staticmethod
|
|
98
|
+
def initialize(market_credential) -> Finterion:
|
|
99
|
+
"""
|
|
100
|
+
Function to initialize the finterion api client.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
market_credential (MarketCredential): The market credential to use
|
|
104
|
+
with the finterion api client
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
Finterion: Instance of the Finterion API client
|
|
108
|
+
"""
|
|
109
|
+
api_key = market_credential.api_key
|
|
110
|
+
return Finterion(api_key)
|
|
111
|
+
|
|
112
|
+
def supports_market(self, market):
|
|
113
|
+
"""
|
|
114
|
+
Function to check if the market is supported by the portfolio
|
|
115
|
+
provider.
|
|
116
|
+
|
|
117
|
+
Args:
|
|
118
|
+
market: Market object
|
|
119
|
+
|
|
120
|
+
Returns:
|
|
121
|
+
bool: True if the market is supported, False otherwise
|
|
122
|
+
"""
|
|
123
|
+
return market.lower() == "finterion"
|
finterion_investing_algorithm_framework-0.23.0/finterion_investing_algorithm_framework/utils.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from dateutil import parser
|
|
2
|
+
from investing_algorithm_framework import Order, Position
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def convert_finterion_order_to_order(finterion_order):
|
|
6
|
+
"""
|
|
7
|
+
Convert a Finterion order to an Order object from the
|
|
8
|
+
investing_algorithm_framework.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
finterion_order (dict): The Finterion order data.
|
|
12
|
+
|
|
13
|
+
Returns:
|
|
14
|
+
Order: An Order object populated with the data
|
|
15
|
+
from the Finterion order.
|
|
16
|
+
"""
|
|
17
|
+
order = Order(
|
|
18
|
+
external_id=finterion_order.get("id"),
|
|
19
|
+
order_type=finterion_order.get("order_type"),
|
|
20
|
+
order_side=finterion_order.get("order_side"),
|
|
21
|
+
status=finterion_order.get("status"),
|
|
22
|
+
amount=float(finterion_order.get("amount")),
|
|
23
|
+
target_symbol=finterion_order.get("target_symbol"),
|
|
24
|
+
trading_symbol=finterion_order.get("trading_symbol"),
|
|
25
|
+
price=float(finterion_order.get("price")),
|
|
26
|
+
filled=float(finterion_order.get("filled")),
|
|
27
|
+
remaining=float(finterion_order.get("remaining")),
|
|
28
|
+
cost=float(finterion_order.get("cost")),
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
if finterion_order.get("created_at") is not None:
|
|
32
|
+
order.created_at = parser.parse(finterion_order.get("created_at"))
|
|
33
|
+
|
|
34
|
+
if finterion_order.get("updated_at") is not None:
|
|
35
|
+
order.updated_at = parser.parse(finterion_order.get("updated_at"))
|
|
36
|
+
|
|
37
|
+
return order
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def convert_finterion_position_to_position(finterion_position) -> Position:
|
|
41
|
+
"""
|
|
42
|
+
Convert a Finterion position to a Position object from the
|
|
43
|
+
investing_algorithm_framework.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
finterion_position (dict): The Finterion position data.
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
Position: An Position object populated with the data
|
|
50
|
+
from the Finterion position.
|
|
51
|
+
"""
|
|
52
|
+
return Position(
|
|
53
|
+
symbol=finterion_position.get("symbol"),
|
|
54
|
+
amount=float(finterion_position.get("amount")),
|
|
55
|
+
cost=float(finterion_position.get("cost")),
|
|
56
|
+
)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "finterion-investing-algorithm-framework"
|
|
3
|
+
version = "v0.23.0"
|
|
4
|
+
description = "This is the official finterion plugin for the investing algorithm framework open source project."
|
|
5
|
+
authors = ["Marc van Duyn <marc@finterion.com>"]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
|
|
8
|
+
[tool.poetry.dependencies]
|
|
9
|
+
python = "^3.10"
|
|
10
|
+
investing-algorithm-framework = ">=6.5.2"
|
|
11
|
+
finterion = "^0.8.9"
|
|
12
|
+
|
|
13
|
+
[tool.poetry.group.test.dependencies]
|
|
14
|
+
coverage= "7.4.2"
|
|
15
|
+
flake8 = "7.0.0"
|
|
16
|
+
|
|
17
|
+
[build-system]
|
|
18
|
+
requires = ["poetry-core"]
|
|
19
|
+
build-backend = "poetry.core.masonry.api"
|