Skip to content

Commit a7c50fd

Browse files
committed
Fix flake8 issues
1 parent 021be50 commit a7c50fd

File tree

16 files changed

+450
-307
lines changed

16 files changed

+450
-307
lines changed

investing_algorithm_framework/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
CCXTTickerMarketDataSource, CSVOHLCVMarketDataSource, \
1818
CSVTickerMarketDataSource
1919
from .create_app import create_app
20-
from investing_algorithm_framework.indicators import *
2120

2221
__all__ = [
2322
"Algorithm",

investing_algorithm_framework/app/algorithm.py

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,16 @@ def _validate_name(self, name):
8989
None
9090
"""
9191
if not isinstance(name, str):
92-
raise OperationalException("The name of the algorithm must be a string")
93-
92+
raise OperationalException(
93+
"The name of the algorithm must be a string"
94+
)
95+
9496
pattern = re.compile(r"^[a-zA-Z0-9]*$")
9597
if not pattern.match(name):
96-
raise OperationalException("The name of the algorithm can only contain letters and numbers")
98+
raise OperationalException(
99+
"The name of the algorithm can only contain" +
100+
" letters and numbers"
101+
)
97102

98103
def initialize_services(
99104
self,
@@ -256,19 +261,19 @@ def create_order(
256261
return self.order_service.create(
257262
order_data, execute=execute, validate=validate, sync=sync
258263
)
259-
264+
260265
def has_balance(self, symbol, amount, market=None):
261266
"""
262267
Function to check if the portfolio has enough balance to
263268
create an order. This function will return True if the
264-
portfolio has enough balance to create an order, False
269+
portfolio has enough balance to create an order, False
265270
otherwise.
266271
267272
Parameters:
268273
symbol: The symbol of the asset
269274
amount: The amount of the asset
270275
market: The market of the asset
271-
276+
272277
Returns:
273278
Boolean: True if the portfolio has enough balance
274279
"""
@@ -309,20 +314,26 @@ def create_limit_order(
309314
price: The price of the asset
310315
order_side: The side of the order
311316
amount (optional): The amount of the asset to trade
312-
amount_trading_symbol (optional): The amount of the trading symbol to trade
313-
percentage (optional): The percentage of the portfolio to allocate to the
317+
amount_trading_symbol (optional): The amount of the
318+
trading symbol to trade
319+
percentage (optional): The percentage of the portfolio
320+
to allocate to the
314321
order
315-
percentage_of_portfolio (optional): The percentage of the portfolio to
316-
allocate to the order
317-
percentage_of_position (optional): The percentage of the position to
318-
allocate to the order. (Only supported for SELL orders)
322+
percentage_of_portfolio (optional): The percentage
323+
of the portfolio to allocate to the order
324+
percentage_of_position (optional): The percentage
325+
of the position to allocate to
326+
the order. (Only supported for SELL orders)
319327
precision (optional): The precision of the amount
320328
market (optional): The market to trade the asset
321-
execute (optional): Default True. If set to True, the order will be executed
322-
validate (optional): Default True. If set to True, the order will be validated
323-
sync (optional): Default True. If set to True, the created order will be synced with the
329+
execute (optional): Default True. If set to True,
330+
the order will be executed
331+
validate (optional): Default True. If set to
332+
True, the order will be validated
333+
sync (optional): Default True. If set to True,
334+
the created order will be synced with the
324335
portfolio of the algorithm
325-
336+
326337
Returns:
327338
Order: Instance of the order created
328339
"""
@@ -369,10 +380,10 @@ def create_limit_order(
369380
raise OperationalException(
370381
"The amount parameter is required to create a limit order." +
371382
"Either the amount, amount_trading_symbol, percentage, " +
372-
"percentage_of_portfolio or percentage_of_position parameter " +
373-
"must be specified."
383+
"percentage_of_portfolio or percentage_of_position "
384+
"parameter must be specified."
374385
)
375-
386+
376387
order_data = {
377388
"target_symbol": target_symbol,
378389
"price": price,
@@ -417,7 +428,7 @@ def create_market_order(
417428
validate: If set to True, the order will be validated
418429
sync: If set to True, the created order will be synced with the
419430
portfolio of the algorithm
420-
431+
421432
Returns:
422433
Order: Instance of the order created
423434
"""
@@ -454,7 +465,7 @@ def get_portfolio(self, market=None) -> Portfolio:
454465
455466
Parameters:
456467
market: The market of the portfolio
457-
468+
458469
Returns:
459470
Portfolio: The portfolio of the algorithm
460471
"""
@@ -492,7 +503,7 @@ def get_total_size(self):
492503
"""
493504
Returns the total size of the portfolio.
494505
495-
The total size of the portfolio is the unallocated balance and the
506+
The total size of the portfolio is the unallocated balance and the
496507
allocated balance of the portfolio.
497508
498509
Returns:
@@ -597,7 +608,7 @@ def get_positions(
597608
amount_lt: The amount of the asset must be less than this
598609
amount_lte: The amount of the asset must be less than or equal
599610
to this
600-
611+
601612
Returns:
602613
List[Position]: A list of positions that match the query parameters
603614
"""
@@ -1167,7 +1178,7 @@ def get_closed_trades(self) -> List[Trade]:
11671178
"""
11681179
Function to get all closed trades. This function will return all
11691180
closed trades of the algorithm.
1170-
1181+
11711182
Returns:
11721183
List[Trade]: A list of closed trades
11731184
"""
@@ -1234,8 +1245,9 @@ def has_trading_symbol_position_available(
12341245
the position must be greater than the net_size of the
12351246
portfolio.
12361247
1237-
:param amount_gt: The amount of the position must be greater than
1238-
this amount.
1248+
Parameters:
1249+
amount_gt: The amount of the position must be greater than this
1250+
amount.
12391251
:param amount_gte: The amount of the position must be greater than
12401252
or equal to this amount.
12411253
:param percentage_of_portfolio: The amount of the position must be

investing_algorithm_framework/app/app.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def _create_backtest_database_if_not_exists(self):
283283
should be called before running a backtest for an algorithm.
284284
It creates the database if it does not exist.
285285
286-
Args:
286+
Parameters:
287287
None
288288
289289
Returns
@@ -728,9 +728,10 @@ def run_backtest(
728728
Algorithm)
729729
backtest_date_range: The date range to run the backtest for
730730
(instance of BacktestDateRange)
731-
pending_order_check_interval: str - pending_order_check_interval: The interval at which to check
732-
pending orders (e.g. 1h, 1d, 1w)
733-
output_directory: str - The directory to write the backtest report to
731+
pending_order_check_interval: str - pending_order_check_interval:
732+
The interval at which to check pending orders (e.g. 1h, 1d, 1w)
733+
output_directory: str - The directory to
734+
write the backtest report to
734735
735736
Returns:
736737
Instance of BacktestReport
@@ -776,7 +777,7 @@ def run_backtests(
776777
date_ranges: List[BacktestDateRange] = None,
777778
pending_order_check_interval=None,
778779
output_directory=None,
779-
checkpoint = False
780+
checkpoint=False
780781
) -> List[BacktestReport]:
781782
"""
782783
Run a backtest for a set algorithm. This method should be called when
@@ -788,15 +789,17 @@ def run_backtests(
788789
backtests for
789790
pending_order_check_interval: str - The interval at which to check
790791
pending orders
791-
output_directory: str - The directory to write the backtest report to.
792-
checkpoint: bool - Whether to checkpoint the backtest, If True, then it
793-
will be checked if for a given algorithm name and date range,
794-
a backtest report already exists. If it does, then the backtest will
795-
not be run again. This is useful when running backtests
796-
for a large number of algorithms and date ranges where some of the
797-
backtests may fail and you want to re-run only the failed backtests.
798-
799-
Returns
792+
output_directory: str - The directory to write the backtest
793+
report to.
794+
checkpoint: bool - Whether to checkpoint the backtest,
795+
If True, then it will be checked if for a given algorithm name
796+
and date range, a backtest report already exists. If it does,
797+
then the backtest will not be run again. This is useful
798+
when running backtests for a large number of algorithms
799+
and date ranges where some of the backtests may fail
800+
and you want to re-run only the failed backtests.
801+
802+
Returns
800803
List of BacktestReport intances
801804
"""
802805
logger.info("Initializing backtests")
@@ -822,17 +825,18 @@ def run_backtests(
822825
if checkpoint:
823826
backtest_service = self.container.backtest_service()
824827
report = backtest_service.get_report(
825-
algorithm_name=algorithm.name,
826-
backtest_date_range=date_range,
828+
algorithm_name=algorithm.name,
829+
backtest_date_range=date_range,
827830
directory=output_directory
828831
)
829832

830833
if report is not None:
831-
834+
832835
print(
833836
f"{COLOR_YELLOW}Backtest already exists "
834837
f"for algorithm {algorithm.name} date "
835-
f"range:{COLOR_RESET} {COLOR_GREEN}{date_range.name} "
838+
f"range:{COLOR_RESET} {COLOR_GREEN} "
839+
f"{date_range.name} "
836840
f"{date_range.start_date} - "
837841
f"{date_range.end_date}"
838842
)

0 commit comments

Comments
 (0)