Skip to content
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

🥚 update capitalcom.py Modify parameters SL / TP of a position. Modi… #464

Merged
merged 2 commits into from
Apr 28, 2024

Conversation

mraniki
Copy link
Owner

@mraniki mraniki commented Apr 28, 2024

…fy parameters such as SL / TP of a position that is opened. No capability to modify amount to reduce size

…y parameters such as SL / TP of a position that is opened. No capability to modify amount to reduce size
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mraniki - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 5 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

Comment on lines +378 to +379
gsl=order_params.get("trailing_stop_enabled", False),
tsl=order_params.get("trailing_stop_enabled", False),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Potential bug with trailing stop parameters.

Both 'gsl' and 'tsl' are set to the same value from 'trailing_stop_enabled'. If these should be different or configurable separately, this needs adjustment.

@@ -350,3 +350,58 @@ async def execute_order(self, order_params):
except Exception as e:
logger.error("{} Error {}", self.name, e)
return f"Error executing {self.name}: {e}"

async def modify_position(self, order_params):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_clarification): Method documentation could be more descriptive.

The method docstring should include more details about the parameters, especially what 'action' is used for, as it's included but not described.

Suggested change
async def modify_position(self, order_params):
async def modify_position(self, order_params):
"""
Modify parameters such as SL / TP of a position that is opened.
Args:
order_params (dict): A dictionary containing the parameters for the order modification.
Expected keys include 'action' which describes the type of modification to apply.
"""

logger.error(f"Error modifying order: {order['errorCode']}")
return str(order["errorCode"])

logger.debug("Order: {}", order)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code_refinement): Logger placeholder mismatch.

The logger uses '{}' as a placeholder, but this syntax requires '.format()' or should be changed to use f-string for consistency with other log statements.

@@ -266,3 +266,21 @@ async def submit_order(self, order_params):
f"{client.name}:\n{await client.execute_order(order_params)}\n"
)
return "\n".join(_order)

async def modify_position(self, order_params):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_clarification): Inconsistent method documentation.

The documentation for 'modify_position' in 'main.py' is less detailed compared to its implementation in 'capitalcom.py'. Consider enhancing it for consistency and clarity.

Suggested change
async def modify_position(self, order_params):
async def modify_position(self, order_params):
"""
Modify the parameters of an existing trading position, such as stop loss (SL) and take profit (TP) values.
Args:
order_params (dict): A dictionary containing the parameters to be modified for the position.
Returns:
dict: The result of the modification request, typically containing status and any error messages.
"""

Comment on lines +354 to +363
async def modify_position(self, order_params):
"""
Modify parameters such as SL / TP of a position that is opened
No capability to modify amount to reduce

Args:
order_params (dict):
action(str)
instrument(str)
quantity(int)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (testing): Missing tests for the new modify_position method.

The PR introduces a new method modify_position which includes several branches and error handling, but there are no unit tests provided to verify the behavior of this method under various conditions, including normal operation and error scenarios. It's crucial to ensure that this functionality is covered by tests to prevent future regressions.

Copy link

codecov bot commented Apr 28, 2024

Codecov Report

Attention: Patch coverage is 15.00000% with 17 lines in your changes are missing coverage. Please review.

Project coverage is 69.13%. Comparing base (70ea9de) to head (7a96e73).

Files Patch % Lines
cefi/handler/capitalcom.py 7.14% 13 Missing ⚠️
cefi/main.py 20.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #464      +/-   ##
==========================================
- Coverage   71.59%   69.13%   -2.47%     
==========================================
  Files           7        7              
  Lines         440      460      +20     
==========================================
+ Hits          315      318       +3     
- Misses        125      142      +17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mraniki mraniki merged commit 8f9b904 into main Apr 28, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant