Skip to content

fix: use frontend_open_orders to return correct trigger prices#1

Open
0xaaditya wants to merge 1 commit into
mainfrom
fix/order-trigger-price
Open

fix: use frontend_open_orders to return correct trigger prices#1
0xaaditya wants to merge 1 commit into
mainfrom
fix/order-trigger-price

Conversation

@0xaaditya

Copy link
Copy Markdown
Contributor

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.

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>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment on lines +52 to +59
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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).

Suggested change
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

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