Skip to content

Commit

Permalink
Fix formatting with new version of black.
Browse files Browse the repository at this point in the history
  • Loading branch information
edtechre committed Mar 17, 2024
1 parent d6035f5 commit 42e306f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
9 changes: 6 additions & 3 deletions src/pybroker/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class Position:
chronological order.
bars: Current number of bars since entry.
"""

symbol: str
shares: Decimal
type: Literal["long", "short"]
Expand Down Expand Up @@ -1104,9 +1105,11 @@ def _trigger_bar_stop(
if entry.bars >= stop.bars:
return price_scope.fetch(
stop.symbol,
PriceType.MIDDLE
if stop.fill_price is None
else stop.fill_price,
(
PriceType.MIDDLE
if stop.fill_price is None
else stop.fill_price
),
)
return None

Expand Down
20 changes: 11 additions & 9 deletions src/pybroker/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,9 @@ def _set_pos_sizes(
if id < len(buy_results):
buy_results[id].buy_shares = to_decimal(shares)
else:
sell_results[
id - len(buy_results)
].sell_shares = to_decimal(shares)
sell_results[id - len(buy_results)].sell_shares = (
to_decimal(shares)
)
elif buy_results is not None:
if id >= len(buy_results):
raise ValueError(f"Invalid ExecSignal id: {id}")
Expand Down Expand Up @@ -837,9 +837,9 @@ def __init__(
self._after_exec_fn: Optional[
Callable[[Mapping[str, ExecContext]], None]
] = None
self._pos_size_handler: Optional[
Callable[[PosSizeContext], None]
] = None
self._pos_size_handler: Optional[Callable[[PosSizeContext], None]] = (
None
)
self._slippage_model: Optional[SlippageModel] = None
self._scope = StaticScope.instance()
self._logger = self._scope.logger
Expand Down Expand Up @@ -1271,9 +1271,11 @@ def _to_day_ids(
)
return tuple(
sorted(
day.value
if isinstance(day, Day)
else Day[day.upper()].value # type: ignore[union-attr]
(
day.value
if isinstance(day, Day)
else Day[day.upper()].value
) # type: ignore[union-attr]
for day in set(days) # type: ignore[arg-type]
)
) # type: ignore[return-value]
Expand Down
12 changes: 5 additions & 7 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,11 @@ def test_enable_and_disable_all_caches(scope, cache_dir, cache_path):
@pytest.mark.usefixtures("setup_teardown")
def test_clear_all_caches(scope, cache_dir):
enable_caches("test", cache_dir)
with mock.patch.object(
scope, "data_source_cache"
) as data_source_cache, mock.patch.object(
scope, "indicator_cache"
) as ind_cache, mock.patch.object(
scope, "model_cache"
) as model_cache:
with (
mock.patch.object(scope, "data_source_cache") as data_source_cache,
mock.patch.object(scope, "indicator_cache") as ind_cache,
mock.patch.object(scope, "model_cache") as model_cache,
):
clear_caches()
data_source_cache.clear.assert_called_once()
ind_cache.clear.assert_called_once()
Expand Down
7 changes: 4 additions & 3 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ def symbols(alpaca_df):

@pytest.fixture()
def mock_cache(scope):
with mock.patch.object(
scope, "data_source_cache"
) as cache, mock.patch.object(cache, "get", return_value=None):
with (
mock.patch.object(scope, "data_source_cache") as cache,
mock.patch.object(cache, "get", return_value=None),
):
yield cache


Expand Down

0 comments on commit 42e306f

Please sign in to comment.