-
Notifications
You must be signed in to change notification settings - Fork 2
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
♻️ Capitalcom _fetch_account_data refactor #481
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -83,18 +83,35 @@ def _fetch_account_data(self): | |||||||||||
Returns: | ||||||||||||
None | ||||||||||||
""" | ||||||||||||
# try: | ||||||||||||
# if self.default_account: | ||||||||||||
# logger.debug("Default account: {}", self.default_account) | ||||||||||||
# self.switch_account(self.default_account) | ||||||||||||
# self.accounts_data = self.client.all_accounts() | ||||||||||||
# except Exception as e: | ||||||||||||
# logger.error("Error fetching account data: {}", e) | ||||||||||||
# return False | ||||||||||||
# logger.debug("Account data: {}", self.accounts_data) | ||||||||||||
# self.account_number = self.accounts_data["accounts"][0]["accountId"] | ||||||||||||
# logger.debug("Account number: {}", self.account_number) | ||||||||||||
# logger.debug("Session details: {}", self.client.get_sesion_details()) | ||||||||||||
try: | ||||||||||||
self.accounts_data = self.client.all_accounts() | ||||||||||||
logger.debug("Account data: {}", self.accounts_data) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚨 issue (security): Potential sensitive data logging Ensure that |
||||||||||||
if self.default_account: | ||||||||||||
logger.debug("Default account: {}", self.default_account) | ||||||||||||
self.switch_account(self.default_account) | ||||||||||||
self.accounts_data = self.client.all_accounts() | ||||||||||||
for account in self.accounts_data["accounts"]: | ||||||||||||
if account["accountId"] == self.default_account: | ||||||||||||
self.account_number = account["accountId"] | ||||||||||||
Comment on lines
+103
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (performance): Inefficient loop for finding default account Consider using a more efficient method to find the default account, such as a dictionary lookup, if possible. This will improve the performance, especially if the number of accounts is large.
Suggested change
|
||||||||||||
else: | ||||||||||||
self.account_number = self.accounts_data["accounts"][0]["accountId"] | ||||||||||||
|
||||||||||||
logger.debug("Account number: {}", self.account_number) | ||||||||||||
logger.debug("Session details: {}", self.client.get_sesion_details()) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (typo): Typo in method name There is a typo in the method name |
||||||||||||
return True | ||||||||||||
except Exception as e: | ||||||||||||
logger.error("Error fetching account data: {}", e) | ||||||||||||
return False | ||||||||||||
logger.debug("Account data: {}", self.accounts_data) | ||||||||||||
self.account_number = self.accounts_data["accounts"][0]["accountId"] | ||||||||||||
logger.debug("Account number: {}", self.account_number) | ||||||||||||
logger.debug("Session details: {}", self.client.get_sesion_details()) | ||||||||||||
|
||||||||||||
def switch_account(self, account_number): | ||||||||||||
""" | ||||||||||||
|
@@ -106,7 +123,9 @@ def switch_account(self, account_number): | |||||||||||
Returns: | ||||||||||||
None | ||||||||||||
""" | ||||||||||||
self.client.switch_account(self.default_account) | ||||||||||||
logger.debug("Switching to account {}", account_number) | ||||||||||||
switch = self.client.switch_account(self.default_account) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Incorrect variable used in switch_account The method |
||||||||||||
logger.debug("Switch: {}", switch) | ||||||||||||
|
||||||||||||
async def get_quote(self, instrument): | ||||||||||||
""" | ||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -109,6 +109,14 @@ async def test_submit_order_exception(CXTrader): | |||||||||||||||||||||||||||||||||||||
CXTrader.clients = [] | ||||||||||||||||||||||||||||||||||||||
await CXTrader.submit_order() | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
@pytest.mark.asyncio | ||||||||||||||||||||||||||||||||||||||
async def test_modify_position(CXTrader, order): | ||||||||||||||||||||||||||||||||||||||
result = await CXTrader.modify_position(order) | ||||||||||||||||||||||||||||||||||||||
print(result) | ||||||||||||||||||||||||||||||||||||||
assert result is not None | ||||||||||||||||||||||||||||||||||||||
Comment on lines
+113
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Consider adding a test for exception handling It would be useful to add a test case that simulates an exception being raised during the
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
# assert ("binance" in result) or ("huobi" in result) or ("capital" in result) | ||||||||||||||||||||||||||||||||||||||
# assert ("🔵" in result) or ("Error" in result) | ||||||||||||||||||||||||||||||||||||||
Comment on lines
+112
to
+119
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Add more assertions to cover edge cases The test
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
# @pytest.mark.asyncio | ||||||||||||||||||||||||||||||||||||||
# async def test_submit_limit_order(CXTrader, limit_order): | ||||||||||||||||||||||||||||||||||||||
|
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.
issue: Remove commented-out code
The commented-out code should be removed to keep the codebase clean and maintainable. If this code is no longer needed, it's better to delete it rather than leaving it commented out.