fix:implemented centralized freeze quantity splitting (issue #1241).#1251
fix:implemented centralized freeze quantity splitting (issue #1241).#1251iAbhi001 wants to merge 1 commit intomarketcalls:mainfrom
Conversation
There was a problem hiding this comment.
3 issues found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="services/close_position_service.py">
<violation number="1" location="services/close_position_service.py:156">
P2: Centralized close-all logic can crash on broker schema/type variations, causing whole operation to fail with 500.</violation>
<violation number="2" location="services/close_position_service.py:208">
P2: Fallback `else` branch after `if status_code == 200` is unreachable because `status_code` is always set to 200 or function returns earlier on exception.</violation>
<violation number="3" location="services/close_position_service.py:208">
P1: Split-order placement failures are swallowed and overall close-position call still returns/publishes success.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="services/close_position_service.py">
<violation number="1" location="services/close_position_service.py:162">
P1: Invalid quantity rows are silently skipped and not counted as failures, allowing false-success close responses with positions left open.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
d9a02d4 to
994e160
Compare
|
Which brokers you tested in the live market. this feature affects 30+ live brokers. |
|
I can test it now with only 1 as I don't have access to 2. |
|
avoid using trackback as we have a cetralized trackack at utils/logging.py |
|
Also remember openalgo has crypto exchanges as well. so we need to write the logic seperately for indian exchanges and crypto exchanges as they dont have the concept of freeze limit. And even for Indian Exchanges Freeze Quantity should be applied for Derviative exchanges only. |
|
I would just request you to check how my code is working for different brokers, I will check the Crypto Exchanges. |
This pull request addresses the issue identified under Reference Number 1241 where large trading positions were being rejected by brokers because they exceeded exchange freeze quantity limits. I have implemented a fix in the service layer that automatically detects when a position size is too large and splits it into smaller manageable orders before sending them to the broker.
By placing this logic in the central service layer we avoid the need to modify code for every individual broker module. The system now looks up the specific freeze limit for each symbol in our database and executes the square off in a sequential loop. I also added a small time delay between these split orders to ensure we do not hit any broker rate limits or trigger spam protections.
This update ensures that the close position feature works reliably for high volume traders across all supported brokers. I have carefully maintained all existing features including sandbox mode support and the event bus system for logging and alerts. These changes provide a stable and unified way to handle exchange restrictions without complicating the broker specific files.
Summary by cubic
Centralized freeze-quantity splitting for close-position to prevent broker rejections on large lots (issue #1241). Finalized with stricter parsing and clearer partial-error reporting.
broker_module.get_positions; derive action fromnetqty; resolve symbol fromsymboltoken/token/instrument_tokenusingdatabase.token_db.get_symbol; read limit viadatabase.qty_freeze_db.get_freeze_qty(fallback to total qty); place MARKET splits viabroker_module.place_order_apiwithreverse_map_product_type; wait 0.2s between orders.207 partial_error(else200 success); return success when no positions; publishPositionClosedEventwithsymbol/exchange/product=ALL; improved 500/403/400 responses.Written for commit 994e160. Summary will update on new commits.