finterion-investing-algorithm-framework 0.10.6__py3-none-any.whl → 0.10.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of finterion-investing-algorithm-framework might be problematic. Click here for more details.
- finterion_investing_algorithm_framework/create_app.py +5 -6
- finterion_investing_algorithm_framework/market_service.py +56 -16
- finterion_investing_algorithm_framework/models/portfolio_configuration.py +11 -1
- {finterion_investing_algorithm_framework-0.10.6.dist-info → finterion_investing_algorithm_framework-0.10.7.dist-info}/METADATA +1 -1
- {finterion_investing_algorithm_framework-0.10.6.dist-info → finterion_investing_algorithm_framework-0.10.7.dist-info}/RECORD +8 -8
- {finterion_investing_algorithm_framework-0.10.6.dist-info → finterion_investing_algorithm_framework-0.10.7.dist-info}/WHEEL +1 -1
- {finterion_investing_algorithm_framework-0.10.6.dist-info → finterion_investing_algorithm_framework-0.10.7.dist-info}/LICENSE +0 -0
- {finterion_investing_algorithm_framework-0.10.6.dist-info → finterion_investing_algorithm_framework-0.10.7.dist-info}/top_level.txt +0 -0
|
@@ -17,18 +17,17 @@ def create_app(
|
|
|
17
17
|
config={},
|
|
18
18
|
stateless=False,
|
|
19
19
|
web=False,
|
|
20
|
-
initialize=True,
|
|
21
20
|
base_url=None,
|
|
22
21
|
) -> App:
|
|
23
22
|
client = Finterion(api_key=api_key, base_url=base_url)
|
|
24
23
|
client.ping()
|
|
25
24
|
model = client.get_algorithm_model()
|
|
26
25
|
portfolio_configuration = FinterionPortfolioConfiguration(
|
|
27
|
-
api_key=api_key,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
config=config, web=web, stateless=stateless, initialize=initialize
|
|
26
|
+
api_key=api_key,
|
|
27
|
+
trading_symbol=model['profile']['trading_symbol'],
|
|
28
|
+
market_data_markets=model['profile']['markets'],
|
|
31
29
|
)
|
|
30
|
+
app = framework_create_app(config=config, web=web, stateless=stateless)
|
|
32
31
|
app.container.market_service.override(
|
|
33
32
|
FinterionMarketService(api_key=api_key, base_url=base_url)
|
|
34
33
|
)
|
|
@@ -39,7 +38,7 @@ def create_app(
|
|
|
39
38
|
time_unit = TimeUnit.MINUTE
|
|
40
39
|
|
|
41
40
|
def run(self, algorithm):
|
|
42
|
-
logger.
|
|
41
|
+
logger.debug("Pinging Finterion platform")
|
|
43
42
|
client.ping()
|
|
44
43
|
|
|
45
44
|
app.add_task(PingTask)
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
|
+
import ccxt
|
|
3
|
+
from dateutil import parser
|
|
4
|
+
from decimal import Decimal
|
|
2
5
|
|
|
3
6
|
from investing_algorithm_framework.infrastructure.services import MarketService
|
|
4
7
|
from investing_algorithm_framework import Order
|
|
8
|
+
from investing_algorithm_framework.domain import OperationalException, \
|
|
9
|
+
parse_decimal_to_string
|
|
5
10
|
from finterion import Finterion
|
|
6
11
|
|
|
7
12
|
|
|
@@ -9,6 +14,7 @@ class FinterionMarketService(MarketService):
|
|
|
9
14
|
|
|
10
15
|
def __init__(self, api_key, base_url=None, initialize=True):
|
|
11
16
|
self._api_key = api_key
|
|
17
|
+
self._market = "finterion"
|
|
12
18
|
|
|
13
19
|
if initialize:
|
|
14
20
|
if base_url is not None:
|
|
@@ -16,6 +22,29 @@ class FinterionMarketService(MarketService):
|
|
|
16
22
|
else:
|
|
17
23
|
self._finterion = Finterion(api_key)
|
|
18
24
|
|
|
25
|
+
@property
|
|
26
|
+
def market(self):
|
|
27
|
+
return self._market
|
|
28
|
+
|
|
29
|
+
@market.setter
|
|
30
|
+
def market(self, value):
|
|
31
|
+
|
|
32
|
+
if not isinstance(value, str):
|
|
33
|
+
raise OperationalException("Market must be a string")
|
|
34
|
+
|
|
35
|
+
if value == "finterion":
|
|
36
|
+
return
|
|
37
|
+
|
|
38
|
+
self._market = value.lower()
|
|
39
|
+
|
|
40
|
+
if not hasattr(ccxt, self._market):
|
|
41
|
+
raise OperationalException(
|
|
42
|
+
f"No market service found for market id {self._market}"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
self.exchange_class = getattr(ccxt, self._market)
|
|
46
|
+
self.exchange = self.exchange_class()
|
|
47
|
+
|
|
19
48
|
def initialize(self, portfolio_configuration):
|
|
20
49
|
pass
|
|
21
50
|
|
|
@@ -24,7 +53,7 @@ class FinterionMarketService(MarketService):
|
|
|
24
53
|
return self._convert_order(order)
|
|
25
54
|
|
|
26
55
|
def get_orders(self, symbol, since: datetime = None):
|
|
27
|
-
orders = self._finterion.get_orders(
|
|
56
|
+
orders = self._finterion.get_orders(target_symbol=symbol)
|
|
28
57
|
return [self._convert_order(order) for order in orders]
|
|
29
58
|
|
|
30
59
|
def get_balance(self):
|
|
@@ -33,7 +62,7 @@ class FinterionMarketService(MarketService):
|
|
|
33
62
|
|
|
34
63
|
for position in positions:
|
|
35
64
|
entries[position["symbol"]] = {
|
|
36
|
-
"free": position["amount"],
|
|
65
|
+
"free": Decimal(position["amount"]),
|
|
37
66
|
}
|
|
38
67
|
|
|
39
68
|
return entries
|
|
@@ -46,7 +75,7 @@ class FinterionMarketService(MarketService):
|
|
|
46
75
|
):
|
|
47
76
|
order = self._finterion.create_market_order(
|
|
48
77
|
order_side="sell",
|
|
49
|
-
amount=amount,
|
|
78
|
+
amount=str(amount),
|
|
50
79
|
target_symbol=target_symbol,
|
|
51
80
|
)
|
|
52
81
|
return self._convert_order(order)
|
|
@@ -55,12 +84,12 @@ class FinterionMarketService(MarketService):
|
|
|
55
84
|
self,
|
|
56
85
|
target_symbol: str,
|
|
57
86
|
trading_symbol: str,
|
|
58
|
-
amount
|
|
59
|
-
price
|
|
87
|
+
amount,
|
|
88
|
+
price
|
|
60
89
|
):
|
|
61
90
|
order = self._finterion.create_limit_order(
|
|
62
91
|
order_side="sell",
|
|
63
|
-
amount=amount,
|
|
92
|
+
amount=parse_decimal_to_string(amount),
|
|
64
93
|
target_symbol=target_symbol,
|
|
65
94
|
price=price
|
|
66
95
|
)
|
|
@@ -75,28 +104,39 @@ class FinterionMarketService(MarketService):
|
|
|
75
104
|
):
|
|
76
105
|
order = self._finterion.create_limit_order(
|
|
77
106
|
order_side="buy",
|
|
78
|
-
amount=amount,
|
|
107
|
+
amount=str(amount),
|
|
79
108
|
target_symbol=target_symbol,
|
|
80
|
-
price=price
|
|
109
|
+
price=str(price)
|
|
81
110
|
)
|
|
82
111
|
return self._convert_order(order)
|
|
83
112
|
|
|
84
113
|
def _convert_order(self, finterion_order):
|
|
85
|
-
|
|
114
|
+
order = Order(
|
|
86
115
|
external_id=finterion_order.get("id"),
|
|
87
|
-
|
|
116
|
+
order_type=finterion_order.get("order_type"),
|
|
88
117
|
side=finterion_order.get("order_side"),
|
|
89
118
|
status=finterion_order.get("status"),
|
|
90
119
|
amount=finterion_order.get("amount"),
|
|
91
120
|
target_symbol=finterion_order.get("target_symbol"),
|
|
92
121
|
trading_symbol=finterion_order.get("trading_symbol"),
|
|
93
122
|
price=finterion_order.get("price"),
|
|
94
|
-
created_at=finterion_order.get("created_at"),
|
|
95
|
-
updated_at=finterion_order.get("updated_at"),
|
|
96
|
-
trade_closed_at=finterion_order.get("trade_closed_at"),
|
|
97
123
|
trade_closed_price=finterion_order.get("trade_closed_price"),
|
|
98
|
-
filled_amount=finterion_order.get("
|
|
99
|
-
remaining_amount=finterion_order.get("
|
|
124
|
+
filled_amount=finterion_order.get("filled"),
|
|
125
|
+
remaining_amount=finterion_order.get("remaining"),
|
|
100
126
|
cost=finterion_order.get("cost"),
|
|
101
|
-
fee=finterion_order.get("fee"),
|
|
102
127
|
)
|
|
128
|
+
|
|
129
|
+
if finterion_order.get("trade_closed_at") is not None:
|
|
130
|
+
order.trade_closed_at = parser.parse(
|
|
131
|
+
finterion_order.get("trade_closed_at")
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
if finterion_order.get("created_at") is not None:
|
|
135
|
+
order.created_at = parser.parse(finterion_order.get("created_at"))
|
|
136
|
+
|
|
137
|
+
if finterion_order.get("updated_at") is not None:
|
|
138
|
+
order.updated_at = parser.parse(finterion_order.get("updated_at"))
|
|
139
|
+
|
|
140
|
+
return order
|
|
141
|
+
|
|
142
|
+
|
|
@@ -4,7 +4,7 @@ from investing_algorithm_framework.domain import ImproperlyConfigured
|
|
|
4
4
|
|
|
5
5
|
class FinterionPortfolioConfiguration(PortfolioConfiguration):
|
|
6
6
|
|
|
7
|
-
def __init__(self, api_key, trading_symbol):
|
|
7
|
+
def __init__(self, api_key, trading_symbol, market_data_markets):
|
|
8
8
|
try:
|
|
9
9
|
super().__init__(
|
|
10
10
|
market="finterion",
|
|
@@ -15,6 +15,16 @@ class FinterionPortfolioConfiguration(PortfolioConfiguration):
|
|
|
15
15
|
except ImproperlyConfigured:
|
|
16
16
|
pass
|
|
17
17
|
|
|
18
|
+
if market_data_markets is None:
|
|
19
|
+
raise ImproperlyConfigured(
|
|
20
|
+
"Your algorithm has no markets configured. Please add at "
|
|
21
|
+
"least one market to your algorithm on the finterion platform."
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
self._market = market_data_markets[0]
|
|
25
|
+
|
|
18
26
|
@property
|
|
19
27
|
def identifier(self):
|
|
20
28
|
return "finterion"
|
|
29
|
+
|
|
30
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: finterion-investing-algorithm-framework
|
|
3
|
-
Version: 0.10.
|
|
3
|
+
Version: 0.10.7
|
|
4
4
|
Summary: Official Finterion plugin for the investing algorithm framework
|
|
5
5
|
Home-page: https://github.com/finterion/finterion-investing-algorithm-framework.git
|
|
6
6
|
Author: Finterion
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
finterion_investing_algorithm_framework/__init__.py,sha256=u-srn87VlLUPUJHWR5hgMAHqw2BWtb1v0eH0tQ8M16w,107
|
|
2
|
-
finterion_investing_algorithm_framework/create_app.py,sha256=
|
|
2
|
+
finterion_investing_algorithm_framework/create_app.py,sha256=tIQAhrWLGDf7d7TQyI48mKTGrSc_QtcpdYAbn073k_Y,1384
|
|
3
3
|
finterion_investing_algorithm_framework/exceptions.py,sha256=KOaDjHQC7vNpKwYYNxJ2nuaJYceMmvExW3BLSzPSWJk,197
|
|
4
|
-
finterion_investing_algorithm_framework/market_service.py,sha256=
|
|
4
|
+
finterion_investing_algorithm_framework/market_service.py,sha256=hWwBTnHOh5f2WAYmLzXNF5il78fPf4vAeGOiCryue5M,4366
|
|
5
5
|
finterion_investing_algorithm_framework/configuration/__init__.py,sha256=yz9TVm7RoGgF3EJ95-iLJrMup7eYoRvTXY1TyfEiGf4,42
|
|
6
6
|
finterion_investing_algorithm_framework/configuration/constants.py,sha256=bhabsdZ8omPvAZlQmdPGM70vHQHS2pcJm2olpkSEciU,93
|
|
7
7
|
finterion_investing_algorithm_framework/models/__init__.py,sha256=waEhKjOtg3oSSoyWHNFsQCcRklQm5EeOoAVCyEaMxSs,174
|
|
8
|
-
finterion_investing_algorithm_framework/models/portfolio_configuration.py,sha256=
|
|
9
|
-
finterion_investing_algorithm_framework-0.10.
|
|
10
|
-
finterion_investing_algorithm_framework-0.10.
|
|
11
|
-
finterion_investing_algorithm_framework-0.10.
|
|
12
|
-
finterion_investing_algorithm_framework-0.10.
|
|
13
|
-
finterion_investing_algorithm_framework-0.10.
|
|
8
|
+
finterion_investing_algorithm_framework/models/portfolio_configuration.py,sha256=cjkD_3VVGRPbsDbsRkY_0eKoTSdB7jADFL_I8hdArg4,898
|
|
9
|
+
finterion_investing_algorithm_framework-0.10.7.dist-info/LICENSE,sha256=wbVEDvoZiMPHufRY3sLEffvAr7GH5hOIngHF8y4HFQg,11343
|
|
10
|
+
finterion_investing_algorithm_framework-0.10.7.dist-info/METADATA,sha256=UdmBVIF6cktW54TiC2ddRiaTypw7XHphAIOt_XcaGKw,3288
|
|
11
|
+
finterion_investing_algorithm_framework-0.10.7.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
|
12
|
+
finterion_investing_algorithm_framework-0.10.7.dist-info/top_level.txt,sha256=B97hJPQAFX_vRhcLE8uVZ6ac3a5ndS79p-O8-C2y-zw,40
|
|
13
|
+
finterion_investing_algorithm_framework-0.10.7.dist-info/RECORD,,
|
|
File without changes
|