feat: add fetch_recent_history_deals_for_trading_client to stable SDK (#90)
* refactor: collapse repeated tests with pytest.mark.parametrize Collapse 13 near-identical test methods into 4 parametrized tests across test_cli.py and test_sdk.py, keeping all 1045 cases passing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add fetch_recent_history_deals_for_trading_client to stable SDK Adds a generic history deal retrieval helper for active trading clients, a _HistoryDealsClientProtocol describing the minimal required interface, clarified create_trading_client() docs (returns pdmt5.Mt5DataClient, not MT5Client), 9 unit tests at 100% coverage, and updated trading.md and public-contract.md with examples and out-of-scope strategy semantics note. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: narrow Mt5CliClient protocol claim and preserve empty deal DataFrame schema - _HistoryDealsClientProtocol docstring and fetch_recent_history_deals_for_trading_client docstring now explicitly state that Mt5CliClient (mt5_session) exposes history_deals() not history_deals_get_as_df() and does not satisfy the protocol; the function is for trading-client sessions (pdmt5.Mt5DataClient) only - Empty DataFrames with columns are now passed through with reset_index rather than replaced by a bare pd.DataFrame(), preserving schema for callers that rely on stable column names even in no-deal windows - Tests updated to assert schema preservation on empty results and bare empty on None Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: add combined protocol so create_trading_client() is type-safe with history deals helper Adds _TradingHistoryDealsClientProtocol combining _Mt5ClientProtocol and _HistoryDealsClientProtocol, and updates create_trading_client() and mt5_trading_session() to return/yield this combined type so the natural SDK flow `client = create_trading_client(...); fetch_recent_history_deals_for_trading_client(client)` is type-safe under pyright strict without casts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: validate hours is finite before timedelta in fetch_recent_history_deals_for_trading_client Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Bump version to 1.1.1 --------- Co-authored-by: agent <agent@localhost> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
agent
parent
1ffac45d57
commit
513eb7617d
+15
-43
@@ -2861,57 +2861,29 @@ class TestUpdateObservability:
|
||||
)
|
||||
spy.assert_called_once()
|
||||
|
||||
def test_update_observability_skips_account_when_disabled(
|
||||
@pytest.mark.parametrize(
|
||||
("kwarg", "method"),
|
||||
[
|
||||
("include_account", "account_info_as_df"),
|
||||
("include_positions", "positions_get_as_df"),
|
||||
("include_orders", "orders_get_as_df"),
|
||||
("include_terminal", "terminal_info_as_df"),
|
||||
],
|
||||
)
|
||||
def test_update_observability_skips_when_disabled(
|
||||
self,
|
||||
mock_client: MagicMock,
|
||||
tmp_path: Path,
|
||||
kwarg: str,
|
||||
method: str,
|
||||
) -> None:
|
||||
"""include_account=False does not call account_info_as_df."""
|
||||
"""include_X=False does not call the corresponding client method."""
|
||||
update_observability(
|
||||
client=mock_client,
|
||||
output=tmp_path / "obs.db",
|
||||
include_account=False,
|
||||
**{kwarg: False}, # type: ignore[arg-type]
|
||||
)
|
||||
mock_client.account_info_as_df.assert_not_called()
|
||||
|
||||
def test_update_observability_skips_positions_when_disabled(
|
||||
self,
|
||||
mock_client: MagicMock,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""include_positions=False does not call positions_get_as_df."""
|
||||
update_observability(
|
||||
client=mock_client,
|
||||
output=tmp_path / "obs.db",
|
||||
include_positions=False,
|
||||
)
|
||||
mock_client.positions_get_as_df.assert_not_called()
|
||||
|
||||
def test_update_observability_skips_orders_when_disabled(
|
||||
self,
|
||||
mock_client: MagicMock,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""include_orders=False does not call orders_get_as_df."""
|
||||
update_observability(
|
||||
client=mock_client,
|
||||
output=tmp_path / "obs.db",
|
||||
include_orders=False,
|
||||
)
|
||||
mock_client.orders_get_as_df.assert_not_called()
|
||||
|
||||
def test_update_observability_skips_terminal_when_disabled(
|
||||
self,
|
||||
mock_client: MagicMock,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""include_terminal=False does not call terminal_info_as_df."""
|
||||
update_observability(
|
||||
client=mock_client,
|
||||
output=tmp_path / "obs.db",
|
||||
include_terminal=False,
|
||||
)
|
||||
mock_client.terminal_info_as_df.assert_not_called()
|
||||
getattr(mock_client, method).assert_not_called()
|
||||
|
||||
def test_update_observability_with_positions_rows(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user