Skip to content

Commit b22cb57

Browse files
committed
Fix flake8 warnings
1 parent d56bd12 commit b22cb57

File tree

15 files changed

+88
-70
lines changed

15 files changed

+88
-70
lines changed

investing_algorithm_framework/app/context.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,8 @@ def add_stop_loss(
10681068
Example of trailing stop loss:
10691069
* You buy BTC at $40,000.
10701070
* You set a TSL of 5%, setting the sell price at $38,000.
1071-
* BTC price increases to $42,000 → New TSL level at $39,900 (42,000 - 5%).
1071+
* BTC price increases to $42,000 → New TSL level
1072+
at $39,900 (42,000 - 5%).
10721073
* BTC price drops to $39,900 → SL level reached, trade closes.
10731074
10741075
Args:

investing_algorithm_framework/app/strategy.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,6 @@ def strategy_identifier(self):
215215

216216
return self.worker_id
217217

218-
@property
219-
def context(self):
220-
return self._context
221-
222-
@context.setter
223-
def context(self, context):
224-
self._context = context
225-
226218
def add_trace(
227219
self,
228220
symbol: str,

investing_algorithm_framework/create_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def create_app(
1212
config: dict = None,
1313
state_handler=None,
1414
web: bool = False,
15-
name = None
15+
name=None
1616
) -> App:
1717
"""
1818
Factory method to create an app instance.

investing_algorithm_framework/domain/models/trade/trade.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
TradeStatus
77
from investing_algorithm_framework.domain.models.trade.trade_stop_loss import \
88
TradeStopLoss
9-
from investing_algorithm_framework.domain.models.trade.trade_take_profit import TradeTakeProfit
9+
from investing_algorithm_framework.domain.models.trade\
10+
.trade_take_profit import TradeTakeProfit
1011

1112

1213
class Trade(BaseModel):
@@ -272,7 +273,6 @@ def is_trailing_take_profit_triggered(self):
272273

273274
return self.last_reported_price >= take_profit_price
274275

275-
276276
def to_dict(self, datetime_format=None):
277277

278278
if datetime_format is not None:

investing_algorithm_framework/domain/models/trade/trade_stop_loss.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ class TradeStopLoss(BaseModel):
1414
trailing or fixed
1515
percentage: float - the stop loss percentage
1616
sell_percentage: float - the percentage of the trade to sell when the
17-
take profit is hit. Default is 100% of the trade. If the take profit percentage is lower than 100% a check must be made that
18-
the combined sell percentage of all take profits is less or
19-
equal than 100%.
17+
take profit is hit. Default is 100% of the trade. If the
18+
take profit percentage is lower than 100% a check must
19+
be made that the combined sell percentage of all
20+
take profits is less or equal than 100%.
2021
sell_amount: float - the amount to sell when the stop loss triggers
2122
sold_amount: float - the amount that has been sold
2223
high_water_mark: float - the highest price of the trade
@@ -30,7 +31,8 @@ class TradeStopLoss(BaseModel):
3031
But if the price keeps falling to $95, the stop loss triggers,
3132
and you exit with a $5 loss.
3233
33-
if trade_risk_type is trailing, the stop loss price is calculated as follows:
34+
if trade_risk_type is trailing, the stop loss price is
35+
calculated as follows:
3436
You buy a stock at $100.
3537
You set a 5% trailing stop loss, meaning you will sell if
3638
the price drops 5% from its peak at $96
@@ -70,10 +72,12 @@ def __init__(
7072

7173
def update_with_last_reported_price(self, current_price: float):
7274
"""
73-
Function to update the take profit price based on the last reported price.
74-
The take profit price is only updated when the trade risk type is trailing.
75-
The take profit price is updated based on the current price and the percentage
76-
of the take profit.
75+
Function to update the take profit price based on the last
76+
reported price.
77+
The take profit price is only updated when the trade risk
78+
type is trailing.
79+
The take profit price is updated based on the current price
80+
and the percentage of the take profit.
7781
7882
Args:
7983
current_price: float - the last reported price of the trade

investing_algorithm_framework/domain/models/trade/trade_take_profit.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ class TradeTakeProfit(BaseModel):
1414
trailing or fixed
1515
percentage: float - the take profit percentage
1616
sell_percentage: float - the percentage of the trade to sell when the
17-
take profit is hit. Default is 100% of the trade. If the take profit percentage is lower than 100% a check must be made that
18-
the combined sell percentage of all take profits is less or
19-
equal than 100%.
17+
take profit is hit. Default is 100% of the trade.
18+
If the take profit percentage is lower than 100% a check
19+
must be made that the combined sell percentage of
20+
all take profits is less or equal than 100%.
2021
21-
if trade_risk_type is fixed, the take profit price is calculated as follows:
22+
if trade_risk_type is fixed, the take profit price is
23+
calculated as follows:
2224
You buy a stock at $100.
2325
You set a 5% take profit, meaning you will sell if the price
2426
rises to $105.
@@ -27,18 +29,21 @@ class TradeTakeProfit(BaseModel):
2729
But if the price keeps falling below $105, the take profit is not
2830
triggered.
2931
30-
if trade_risk_type is trailing, the take profit price is calculated as follows:
32+
if trade_risk_type is trailing, the take profit price is
33+
calculated as follows:
3134
You buy a stock at $100.
3235
You set a 5% trailing take profit, the moment the price rises
3336
5% the initial take profit mark will be set. This means you
3437
will set the take_profit_price initially at none and
3538
only if the price hits $105, you will set the
3639
take_profit_price to $105.
3740
if the price drops below $105, the take profit is triggered.
38-
If the price rises to $120, the take profit adjusts to $114 (5% below $120).
39-
If the price falls to $114, the position is closed, securing a $14 profit.
40-
But if the price keeps rising to $150, the take profit moves up to $142.50.
41-
41+
If the price rises to $120, the take profit adjusts to
42+
$114 (5% below $120).
43+
If the price falls to $114, the position is closed,
44+
securing a $14 profit.
45+
But if the price keeps rising to $150, the take profit
46+
moves up to $142.50.
4247
"""
4348

4449
def __init__(
@@ -67,10 +72,12 @@ def __init__(
6772

6873
def update_with_last_reported_price(self, current_price: float):
6974
"""
70-
Function to update the take profit price based on the last reported price.
71-
The take profit price is only updated when the trade risk type is trailing.
72-
The take profit price is updated based on the current price and the percentage
73-
of the take profit.
75+
Function to update the take profit price based on
76+
the last reported price.
77+
The take profit price is only updated when the
78+
trade risk type is trailing.
79+
The take profit price is updated based on the
80+
current price and the percentage of the take profit.
7481
7582
Args:
7683
current_price: float - the last reported price of the trade
@@ -110,7 +117,7 @@ def update_with_last_reported_price(self, current_price: float):
110117

111118
return
112119

113-
def has_triggered(self, current_price: float=None) -> bool:
120+
def has_triggered(self, current_price: float = None) -> bool:
114121

115122
if TradeRiskType.FIXED.equals(self.trade_risk_type):
116123
# Check if the current price is less than the high water mark

investing_algorithm_framework/infrastructure/models/market_data_sources/ccxt.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ def _precompute_sliding_windows(self):
165165
def load_data(self):
166166
file_path = self._create_file_path()
167167
self.data = polars.read_csv(
168-
file_path, schema_overrides={"Datetime": polars.Datetime}, low_memory=True
168+
file_path,
169+
schema_overrides={"Datetime": polars.Datetime},
170+
low_memory=True
169171
) # Faster parsing
170172
first_row = self.data.head(1)
171173
last_row = self.data.tail(1)

investing_algorithm_framework/infrastructure/models/market_data_sources/csv.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ def csv_file_path(self):
6666

6767
def _load_data(self, file_path):
6868
return polars.read_csv(
69-
file_path, schema_overrides={"Datetime": polars.Datetime}, low_memory=True
69+
file_path,
70+
schema_overrides={"Datetime": polars.Datetime},
71+
low_memory=True
7072
).with_columns(
7173
polars.col("Datetime").cast(
7274
polars.Datetime(time_unit="ms", time_zone="UTC")

investing_algorithm_framework/infrastructure/models/order/order_metadata.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ class SQLOrderMetadata(SQLBaseModel, SQLAlchemyModelExtension):
2121
amount = Column(Float)
2222
amount_pending = Column(Float)
2323

24-
2524
def __init__(
2625
self,
2726
order_id,
2827
amount,
2928
amount_pending,
30-
trade_id = None,
31-
stop_loss_id = None,
32-
take_profit_id = None,
29+
trade_id=None,
30+
stop_loss_id=None,
31+
take_profit_id=None,
3332
):
3433
self.order_id = order_id
3534
self.trade_id = trade_id

investing_algorithm_framework/infrastructure/models/trades/trade.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from sqlalchemy import Column, Integer, String, DateTime, Float, Boolean
1+
from sqlalchemy import Column, Integer, String, DateTime, Float
22
from sqlalchemy.orm import relationship
33

44
from investing_algorithm_framework.domain import Trade, TradeStatus

0 commit comments

Comments
 (0)