Skip to content
This repository was archived by the owner on Apr 26, 2026. It is now read-only.

Commit 2829a81

Browse files
Copilottheshadow76
andcommitted
Address code review feedback: improve boolean comparison and null checks
Co-authored-by: theshadow76 <59869868+theshadow76@users.noreply.github.com>
1 parent 420e90a commit 2829a81

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

pocketoptionapi_async/client.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,12 +1036,13 @@ async def _on_json_data(self, data: Dict[str, Any]) -> None:
10361036
if "requestId" in data and "asset" in data and "amount" in data:
10371037
request_id = str(data["requestId"])
10381038

1039-
# Store mapping from server ID to request ID if server ID is present
1040-
if "id" in data:
1039+
# Store mapping from server ID to request ID if server ID is present and valid
1040+
if "id" in data and data["id"]:
10411041
server_id = str(data["id"])
1042-
self._server_id_to_request_id[server_id] = request_id
1043-
if self.enable_logging:
1044-
logger.debug(f"Mapped server ID {server_id} to request ID {request_id}")
1042+
if server_id: # Ensure string is not empty
1043+
self._server_id_to_request_id[server_id] = request_id
1044+
if self.enable_logging:
1045+
logger.debug(f"Mapped server ID {server_id} to request ID {request_id}")
10451046

10461047
# If this is a new order, add it to tracking
10471048
if (
@@ -1084,7 +1085,7 @@ async def _on_json_data(self, data: Dict[str, Any]) -> None:
10841085

10851086
# If we have a mapping, use request_id to find the order
10861087
# Otherwise, fall back to trying server_deal_id directly
1087-
lookup_id = request_id if request_id else server_deal_id
1088+
lookup_id = request_id or server_deal_id
10881089

10891090
if lookup_id in self._active_orders:
10901091
active_order = self._active_orders[lookup_id]

tests/test_check_win.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ async def test_check_win_id_mapping():
9191
check_result = await client.check_win(client_request_id, max_wait_time=1.0)
9292

9393
assert check_result is not None, "check_win should return a result"
94-
assert check_result["completed"] == True, "Order should be completed"
94+
assert check_result["completed"], "Order should be completed"
9595
assert check_result["result"] == "win", f"Result should be 'win', got {check_result['result']}"
9696
assert check_result["profit"] == 8.5, f"Profit should be 8.5, got {check_result['profit']}"
9797
print(f" ✅ PASS: check_win returned correct result: {check_result}")

0 commit comments

Comments
 (0)