Skip to content

Commit c786d9b

Browse files
committed
Fix flake8 errors
1 parent 67ec6e6 commit c786d9b

File tree

8 files changed

+37
-41
lines changed

8 files changed

+37
-41
lines changed

investing_algorithm_framework/app/app.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ def initialize(self, sync=False):
148148
if not portfolio_service.exists(
149149
{"identifier": portfolio_configuration.identifier}
150150
):
151-
portfolio = portfolio_service.create_portfolio_from_configuration(
152-
portfolio_configuration
153-
)
151+
portfolio = portfolio_service\
152+
.create_portfolio_from_configuration(
153+
portfolio_configuration
154+
)
154155
self.sync(portfolio)
155156
synced_portfolios.append(portfolio)
156157

@@ -162,9 +163,6 @@ def initialize(self, sync=False):
162163
if portfolio not in synced_portfolios:
163164
self.sync(portfolio)
164165

165-
166-
167-
168166
def sync(self, portfolio):
169167
"""
170168
Sync the portfolio with the exchange. This method should be called
@@ -259,8 +257,9 @@ def _initialize_app_for_backtest(
259257
configuration_service.config[BACKTESTING_START_DATE] = \
260258
backtest_start_date
261259
configuration_service.config[BACKTESTING_END_DATE] = backtest_end_date
262-
configuration_service.config[BACKTESTING_PENDING_ORDER_CHECK_INTERVAL] \
263-
= pending_order_check_interval
260+
configuration_service.config[
261+
BACKTESTING_PENDING_ORDER_CHECK_INTERVAL
262+
] = pending_order_check_interval
264263

265264
# Create resource dir if not exits
266265
self._create_resource_directory_if_not_exists()

investing_algorithm_framework/domain/models/market/market_credential.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,4 @@ def secret_key(self):
3131

3232
def __repr__(self):
3333
return f"MarketCredential(" \
34-
f"{self.market}, {self.api_key}, {self.secret_key}" \
35-
f")"
34+
f"{self.market}, {self.api_key}, {self.secret_key}"

investing_algorithm_framework/domain/services/portfolios/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
__all__ = [
44
"AbstractPortfolioSyncService"
5-
]
5+
]

investing_algorithm_framework/domain/services/portfolios/portfolio_sync_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ def sync_orders(self, portfolio):
1212
pass
1313

1414
def sync_trades(self, portfolio):
15-
pass
15+
pass

investing_algorithm_framework/infrastructure/repositories/order_repository.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ def _apply_query_params(self, db, query, query_params):
3333
order_by_created_at_asc = self.get_query_param(
3434
"order_by_created_at_asc", query_params
3535
)
36-
order_by_created_at_desc = self.get_query_param(
37-
"order_by_created_at_desc", query_params
38-
)
3936

4037
if portfolio_query_param is not None:
4138
portfolio = db.query(SQLPortfolio).filter_by(

investing_algorithm_framework/services/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
from .backtesting import BacktestService, BacktestReportWriterService
2+
from .configuration_service import ConfigurationService
3+
from .market_credential_service import MarketCredentialService
4+
from .market_data_source_service import MarketDataSourceService, \
5+
BacktestMarketDataSourceService
16
from .order_service import OrderService, OrderBacktestService
27
from .portfolios import PortfolioService, BacktestPortfolioService, \
38
PortfolioConfigurationService, PortfolioSyncService, \
@@ -6,14 +11,8 @@
611
from .position_snapshot_service import PositionSnapshotService
712
from .repository_service import RepositoryService
813
from .strategy_orchestrator_service import StrategyOrchestratorService
9-
from .market_data_source_service import MarketDataSourceService, \
10-
BacktestMarketDataSourceService
11-
from .backtesting import BacktestService, BacktestReportWriterService
12-
from .configuration_service import ConfigurationService
13-
from .market_credential_service import MarketCredentialService
1414
from .trade_service import TradeService
1515

16-
1716
__all__ = [
1817
"StrategyOrchestratorService",
1918
"OrderService",
@@ -26,6 +25,7 @@
2625
"BacktestReportWriterService",
2726
"OrderBacktestService",
2827
"ConfigurationService",
28+
"PortfolioSyncService",
2929
"PortfolioSnapshotService",
3030
"PositionSnapshotService",
3131
"MarketCredentialService",

investing_algorithm_framework/services/portfolios/portfolio_sync_service.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ class PortfolioSyncService(AbstractPortfolioSyncService):
1111
"""
1212
Service to sync the portfolio with the exchange.
1313
"""
14+
1415
def __init__(
15-
self,
16-
trade_service: TradeService,
17-
configuration_service,
18-
order_repository,
19-
position_repository,
20-
portfolio_repository,
21-
portfolio_configuration_service,
22-
market_credential_service,
23-
market_service
16+
self,
17+
trade_service: TradeService,
18+
configuration_service,
19+
order_repository,
20+
position_repository,
21+
portfolio_repository,
22+
portfolio_configuration_service,
23+
market_credential_service,
24+
market_service
2425
):
2526
self.trade_service = trade_service
2627
self.configuration_service = configuration_service
@@ -88,11 +89,10 @@ def sync_unallocated(self, portfolio):
8889

8990
unallocated = unallocated - reserved_unallocated
9091

91-
if portfolio.unallocated is not None and\
92+
if portfolio.unallocated is not None and \
9293
unallocated != portfolio.unallocated:
9394

9495
if unallocated < portfolio.unallocated:
95-
9696
raise OperationalException(
9797
"There seems to be a mismatch between "
9898
"the portfolio configuration and the balances on"
@@ -112,12 +112,12 @@ def sync_unallocated(self, portfolio):
112112
# create the portfolio with the initial balance
113113
if unallocated > portfolio.unallocated and \
114114
not self.portfolio_repository.exists(
115-
{"identifier": portfolio.identifier}
116-
):
115+
{"identifier": portfolio.identifier}
116+
):
117117
unallocated = portfolio.unallocated
118118

119119
if not self.portfolio_repository.exists(
120-
{"identifier": portfolio.identifier}
120+
{"identifier": portfolio.identifier}
121121
):
122122
create_data = {
123123
"identifier": portfolio.get_identifier(),
@@ -138,7 +138,8 @@ def sync_unallocated(self, portfolio):
138138

139139
def sync_positions(self, portfolio):
140140
"""
141-
Method to sync the portfolio balances with the balances on the exchange.
141+
Method to sync the portfolio balances with the balances
142+
on the exchange.
142143
This method will retrieve the balances from the exchange and update
143144
the portfolio balances accordingly.
144145
@@ -249,14 +250,14 @@ def sync_orders(self, portfolio):
249250
if portfolio_configuration.track_from is not None:
250251
ordered_external_order_list = [
251252
order for order in ordered_external_order_list
252-
if order.created_at >=
253-
portfolio_configuration.track_from
253+
if order.created_at >= portfolio_configuration
254+
.track_from
254255
]
255256

256257
for external_order in ordered_external_order_list:
257258

258259
if self.order_repository.exists(
259-
{"external_id": external_order.external_id}
260+
{"external_id": external_order.external_id}
260261
):
261262
logger.info("Updating existing order")
262263
order = self.order_repository.find(

investing_algorithm_framework/services/trade_service/trade_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def close_trades(self, sell_order: Order, amount_to_close: float) -> None:
353353
remaining = amount_to_close - to_be_closed
354354
cost = buy_order.get_price() * to_be_closed
355355
net_gain = (sell_order.get_price() - buy_order.get_price()) \
356-
* to_be_closed
356+
* to_be_closed
357357
amount_to_close = remaining
358358
self.order_service.repository.update(
359359
buy_order.id,
@@ -367,7 +367,7 @@ def close_trades(self, sell_order: Order, amount_to_close: float) -> None:
367367
else:
368368
to_be_closed = amount_to_close
369369
net_gain = (sell_order.get_price() - buy_order.get_price()) \
370-
* to_be_closed
370+
* to_be_closed
371371
cost = buy_order.get_price() * amount_to_close
372372
closed_amount = buy_order.get_trade_closed_amount()
373373

0 commit comments

Comments
 (0)