Skip to content

Commit 0e903a1

Browse files
committed
fix: 增强输入验证以捕获 ValueError,更新 Hyperliquid API URL 逻辑
1 parent 7e549a4 commit 0e903a1

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ async def set_take_profit_stop_loss(
455455
sl_px=stop_loss_price,
456456
position_size=position_size
457457
)
458-
except ValidationError as e:
458+
except (ValidationError, ValueError) as e:
459459
return {
460460
"success": False,
461461
"error": f"Invalid input: {str(e)}",
@@ -709,4 +709,4 @@ def stdio_server():
709709
print("\n3. Or create a .env file:")
710710
print(" HYPERLIQUID_PRIVATE_KEY=your_private_key")
711711
print(" HYPERLIQUID_TESTNET=false")
712-
print(" HYPERLIQUID_ACCOUNT_ADDRESS=your_address")
712+
print(" HYPERLIQUID_ACCOUNT_ADDRESS=your_address")

services/hyperliquid_services.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from hyperliquid.info import Info
66
from hyperliquid.exchange import Exchange
7-
from hyperliquid.utils import constants
7+
from hyperliquid.utils import constants as hl_constants
88
from hyperliquid.utils.types import Cloid
99
from hyperliquid.utils.signing import (
1010
order_request_to_order_wire,
@@ -47,10 +47,10 @@ def __init__(self, private_key: str, testnet: bool = False, account_address: str
4747
self.logger.setLevel(logging.INFO)
4848

4949
# Set up API URLs
50-
if testnet:
51-
self.base_url = "https://api.hyperliquid.xyz"
52-
else:
53-
self.base_url = "https://api.hyperliquid.xyz"
50+
mainnet_url = getattr(hl_constants, "MAINNET_API_URL", "https://api.hyperliquid.xyz")
51+
testnet_url = getattr(hl_constants, "TESTNET_API_URL", "https://api.hyperliquid.xyz")
52+
self.base_url = testnet_url if testnet else mainnet_url
53+
self.is_mainnet = not testnet
5454

5555
# Initialize account address and wallet
5656
from eth_account import Account
@@ -111,7 +111,7 @@ def _bulk_orders_with_grouping(self, order_requests, grouping="na", builder=None
111111
self.exchange.vault_address,
112112
timestamp,
113113
expires_after,
114-
self.exchange.base_url == constants.MAINNET_API_URL
114+
self.is_mainnet
115115
)
116116

117117
# Post the action

0 commit comments

Comments
 (0)