fix: use frontend_open_orders to return correct trigger prices#1
fix: use frontend_open_orders to return correct trigger prices#10xaaditya wants to merge 1 commit into
Conversation
Switched from open_orders to frontend_open_orders endpoint which returns full trigger metadata (triggerPx, triggerCondition, orderType) for TP/SL orders instead of stripping it out. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request updates the HyperliquidServices initialization to support API keys by allowing an explicit account_address and modifies get_open_orders to use the frontend_open_orders endpoint, providing more detailed order metadata. A critical logical flaw was identified in the new error handling logic where a failed wallet derivation is retried in the except block, which would cause an unhandled exception.
| try: | ||
| self.wallet = Account.from_key(private_key) | ||
| # If account_address wasn't provided, try to use the wallet's address | ||
| self.account_address = account_address or self.wallet.address | ||
| except Exception as e: | ||
| self.logger.warning(f"Could not derive wallet from private key (might be an API key): {e}") | ||
| self.wallet = Account.from_key(private_key) # This might still work for signing if it's a valid hex string | ||
| self.account_address = account_address |
There was a problem hiding this comment.
The try-except block is logically flawed. If Account.from_key(private_key) fails on line 53, it will be called again on line 58 with the same input, which will inevitably raise the same exception and crash the initialization. This makes the except block redundant and misleading. Furthermore, if Account.from_key fails, self.wallet is never successfully assigned, which will cause a crash later when initializing the Exchange client on line 69. If the intention is to support API keys, note that they are still valid private keys that Account.from_key can parse; the only difference is that the derived address is for the API wallet, which is why providing an explicit account_address is necessary (and already handled by the logic on line 55).
| try: | |
| self.wallet = Account.from_key(private_key) | |
| # If account_address wasn't provided, try to use the wallet's address | |
| self.account_address = account_address or self.wallet.address | |
| except Exception as e: | |
| self.logger.warning(f"Could not derive wallet from private key (might be an API key): {e}") | |
| self.wallet = Account.from_key(private_key) # This might still work for signing if it's a valid hex string | |
| self.account_address = account_address | |
| try: | |
| self.wallet = Account.from_key(private_key) | |
| # If account_address wasn't provided, try to use the wallet's address | |
| self.account_address = account_address or self.wallet.address | |
| except Exception as e: | |
| self.logger.error(f"Could not derive wallet from private key: {e}") | |
| raise |
Switched from open_orders to frontend_open_orders endpoint which returns full trigger metadata (triggerPx, triggerCondition, orderType) for TP/SL orders instead of stripping it out.