2
2
from datetime import datetime
3
3
4
4
from investing_algorithm_framework .domain import OrderSide , OrderStatus , \
5
- OperationalException , MarketService , MarketCredentialService
5
+ OperationalException , MarketService , MarketCredentialService , SYMBOLS
6
6
from investing_algorithm_framework .services .repository_service \
7
7
import RepositoryService
8
+ from investing_algorithm_framework .services .configuration_service import \
9
+ ConfigurationService
8
10
9
11
logger = logging .getLogger ("investing_algorithm_framework" )
10
12
@@ -18,6 +20,7 @@ class PortfolioService(RepositoryService):
18
20
19
21
def __init__ (
20
22
self ,
23
+ configuration_service : ConfigurationService ,
21
24
market_service : MarketService ,
22
25
market_credential_service : MarketCredentialService ,
23
26
position_repository ,
@@ -26,6 +29,7 @@ def __init__(
26
29
portfolio_configuration_service ,
27
30
portfolio_snapshot_service ,
28
31
):
32
+ self .configuration_service = configuration_service
29
33
self .market_credential_service = market_credential_service
30
34
self .market_service = market_service
31
35
self .position_repository = position_repository
@@ -235,12 +239,24 @@ def sync_portfolio_orders(self, portfolio):
235
239
portfolio_configuration = self .portfolio_configuration_service \
236
240
.get (portfolio .identifier )
237
241
238
- # Get all available symbols for the market and check if
239
- # there are orders
240
- available_symbols = self .market_service .get_symbols (
241
- market = portfolio .market
242
- )
242
+ # Check if the symbols param in the configuration is set
243
+ config = self .configuration_service .config
244
+
245
+ if SYMBOLS in config and config [SYMBOLS ] is not None :
246
+ available_symbols = config [SYMBOLS ]
247
+
248
+ if not isinstance (available_symbols , list ):
249
+ raise OperationalException (
250
+ "The symbols configuration should be a list of strings"
251
+ )
252
+ else :
253
+ # if not, get all available symbols for the market and check if
254
+ # there are orders
255
+ available_symbols = self .market_service .get_symbols (
256
+ market = portfolio .market
257
+ )
243
258
259
+ # Check if there are orders for the available symbols
244
260
for symbol in available_symbols :
245
261
orders = self .market_service .get_orders (
246
262
symbol = symbol ,
0 commit comments