Skip to content

Commit f880fd4

Browse files
authored
feat: v4.0.0 Phase 1 - Remove all deprecated code (#55)
Phase 1 complete: Removed all deprecated code marked for v4.0.0
1 parent 09673e4 commit f880fd4

20 files changed

+871
-1605
lines changed

examples/15_order_lifecycle_tracking.py

Lines changed: 626 additions & 354 deletions
Large diffs are not rendered by default.

scripts/check_async.py

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@ def visit_ClassDef(self, node: ast.ClassDef) -> None:
2828
# Explicitly exclude utility classes that don't need to be async
2929
excluded_classes = [
3030
"ConfigManager", # Configuration management - sync utility
31-
"ErrorContext", # Error context manager - has async context but methods can be sync
32-
"Deprecation", # Deprecation utilities
33-
"Logger", # Logging utilities
31+
"ErrorContext", # Error context manager - has async context but methods can be sync
32+
"Deprecation", # Deprecation utilities
33+
"Logger", # Logging utilities
3434
]
3535

3636
if node.name in excluded_classes:
3737
is_async_class = False
3838
else:
3939
# Check if it's a class that should be async based on patterns
4040
is_async_class = (
41-
("Manager" in node.name and node.name != "ConfigManager") # Managers except ConfigManager
41+
(
42+
"Manager" in node.name and node.name != "ConfigManager"
43+
) # Managers except ConfigManager
4244
or "Client" in node.name
4345
or "Suite" in node.name
4446
or "Realtime" in node.name
@@ -101,29 +103,64 @@ def _has_io_operations(self, node: ast.FunctionDef) -> bool:
101103

102104
# Check for known I/O objects and their methods
103105
if obj_name in ["httpx", "aiohttp", "requests", "urllib"]:
104-
if attr_name in ["get", "post", "put", "delete", "patch", "request"]:
106+
if attr_name in [
107+
"get",
108+
"post",
109+
"put",
110+
"delete",
111+
"patch",
112+
"request",
113+
]:
105114
return True
106115
elif obj_name in ["socket", "websocket", "ws"]:
107116
if attr_name in ["connect", "send", "recv", "close"]:
108117
return True
109118
elif obj_name in ["file", "f", "fp"]:
110119
if attr_name in ["read", "write", "seek", "tell"]:
111120
return True
112-
elif obj_name in ["db", "database", "conn", "connection", "cursor"]:
121+
elif obj_name in [
122+
"db",
123+
"database",
124+
"conn",
125+
"connection",
126+
"cursor",
127+
]:
113128
if attr_name in ["execute", "fetch", "commit", "rollback"]:
114129
return True
115130

116131
# Check for self.client or self.http calls (common in SDK)
117132
if isinstance(item.func.value, ast.Attribute):
118133
if hasattr(item.func.value, "attr"):
119134
obj_attr = item.func.value.attr
120-
if obj_attr in ["client", "http", "session", "api", "_client", "_http"]:
121-
if attr_name in ["get", "post", "put", "delete", "patch", "request", "fetch"]:
135+
if obj_attr in [
136+
"client",
137+
"http",
138+
"session",
139+
"api",
140+
"_client",
141+
"_http",
142+
]:
143+
if attr_name in [
144+
"get",
145+
"post",
146+
"put",
147+
"delete",
148+
"patch",
149+
"request",
150+
"fetch",
151+
]:
122152
return True
123153

124154
# Check for common async I/O patterns that should be async
125-
if attr_name in ["request", "fetch_data", "api_call", "send_request",
126-
"make_request", "http_get", "http_post"]:
155+
if attr_name in [
156+
"request",
157+
"fetch_data",
158+
"api_call",
159+
"send_request",
160+
"make_request",
161+
"http_get",
162+
"http_post",
163+
]:
127164
return True
128165

129166
elif isinstance(item.func, ast.Name):
@@ -148,7 +185,13 @@ def _is_simple_getter(self, node: ast.FunctionDef) -> bool:
148185
if isinstance(item, ast.Call):
149186
# Check if any calls might be I/O
150187
if isinstance(item.func, ast.Attribute):
151-
if item.func.attr in ["request", "fetch", "api_call", "http_get", "http_post"]:
188+
if item.func.attr in [
189+
"request",
190+
"fetch",
191+
"api_call",
192+
"http_get",
193+
"http_post",
194+
]:
152195
has_io_call = True
153196
break
154197
elif isinstance(item.func, ast.Name):

src/project_x_py/__init__.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,7 @@
180180
ScalpingTemplate,
181181
get_template,
182182
)
183-
184-
# Deprecated: These are re-exported for backward compatibility only
185-
# Use TradingSuite.track_order() and TradingSuite.order_chain() instead
186-
from project_x_py.order_tracker import (
187-
OrderChainBuilder, # Deprecated: Use TradingSuite.order_chain()
188-
OrderLifecycleError,
189-
OrderTracker, # Deprecated: Use TradingSuite.track_order()
190-
)
191-
from project_x_py.orderbook import (
192-
OrderBook,
193-
create_orderbook,
194-
)
183+
from project_x_py.orderbook import OrderBook
195184
from project_x_py.position_manager import PositionManager
196185
from project_x_py.realtime import ProjectXRealtimeClient as ProjectXRealtimeClient
197186
from project_x_py.realtime_data_manager import RealtimeDataManager
@@ -249,13 +238,10 @@
249238
"Order",
250239
# Core classes (now async-only but with original names)
251240
"OrderBook",
252-
"OrderChainBuilder",
253-
"OrderLifecycleError",
254241
"OrderManager",
255242
"OrderManagerConfig",
256243
"OrderPlaceResponse",
257244
"OrderTemplate",
258-
"OrderTracker",
259245
"OrderSide",
260246
"OrderStatus",
261247
"OrderType",
@@ -314,7 +300,6 @@
314300
"calculate_vwap",
315301
"calculate_williams_r",
316302
"create_custom_config",
317-
"create_orderbook",
318303
"get_env_var",
319304
"load_default_config",
320305
"load_topstepx_config",

src/project_x_py/client/trading.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ async def main():
7373

7474
from project_x_py.exceptions import ProjectXError
7575
from project_x_py.models import Position, Trade
76-
from project_x_py.utils.deprecation import deprecated
7776

7877
logger = logging.getLogger(__name__)
7978

@@ -99,29 +98,6 @@ async def _make_request(
9998
"""Provided by HttpMixin."""
10099
_ = (method, endpoint, data, params, headers, retry_count)
101100

102-
@deprecated(
103-
reason="Method renamed for API consistency",
104-
version="3.0.0",
105-
removal_version="4.0.0",
106-
replacement="search_open_positions()",
107-
)
108-
async def get_positions(self) -> list[Position]:
109-
"""
110-
DEPRECATED: Get all open positions for the authenticated account.
111-
112-
This method is deprecated and will be removed in a future version.
113-
Please use `search_open_positions()` instead, which provides the same
114-
functionality with a more consistent API endpoint.
115-
116-
Args:
117-
self: The client instance.
118-
119-
Returns:
120-
A list of Position objects representing current holdings.
121-
"""
122-
# Deprecation warning handled by decorator
123-
return await self.search_open_positions()
124-
125101
async def search_open_positions(
126102
self, account_id: int | None = None
127103
) -> list[Position]:

src/project_x_py/order_manager/tracking.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,11 @@ def on_order_fill(order_data):
5252
import logging
5353
import time
5454
from collections import defaultdict, deque
55-
from collections.abc import Callable, Coroutine
55+
from collections.abc import Coroutine
5656
from typing import TYPE_CHECKING, Any, cast
5757

5858
from cachetools import TTLCache
5959

60-
from project_x_py.utils.deprecation import deprecated
61-
6260
if TYPE_CHECKING:
6361
from project_x_py.event_bus import EventBus
6462
from project_x_py.types import OrderManagerProtocol
@@ -1024,24 +1022,6 @@ async def get_tracked_order_status(
10241022
order_data = self.tracked_orders.get(order_id)
10251023
return order_data if order_data is not None else None
10261024

1027-
@deprecated(
1028-
reason="Use TradingSuite.on() with EventType enum for event handling",
1029-
version="3.1.0",
1030-
removal_version="4.0.0",
1031-
replacement="TradingSuite.on(EventType.ORDER_FILLED, callback)",
1032-
)
1033-
def add_callback(
1034-
self,
1035-
_event_type: str,
1036-
_callback: Callable[[dict[str, Any]], None],
1037-
) -> None:
1038-
"""
1039-
DEPRECATED: Use TradingSuite.on() with EventType enum instead.
1040-
1041-
This method is provided for backward compatibility only and will be removed in v4.0.
1042-
"""
1043-
# Deprecation warning handled by decorator
1044-
10451025
async def _trigger_callbacks(self, event_type: str, data: Any) -> None:
10461026
"""
10471027
Trigger all callbacks registered for a specific event type.

0 commit comments

Comments
 (0)