from mcp.server.fastmcp import FastMCP from hype_accounts import setup, long_short_shares_mkt_price mcp = FastMCP("hype_accounts_server") @mcp.tool() async def get_account_details() -> dict: """Get cash balance, cryptocurrency holdings and PNL of hyperliquid account. """ account_details_dict = { "holdings": None, "cash_balance": None, "profit_and_loss": None } address, info, exchange = setup() user_state = info.user_state(address) account_details_dict["cash_balance"] = user_state['marginSummary']['accountValue'] if user_state['assetPositions'] == []: account_details_dict["holdings"] = "No holdings" else: account_details_dict["holdings"] = user_state['assetPositions'] account_details_dict["profit_and_loss"] = exchange.info.portfolio(address)[3][1]['pnlHistory'][-1][1] return account_details_dict @mcp.tool() async def long_perps_mkt_price(symbol: str, value:float, leverage:int) -> str: """Create a long position for a cryptocurrency perpetual contract at market price. Args: symbol: The symbol of the cryptocurrency (e.g., "HYPE","ETC","BTC","XRP"). value: The USD value to long. leverage: The leverage to use for the position. """ return str(long_short_shares_mkt_price(symbol, value, leverage, is_buy=True)) @mcp.tool() async def short_perps_mkt_price(symbol: str, value:float, leverage:int) -> str: """Create a short position for a cryptocurrency perpetual contract at market price. Args: symbol: The symbol of the cryptocurrency (e.g., "HYPE","ETC","BTC"). value: The USD value to short. leverage: The leverage to use for the position. """ return str(long_short_shares_mkt_price(symbol, value, leverage, is_buy=False)) @mcp.tool() async def close_perps_mkt_price(symbol: str) -> str: """Close the position for a cryptocurrency perpetual contract at market price. Args: symbol: The symbol of the cryptocurrency (e.g., "HYPE","ETC","BTC"). """ _, _, exchange = setup() return str(exchange.market_close(symbol)) if __name__ == "__main__": mcp.run(transport='stdio')