-
Notifications
You must be signed in to change notification settings - Fork 66
Fix check_win: Map server deal IDs to client request IDs #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Comment |
Co-authored-by: theshadow76 <59869868+theshadow76@users.noreply.github.com>
Co-authored-by: theshadow76 <59869868+theshadow76@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a critical bug in the check_win functionality where completed orders were never found because the server uses its own deal IDs in completion messages while orders were stored under client-generated request IDs. The fix introduces a mapping mechanism to translate between server IDs and client request IDs.
- Adds a bidirectional mapping system to correlate server-assigned deal IDs with client request IDs
- Updates the deal processing logic to use the mapping for order lookups
- Includes comprehensive test coverage for the mapping functionality
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| pocketoptionapi_async/client.py | Adds _server_id_to_request_id mapping dict, updates order confirmation to store mappings, modifies deal completion to lookup via mapping, and cleans up mappings after use |
| tests/test_check_win.py | New comprehensive test file validating the ID mapping fix with win/loss scenarios and backward compatibility |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if server_id: # Ensure string is not empty | ||
| self._server_id_to_request_id[server_id] = request_id | ||
| if self.enable_logging: | ||
| logger.debug(f"Mapped server ID {server_id} to request ID {request_id}") |
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant check: server_id is guaranteed to be non-empty at this point. Line 1040 already checks data['id'] is truthy before converting to string on line 1041. An empty string input would have failed the line 1040 check. This redundant check on line 1042 adds unnecessary complexity.
| if server_id: # Ensure string is not empty | |
| self._server_id_to_request_id[server_id] = request_id | |
| if self.enable_logging: | |
| logger.debug(f"Mapped server ID {server_id} to request ID {request_id}") | |
| self._server_id_to_request_id[server_id] = request_id | |
| if self.enable_logging: | |
| logger.debug(f"Mapped server ID {server_id} to request ID {request_id}") |
| all_passed = await test_check_win_id_mapping() and all_passed | ||
| except Exception as e: | ||
| print(f"❌ FAIL: test_check_win_id_mapping - {e}") | ||
| all_passed = False | ||
|
|
||
| try: | ||
| all_passed = await test_check_win_loss_scenario() and all_passed | ||
| except Exception as e: | ||
| print(f"❌ FAIL: test_check_win_loss_scenario - {e}") | ||
| all_passed = False | ||
|
|
||
| try: | ||
| all_passed = await test_check_win_fallback_without_mapping() and all_passed |
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect short-circuit evaluation order. The current order await test() and all_passed will skip tests if all_passed is already False due to short-circuiting. The tests should run first and then AND with all_passed. Change to all_passed = all_passed and await test() to ensure all tests execute.
| all_passed = await test_check_win_id_mapping() and all_passed | |
| except Exception as e: | |
| print(f"❌ FAIL: test_check_win_id_mapping - {e}") | |
| all_passed = False | |
| try: | |
| all_passed = await test_check_win_loss_scenario() and all_passed | |
| except Exception as e: | |
| print(f"❌ FAIL: test_check_win_loss_scenario - {e}") | |
| all_passed = False | |
| try: | |
| all_passed = await test_check_win_fallback_without_mapping() and all_passed | |
| all_passed = all_passed and await test_check_win_id_mapping() | |
| except Exception as e: | |
| print(f"❌ FAIL: test_check_win_id_mapping - {e}") | |
| all_passed = False | |
| try: | |
| all_passed = all_passed and await test_check_win_loss_scenario() | |
| except Exception as e: | |
| print(f"❌ FAIL: test_check_win_loss_scenario - {e}") | |
| all_passed = False | |
| try: | |
| all_passed = all_passed and await test_check_win_fallback_without_mapping() |
| all_passed = await test_check_win_id_mapping() and all_passed | ||
| except Exception as e: | ||
| print(f"❌ FAIL: test_check_win_id_mapping - {e}") | ||
| all_passed = False | ||
|
|
||
| try: | ||
| all_passed = await test_check_win_loss_scenario() and all_passed | ||
| except Exception as e: | ||
| print(f"❌ FAIL: test_check_win_loss_scenario - {e}") | ||
| all_passed = False | ||
|
|
||
| try: | ||
| all_passed = await test_check_win_fallback_without_mapping() and all_passed |
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect short-circuit evaluation order. The current order await test() and all_passed will skip tests if all_passed is already False due to short-circuiting. The tests should run first and then AND with all_passed. Change to all_passed = all_passed and await test() to ensure all tests execute.
| all_passed = await test_check_win_id_mapping() and all_passed | |
| except Exception as e: | |
| print(f"❌ FAIL: test_check_win_id_mapping - {e}") | |
| all_passed = False | |
| try: | |
| all_passed = await test_check_win_loss_scenario() and all_passed | |
| except Exception as e: | |
| print(f"❌ FAIL: test_check_win_loss_scenario - {e}") | |
| all_passed = False | |
| try: | |
| all_passed = await test_check_win_fallback_without_mapping() and all_passed | |
| all_passed = all_passed and await test_check_win_id_mapping() | |
| except Exception as e: | |
| print(f"❌ FAIL: test_check_win_id_mapping - {e}") | |
| all_passed = False | |
| try: | |
| all_passed = all_passed and await test_check_win_loss_scenario() | |
| except Exception as e: | |
| print(f"❌ FAIL: test_check_win_loss_scenario - {e}") | |
| all_passed = False | |
| try: | |
| all_passed = all_passed and await test_check_win_fallback_without_mapping() |
| all_passed = await test_check_win_id_mapping() and all_passed | ||
| except Exception as e: | ||
| print(f"❌ FAIL: test_check_win_id_mapping - {e}") | ||
| all_passed = False | ||
|
|
||
| try: | ||
| all_passed = await test_check_win_loss_scenario() and all_passed | ||
| except Exception as e: | ||
| print(f"❌ FAIL: test_check_win_loss_scenario - {e}") | ||
| all_passed = False | ||
|
|
||
| try: | ||
| all_passed = await test_check_win_fallback_without_mapping() and all_passed |
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect short-circuit evaluation order. The current order await test() and all_passed will skip tests if all_passed is already False due to short-circuiting. The tests should run first and then AND with all_passed. Change to all_passed = all_passed and await test() to ensure all tests execute.
| all_passed = await test_check_win_id_mapping() and all_passed | |
| except Exception as e: | |
| print(f"❌ FAIL: test_check_win_id_mapping - {e}") | |
| all_passed = False | |
| try: | |
| all_passed = await test_check_win_loss_scenario() and all_passed | |
| except Exception as e: | |
| print(f"❌ FAIL: test_check_win_loss_scenario - {e}") | |
| all_passed = False | |
| try: | |
| all_passed = await test_check_win_fallback_without_mapping() and all_passed | |
| all_passed = all_passed and await test_check_win_id_mapping() | |
| except Exception as e: | |
| print(f"❌ FAIL: test_check_win_id_mapping - {e}") | |
| all_passed = False | |
| try: | |
| all_passed = all_passed and await test_check_win_loss_scenario() | |
| except Exception as e: | |
| print(f"❌ FAIL: test_check_win_loss_scenario - {e}") | |
| all_passed = False | |
| try: | |
| all_passed = all_passed and await test_check_win_fallback_without_mapping() |
| # If we have a mapping, use request_id to find the order | ||
| # Otherwise, fall back to trying server_deal_id directly |
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The comment on line 1086-1087 could be clearer. Consider: 'Use mapped request_id if available; otherwise fall back to server_deal_id for backward compatibility' to explicitly mention backward compatibility, which is the key design decision here.
| # If we have a mapping, use request_id to find the order | |
| # Otherwise, fall back to trying server_deal_id directly | |
| # Use mapped request_id if available; otherwise fall back to server_deal_id for backward compatibility |
check_winnever finds completed orders because the server uses its own dealidin completion messages, while orders are stored under the client-generatedrequestId.Changes
_server_id_to_request_idmapping dict — Captures server ID → request ID relationship when order confirmation arrives with both fieldsrequestIdvia mapping before searching_active_ordersrequestId— Ensurescheck_winandcheck_order_resultfind completed ordersFlow Before
Flow After
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.