### Spot Quickstart Example Source: https://github.com/jkorf/hyperliquid.net/blob/main/llms.txt Demonstrates basic client setup, fetching prices, spot ticker metadata, authenticated balances, and a spot order pattern. Ensure proper client initialization before use. ```csharp using HyperLiquid.Net; using HyperLiquid.Net.Clients.Spot; using HyperLiquid.Net.Objects.Requests; // Initialize client var client = new HyperLiquidRestClient(); // Get prices var prices = await client.SpotApi.GetPricesAsync(); // Get spot ticker metadata var ticker = await client.SpotApi.GetSpotTickerAsync("HYPE/USDC"); // Get authenticated balances var balances = await client.SpotApi.GetBalancesAsync(); // Place a spot order var orderResult = await client.SpotApi.PlaceOrderAsync(new PlaceOrderRequest { Symbol = "HYPE/USDC", OrderType = SpotOrderType.Limit, Side = OrderSide.Buy, Quantity = 10, Price = 0.5 }); ``` -------------------------------- ### Setup Console Project with HyperLiquid.Net Source: https://github.com/jkorf/hyperliquid.net/blob/main/Examples/ai-friendly/README.md Instructions for creating a new .NET console project and adding the HyperLiquid.Net package. ```bash dotnet new console -n HyperLiquidExample cd HyperLiquidExample dotnet add package HyperLiquid.Net ``` ```bash dotnet run ``` -------------------------------- ### Setup HyperLiquid Socket Client (with Credentials) Source: https://github.com/jkorf/hyperliquid.net/blob/main/llms-full.txt Instantiate a HyperLiquidSocketClient and provide API credentials for authenticated WebSocket connections. ```csharp var socketClient = new HyperLiquidSocketClient(options => { options.ApiCredentials = new HyperLiquidCredentials("PUBLIC_ADDRESS", "PRIVATE_KEY"); }); ``` -------------------------------- ### Setup HyperLiquid REST Client (Public Data) Source: https://github.com/jkorf/hyperliquid.net/blob/main/llms-full.txt Instantiate a HyperLiquidRestClient for accessing public market data. No credentials are required for this. ```csharp var client = new HyperLiquidRestClient(); var prices = await client.SpotApi.ExchangeData.GetPricesAsync(); if (!prices.Success) { Console.WriteLine(prices.Error); return; } Console.WriteLine(prices.Data["HYPE/USDC"]); ``` -------------------------------- ### Setup HyperLiquid REST Client (Private Data) Source: https://github.com/jkorf/hyperliquid.net/blob/main/llms-full.txt Configure the HyperLiquidRestClient with API credentials for accessing private account and trading endpoints. ```csharp var client = new HyperLiquidRestClient(options => { options.ApiCredentials = new HyperLiquidCredentials("PUBLIC_ADDRESS", "PRIVATE_KEY"); }); ``` -------------------------------- ### Get Spot Balances Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Retrieve the current balances for all assets in your spot account. ```csharp client.SpotApi.Account.GetBalancesAsync() ``` -------------------------------- ### Get Fee Information Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Fetch current fee information applicable to your account. ```csharp client.SpotApi.Account.GetFeeInfoAsync() ``` -------------------------------- ### Get Spot Exchange Information Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Fetch general information about the spot exchange. ```csharp client.SpotApi.ExchangeData.GetExchangeInfoAsync() ``` -------------------------------- ### Get User Trades by Time Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Fetch user trades within a specified start and end time range. ```csharp client.SpotApi.Trading.GetUserTradesByTimeAsync(start, end) ``` -------------------------------- ### Get Staking Summary Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Obtain a summary of your staking activities, including total staked amount and rewards. ```csharp client.SpotApi.Account.GetStakingSummaryAsync() ``` -------------------------------- ### Get Staking Delegations Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md View the current staking delegations associated with your account. ```csharp client.SpotApi.Account.GetStakingDelegationsAsync() ``` -------------------------------- ### Dependency Injection Setup for HyperLiquid Source: https://github.com/jkorf/hyperliquid.net/blob/main/llms-full.txt Configure the service collection to use HyperLiquid clients via dependency injection, including optional API credentials. ```csharp services.AddHyperLiquid(options => { options.ApiCredentials = new HyperLiquidCredentials("PUBLIC_ADDRESS", "PRIVATE_KEY"); }); ``` -------------------------------- ### Get Approved Builder Fee Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Retrieve the currently approved builder fee percentage for your account. ```csharp client.SpotApi.Account.GetApprovedBuilderFeeAsync() ``` -------------------------------- ### Place a Spot Limit Buy Order in C# Source: https://github.com/jkorf/hyperliquid.net/blob/main/llms-full.txt Example of placing a limit buy order for a specific symbol on the spot market. Ensure you have initialized the HyperLiquidRestClient with valid API credentials. ```csharp using HyperLiquid.Net; using HyperLiquid.Net.Clients; using HyperLiquid.Net.Enums; var client = new HyperLiquidRestClient(options => { options.ApiCredentials = new HyperLiquidCredentials("PUBLIC_ADDRESS", "PRIVATE_KEY"); }); var order = await client.SpotApi.Trading.PlaceOrderAsync( symbol: "HYPE/USDC", side: OrderSide.Buy, orderType: OrderType.Limit, quantity: 1m, price: 20m, timeInForce: TimeInForce.GoodTillCanceled); if (!order.Success) { Console.WriteLine(order.Error); return; } Console.WriteLine(order.Data.OrderId); ``` -------------------------------- ### Get Order History Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Fetch the complete history of all orders placed by the user. ```csharp client.SpotApi.Trading.GetOrderHistoryAsync() ``` -------------------------------- ### Get Open Orders Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Retrieve a list of all currently open orders for spot and futures markets. ```csharp client.SpotApi.Trading.GetOpenOrdersAsync() ``` -------------------------------- ### WebSocket Streams Example Source: https://github.com/jkorf/hyperliquid.net/blob/main/llms.txt Demonstrates subscribing to various WebSocket streams including spot tickers, futures tickers, order books, and authenticated order updates. Proper teardown by unsubscribing is crucial. ```csharp using HyperLiquid.Net; using HyperLiquid.Net.Clients.WebSocket; // Initialize client var socketClient = new HyperLiquidSocketClient(); // Subscribe to spot ticker stream var spotTickerSubscription = await socketClient.SubscribeToSpotTickerStreamAsync("HYPE/USDC", data => { Console.WriteLine($"Spot Ticker Update: {data.LastPrice}"); }); // Subscribe to futures ticker stream var futuresTickerSubscription = await socketClient.SubscribeToFuturesTickerStreamAsync("ETH", data => { Console.WriteLine($"Futures Ticker Update: {data.LastPrice}"); }); // Subscribe to order book stream var orderBookSubscription = await socketClient.SubscribeToOrderBookStreamAsync("HYPE/USDC", data => { Console.WriteLine($"Order Book Update: {data.Bids.Count} bids, {data.Asks.Count} asks"); }); // Subscribe to authenticated orders stream var authenticatedOrdersSubscription = await socketClient.SubscribeToAuthenticatedOrdersStreamAsync(data => { Console.WriteLine($"Authenticated Order Update: {data.OrderId}"); }); // Unsubscribe on shutdown // spotTickerSubscription.Dispose(); // futuresTickerSubscription.Dispose(); // orderBookSubscription.Dispose(); // authenticatedOrdersSubscription.Dispose(); ``` -------------------------------- ### Get All Mid Prices (Spot) Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Retrieve the current mid-price for all available spot trading pairs. ```csharp client.SpotApi.ExchangeData.GetPricesAsync() ``` -------------------------------- ### Install HyperLiquid.Net Package Source: https://github.com/jkorf/hyperliquid.net/blob/main/AGENTS.md Use the dotnet CLI to add the HyperLiquid.Net package to your project. This package supports multiple .NET target frameworks and Native AOT. ```bash dotnet add package HyperLiquid.Net ``` -------------------------------- ### Futures Trading Example Source: https://github.com/jkorf/hyperliquid.net/blob/main/llms.txt Covers perpetual futures metadata, setting leverage, retrieving futures account positions, and placing market or reduce-only orders. Use `reduceOnly: true` for closing exposure. ```csharp using HyperLiquid.Net; using HyperLiquid.Net.Clients.Futures; using HyperLiquid.Net.Objects.Requests; // Initialize client var client = new HyperLiquidRestClient(); // Get perp metadata var perpMetadata = await client.FuturesApi.GetPerpetualMarketMetadataAsync(); // Set leverage await client.FuturesApi.SetLeverageAsync("ETH", 10); // Get futures account positions var positions = await client.FuturesApi.GetAccountPositionsAsync(); // Place a market order (reduce only) var orderResult = await client.FuturesApi.PlaceOrderAsync(new PlaceOrderRequest { Symbol = "ETH", OrderType = FuturesOrderType.Market, Side = OrderSide.Sell, Quantity = 0.1, ReduceOnly = true }); ``` -------------------------------- ### Subscribe to All Mids Source: https://github.com/jkorf/hyperliquid.net/blob/main/HyperLiquid.Net.UnitTests/Subscriptions/Prices.txt Send a subscription request for all price midpoints. This is a common starting point for market data. ```json {"subscription":{"type":"allMids"},"method":"subscribe"} ``` -------------------------------- ### Place a Spot Order Source: https://github.com/jkorf/hyperliquid.net/blob/main/AGENTS.md Use the PlaceOrderAsync method to submit spot orders. Specify the symbol, side, order type, quantity, and price. TimeInForce.GoodTillCanceled is used in this example. ```csharp using HyperLiquid.Net.Enums; var order = await restClient.SpotApi.Trading.PlaceOrderAsync( symbol: "HYPE/USDC", side: OrderSide.Buy, orderType: OrderType.Limit, quantity: 1m, price: 20m, timeInForce: TimeInForce.GoodTillCanceled); if (!order.Success) { Console.WriteLine(order.Error); return; } Console.WriteLine(order.Data.OrderId); ``` -------------------------------- ### Get Extended Open Orders Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Fetch a more detailed list of open orders, potentially including additional information. ```csharp client.SpotApi.Trading.GetOpenOrdersExtendedAsync() ``` -------------------------------- ### Get Spot Asset Information Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Fetch specific information for a given asset on the spot market. Requires an asset ID. ```csharp client.SpotApi.ExchangeData.GetAssetInfoAsync(assetId) ``` -------------------------------- ### Get Spot and Futures Ticker Info Source: https://github.com/jkorf/hyperliquid.net/blob/main/README.md Retrieve exchange information and ticker data for both spot and futures markets using the HyperLiquidRestClient. ```csharp var restClient = new HyperLiquidRestClient(); // Spot HYPE/USDC info var spotTickerResult = await restClient.SpotApi.ExchangeData.GetExchangeInfoAndTickersAsync(); var hypeInfo = spotTickerResult.Data.Tickers.Single(x => x.Symbol == "HYPE/USDC"); var currentHypePrice = hypeInfo.MidPrice; // Futures ETH perpetual contract info var futuresTickerResult = await restClient.FuturesApi.ExchangeData.GetExchangeInfoAndTickersAsync(); var ethInfo = futuresTickerResult.Data.Tickers.Single(x => x.Symbol == "ETH"); var currentEthPrice = ethInfo.MidPrice; ``` -------------------------------- ### Error Handling Example Source: https://github.com/jkorf/hyperliquid.net/blob/main/llms.txt Illustrates handling `WebCallResult` and `CallResult` patterns, implementing retry logic, correct symbol formatting, and performing builder fee checks. Always check `.Success` before accessing `.Data`. ```csharp using HyperLiquid.Net; using HyperLiquid.Net.Clients.Spot; using CryptoExchange.Net.Objects; // Initialize client var client = new HyperLiquidRestClient(); // Example of fetching data with error handling WebCallResult> result = await client.SpotApi.GetSpotTickersAsync(); if (result.Success) { // Process data foreach (var ticker in result.Data) { Console.WriteLine($"Symbol: {ticker.Symbol}, Price: {ticker.LastPrice}"); } } else { // Handle error Console.WriteLine($"Error fetching spot tickers: {result.Error?.Message}"); // Implement retry logic if necessary } // Symbol formatting example string formattedSymbol = Symbol.FormatSymbol("HYPE", "USDC"); // "HYPE/USDC" // Builder fee checks (conceptual) // var feeResult = await client.SpotApi.GetFeeRatesAsync(); // if (feeResult.Success) // { // var makerFee = feeResult.Data.MakerFee; // Console.WriteLine($"Maker Fee: {makerFee}"); // } ``` -------------------------------- ### Get Spot Exchange Info and Tickers Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Retrieve both exchange information and current ticker data for spot markets. ```csharp client.SpotApi.ExchangeData.GetExchangeInfoAndTickersAsync() ``` -------------------------------- ### Get Spot Account Balances Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/index.html Retrieve the asset balances for your spot trading account. Requires API credentials to be configured. ```csharp var hyperLiquidClient = new HyperLiquidRestClient(options => { options.ApiCredentials = new ApiCredentials("ADDRESS", "PRIVATE KEY"); }); var result = await hyperLiquidClient.SpotApi.Account.GetBalancesAsync(); ``` -------------------------------- ### Configure HyperLiquid with Dependency Injection Source: https://github.com/jkorf/hyperliquid.net/blob/main/AGENTS.md Register HyperLiquid clients with dependency injection using AddHyperLiquid. Configure API credentials during setup. The library will automatically inject IHyperLiquidRestClient and IHyperLiquidSocketClient. ```csharp using HyperLiquid.Net; services.AddHyperLiquid(options => { options.ApiCredentials = new HyperLiquidCredentials("PUBLIC_ADDRESS", "PRIVATE_KEY"); }); // Inject IHyperLiquidRestClient and IHyperLiquidSocketClient. ``` -------------------------------- ### Get Spot Symbols Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/index.html Retrieve a list of supported spot trading symbols from the exchange. Requires a RestClient instance. ```csharp var hyperLiquidClient = new HyperLiquidRestClient(); var result = await hyperLiquidClient.SpotApi.ExchangeData.GetExchangeInfoAsync(); var symbols = result.Data.Symbols; ``` -------------------------------- ### Get Account Information Source: https://github.com/jkorf/hyperliquid.net/blob/main/HyperLiquid.Net.UnitTests/Endpoints/Futures/Account/GetAccountInfo.txt This endpoint retrieves the current state of your account, including margin details, open positions, and available funds. ```APIDOC ## POST /info ### Description Retrieves detailed account information, including margin summaries, open positions, and withdrawable balance. ### Method POST ### Endpoint /info ### Request Body This endpoint does not require a request body. ### Response #### Success Response (200) - **marginSummary** (object) - Summary of margin usage for the account. - **accountValue** (string) - The total account value. - **totalNtlPos** (string) - The total notional position value. - **totalRawUsd** (string) - The total raw USD value. - **totalMarginUsed** (string) - The total margin used. - **crossMarginSummary** (object) - Summary of cross margin usage. - **accountValue** (string) - The total account value. - **totalNtlPos** (string) - The total notional position value. - **totalRawUsd** (string) - The total raw USD value. - **totalMarginUsed** (string) - The total margin used. - **crossMaintenanceMarginUsed** (string) - The cross maintenance margin used. - **withdrawable** (string) - The amount of funds that can be withdrawn. - **assetPositions** (array) - An array of objects, each representing an asset position. - **type** (string) - The type of position (e.g., "oneWay"). - **position** (object) - Details of the asset position. - **coin** (string) - The cryptocurrency symbol. - **szi** (string) - Size of the position. - **leverage** (object) - Leverage details for the position. - **type** (string) - The type of leverage (e.g., "isolated"). - **value** (number) - The leverage value. - **rawUsd** (string) - The raw USD value of the leverage. - **entryPx** (string) - The entry price of the position. - **positionValue** (string) - The total value of the position. - **unrealizedPnl** (string) - The unrealized profit or loss. - **returnOnEquity** (string) - The return on equity. - **liquidationPx** (string) - The liquidation price. - **marginUsed** (string) - The margin used for this position. - **maxLeverage** (number) - The maximum leverage allowed for this position. - **cumFunding** (object) - Cumulative funding details. - **allTime** (string) - Total cumulative funding. - **sinceOpen** (string) - Funding since the position was opened. - **sinceChange** (string) - Funding since the last change. - **time** (number) - The timestamp of the data. #### Response Example ```json { "marginSummary": { "accountValue": "83.307638", "totalNtlPos": "75.652", "totalRawUsd": "7.655638", "totalMarginUsed": "7.525754" }, "crossMarginSummary": { "accountValue": "75.781884", "totalNtlPos": "0.0", "totalRawUsd": "75.781884", "totalMarginUsed": "0.0" }, "crossMaintenanceMarginUsed": "0.0", "withdrawable": "75.781884", "assetPositions": [ { "type": "oneWay", "position": { "coin": "HYPE", "szi": "2.0", "leverage": { "type": "isolated", "value": 10, "rawUsd": "-68.126246" }, "entryPx": "37.829", "positionValue": "75.652", "unrealizedPnl": "-0.006", "returnOnEquity": "-0.0007930424", "liquidationPx": "35.8559189474", "marginUsed": "7.525754", "maxLeverage": 10, "cumFunding": { "allTime": "4.966798", "sinceOpen": "0.0", "sinceChange": "0.0" } } } ], "time": 1754467216357 } ``` ``` -------------------------------- ### Get Asset Info Source: https://github.com/jkorf/hyperliquid.net/blob/main/HyperLiquid.Net.UnitTests/Endpoints/Spot/ExchangeData/GetAssetInfo.txt Fetches detailed information for a given asset. This includes supply details, current and historical pricing, and other relevant metadata. ```APIDOC ## POST /info ### Description Fetches detailed information for a given asset. This includes supply details, current and historical pricing, and other relevant metadata. ### Method POST ### Endpoint /info ### Request Body - **name** (string) - Required - The name of the asset to retrieve information for. ### Request Example ```json { "name": "USDC" } ``` ### Response #### Success Response (200) - **name** (string) - The name of the asset. - **maxSupply** (string) - The maximum possible supply of the asset. - **totalSupply** (string) - The total current supply of the asset. - **circulatingSupply** (string) - The currently circulating supply of the asset. - **szDecimals** (integer) - The number of decimal places for the size of the asset. - **weiDecimals** (integer) - The number of decimal places for the wei value of the asset. - **midPx** (string) - The mid-price of the asset. - **markPx** (string) - The mark price of the asset. - **prevDayPx** (string) - The price of the asset from the previous day. - **genesis** (null) - Placeholder for genesis information. - **deployer** (null) - Placeholder for deployer information. - **deployGas** (null) - Placeholder for deploy gas information. - **deployTime** (null) - Placeholder for deploy time information. - **seededUsdc** (string) - The amount of seeded USDC for the asset. - **nonCirculatingUserBalances** (array) - Balances not currently in circulation. - **futureEmissions** (string) - Future emissions information for the asset. #### Response Example ```json { "name": "USDC", "maxSupply": "1000000000000.0", "totalSupply": "2275588757.45336485", "circulatingSupply": "2275588757.45336485", "szDecimals": 8, "weiDecimals": 0, "midPx": "1.0", "markPx": "1.0", "prevDayPx": "1.0", "genesis": null, "deployer": null, "deployGas": null, "deployTime": null, "seededUsdc": "0.0", "nonCirculatingUserBalances": [], "futureEmissions": "0.0" } ``` ``` -------------------------------- ### Get Futures Symbol Ticker Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/index.html Fetches the 24-hour price ticker for a specific futures symbol. Use this to get the latest trading price and volume information. ```csharp var result = await hyperLiquidClient.SpotApi.ExchangeData.GetExchangeInfoAndTickersAsync(); var symbolTicker = result.Data.Tickers.Single(x => x.Symbol == "ETH"); ``` -------------------------------- ### Get Exchange Info and Tickers (REST) Source: https://github.com/jkorf/hyperliquid.net/blob/main/llms-full.txt Retrieves comprehensive exchange information and current ticker data for a specified trading mode (Spot or Futures). This is useful for getting a snapshot of market conditions. ```APIDOC ## Get Exchange Info and Tickers ### Description Retrieves exchange information and ticker data. ### Method ```text client.SpotApi.ExchangeData.GetExchangeInfoAndTickersAsync() client.FuturesApi.ExchangeData.GetExchangeInfoAndTickersAsync() ``` ### Parameters None directly on the method, but the client must be initialized. ### Response - **Success** (bool) - Indicates if the call was successful. - **Error** (object) - Contains error details if `Success` is false. - **Data** (object) - Contains `ExchangeInfo` and `Tickers` if `Success` is true. ### Example ```csharp var result = await client.FuturesApi.ExchangeData.GetExchangeInfoAndTickersAsync(); if (!result.Success) { Console.WriteLine($"Code: {result.Error?.Code}"); Console.WriteLine($"Message: {result.Error?.Message}"); return; } var eth = result.Data.Tickers.Single(x => x.Symbol == "ETH"); Console.WriteLine(eth.MidPrice); ``` ``` -------------------------------- ### Get User Trades Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Retrieve a list of all trades executed by the user. ```csharp client.SpotApi.Trading.GetUserTradesAsync() ``` -------------------------------- ### Multi-Exchange Pattern Example Source: https://github.com/jkorf/hyperliquid.net/blob/main/llms.txt Utilizes CryptoExchange.Net SharedApis for exchange-agnostic spot and futures ticker and socket code. This pattern allows for unified handling across different exchange clients. ```csharp using CryptoExchange.Net.Clients; using CryptoExchange.Net.Objects; using HyperLiquid.Net; // Initialize clients for multiple exchanges var hyperliquidClient = new HyperLiquidRestClient(); // var anotherExchangeClient = new AnotherExchangeRestClient(); // Use shared APIs for exchange-agnostic operations var spotTickers = await hyperliquidClient.SpotApi.GetSpotTickersAsync(); // var anotherSpotTickers = await anotherExchangeClient.SpotApi.GetSpotTickersAsync(); // Example of using shared WebSocket functionality (conceptual) // var socketClient = new CombinedSocketClient( // new HyperLiquidSocketClient(), // new AnotherExchangeSocketClient() // ); // await socketClient.SpotTickerStreams.SubscribeAsync("HYPE/USDC", data => { // Console.WriteLine($"Spot Ticker: {data.Symbol} - {data.LastPrice}"); // }); ``` -------------------------------- ### Get Staking Rewards Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Fetch information about accrued staking rewards. ```csharp client.SpotApi.Account.GetStakingRewardsAsync() ``` -------------------------------- ### Initialize HyperLiquid REST Client Source: https://github.com/jkorf/hyperliquid.net/blob/main/AGENTS.md Set up a REST client for interacting with the HyperLiquid API. Provide API credentials for authenticated requests or omit them for public market data access. ```csharp using HyperLiquid.Net; using HyperLiquid.Net.Clients; var restClient = new HyperLiquidRestClient(options => { options.ApiCredentials = new HyperLiquidCredentials("PUBLIC_ADDRESS", "PRIVATE_KEY"); }); ``` ```csharp var publicClient = new HyperLiquidRestClient(); ``` -------------------------------- ### Get Staking History Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Retrieve the historical record of your staking transactions. ```csharp client.SpotApi.Account.GetStakingHistoryAsync() ``` -------------------------------- ### Configure HyperLiquid Environments Source: https://github.com/jkorf/hyperliquid.net/blob/main/AGENTS.md Instantiate HyperLiquidRestClient instances for different environments (Live or Testnet) by setting the 'Environment' option during client creation. ```csharp var live = new HyperLiquidRestClient(o => o.Environment = HyperLiquidEnvironment.Live); var testnet = new HyperLiquidRestClient(o => o.Environment = HyperLiquidEnvironment.Testnet); ``` -------------------------------- ### Get User Role Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Determine the role assigned to the current user. ```csharp client.SpotApi.Account.GetUserRoleAsync() ``` -------------------------------- ### Get Subaccounts Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Retrieve a list of all subaccounts associated with your main account. ```csharp client.SpotApi.Account.GetSubAccountsAsync() ``` -------------------------------- ### Get Extra Agents Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Retrieve information about any additional agents linked to your account. ```csharp client.SpotApi.Account.GetExtraAgentsAsync() ``` -------------------------------- ### Configure HyperLiquid Client for Different Environments Source: https://github.com/jkorf/hyperliquid.net/blob/main/llms-full.txt Set the HyperLiquidEnvironment to either Live or Testnet when initializing the REST client. ```csharp var live = new HyperLiquidRestClient(options => options.Environment = HyperLiquidEnvironment.Live); var testnet = new HyperLiquidRestClient(options => options.Environment = HyperLiquidEnvironment.Testnet); ``` -------------------------------- ### Configure API Key Authentication Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Set up API credentials using your public address and private key for authentication. ```csharp options.ApiCredentials = new HyperLiquidCredentials("public address", "private key") ``` -------------------------------- ### Use Account API for Staking Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Access staking functionalities through `SpotApi.Account.GetStaking*` and related action methods, not a separate staking client. ```csharp Separate staking client ``` -------------------------------- ### Configure HyperLiquid with Dependency Injection Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/index.html Configure HyperLiquid.Net using .NET dependency injection, either from a configuration file or directly in code. This sets up logging and HttpClient usage. ```csharp builder.Services.AddHyperLiquid(builder.Configuration.GetSection("HyperLiquid")); ``` ```csharp builder.Services.AddHyperLiquid(options => { // Configure options in code options.ApiCredentials = new ApiCredentials("APIKEY", "APISECRET"); }); ``` -------------------------------- ### Get Open Orders Source: https://github.com/jkorf/hyperliquid.net/blob/main/HyperLiquid.Net.UnitTests/Endpoints/Spot/Trading/GetOpenOrders.txt Retrieves a list of all open orders for the current user. ```APIDOC ## POST /info ### Description Retrieves a list of open orders. This endpoint is used to fetch all currently active orders for a user. ### Method POST ### Endpoint /info ### Request Body - **coin** (string) - Required - The trading pair symbol (e.g., "BTC"). - **limitPx** (string) - Required - The limit price for the order. - **oid** (integer) - Required - The order ID. - **side** (string) - Required - The side of the order, "A" for Ask (Sell), "B" for Bid (Buy). - **sz** (string) - Required - The size or quantity of the order. - **timestamp** (integer) - Required - The Unix timestamp in milliseconds when the order was placed. ### Request Example ```json [ { "coin": "BTC", "limitPx": "29792.0", "oid": 91490942, "side": "A", "sz": "0.0", "timestamp": 1681247412573 } ] ``` ### Response #### Success Response (200) - **field1** (type) - Description #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Construct HyperLiquid Clients Directly Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/index.html Instantiate HyperLiquidRestClient and HyperLiquidSocketClient directly, configuring options as needed. This is an alternative to dependency injection. ```csharp var restClient = new HyperLiquidRestClient(options => { // Options can be configured here, for example: options.ApiCredentials = new ApiCredentials("APIKEY", "APISECRET"); }); ``` ```csharp var socketClient = new HyperLiquidSocketClient(); ``` -------------------------------- ### Get Rate Limits Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Check the current API rate limits and usage status. ```csharp client.SpotApi.Account.GetRateLimitsAsync() ``` -------------------------------- ### Get Balances and Position Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/index.html Retrieves the balance and position information for the perpetual futures account. ```APIDOC ## Get Balances and Position ### Description Get balance of the perpetual futures account ### Method GET (Implied) ### Endpoint /api/v1/futures/account (Implied) ### Authentication Requires API credentials. ### Code Example ```csharp var hyperLiquidClient = new HyperLiquidRestClient(options => { options.ApiCredentials = new ApiCredentials("ADDRESS", "PRIVATE KEY"); }); var result = await hyperLiquidClient.FuturesApi.Account.GetAccountInfoAsync(); ``` ``` -------------------------------- ### Create Shared Spot WebSocket Client Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Instantiate a shared spot WebSocket client for real-time data across exchanges. Use this for exchange-agnostic spot market data. ```csharp new HyperLiquidSocketClient().SpotApi.SharedClient ``` -------------------------------- ### Place Futures Order Source: https://github.com/jkorf/hyperliquid.net/blob/main/llms-full.txt Demonstrates placing a market order for ETH futures. Ensure leverage is set before placing orders. Use `reduceOnly: true` for closing positions. ```csharp using HyperLiquid.Net; using HyperLiquid.Net.Clients; using HyperLiquid.Net.Enums; var client = new HyperLiquidRestClient(options => { options.ApiCredentials = new HyperLiquidCredentials("PUBLIC_ADDRESS", "PRIVATE_KEY"); }); var leverage = await client.FuturesApi.Trading.SetLeverageAsync("ETH", 5, MarginType.Cross); if (!leverage.Success) { Console.WriteLine(leverage.Error); return; } var order = await client.FuturesApi.Trading.PlaceOrderAsync( symbol: "ETH", side: OrderSide.Buy, orderType: OrderType.Market, quantity: 0.01m, price: 3000m); if (!order.Success) { Console.WriteLine(order.Error); return; } ``` -------------------------------- ### Get Symbols Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/index.html Retrieves a list of all supported USD futures symbols available on the exchange. ```APIDOC ## Get Symbols ### Description Get a list of supported usd futures symbols ### Method GET (Implied) ### Endpoint /api/v1/futures/symbols (Implied) ### Code Example ```csharp var hyperLiquidClient = new HyperLiquidRestClient(); var result = await hyperLiquidClient.FuturesApi.ExchangeData.GetExchangeInfoAsync(); ``` ``` -------------------------------- ### Subscribe to All Mid Prices via WebSocket Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Subscribe to real-time mid-price updates for all available instruments on a specified DEX. Requires the DEX identifier and a handler. ```csharp socketClient.FuturesApi.ExchangeData.SubscribeToPriceUpdatesAsync(dex, handler) ``` -------------------------------- ### Provide Price for Market Orders Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md When placing a market order, ensure that a `price` is provided to the `PlaceOrderAsync` method. ```csharp Market order without price ``` -------------------------------- ### Get Account Ledger Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Retrieve a history of account transactions within a specified time range. ```csharp client.SpotApi.Account.GetAccountLedgerAsync(start, end) ``` -------------------------------- ### Initialize HyperLiquid WebSocket Client Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Use this for establishing WebSocket streams and making socket API requests. ```csharp new HyperLiquidSocketClient() ``` -------------------------------- ### Get Spot Order Book Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Retrieve the order book for a specified spot trading symbol. ```csharp client.SpotApi.ExchangeData.GetOrderBookAsync("HYPE/USDC") ``` -------------------------------- ### Configure Dependency Injection Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Integrate HyperLiquid services into your application using dependency injection. ```csharp services.AddHyperLiquid(options => { ... }) ``` -------------------------------- ### Get Symbol Ticker Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/index.html Fetches the 24-hour price ticker information for a specific futures symbol. ```APIDOC ## Get Symbol Ticker ### Description Get the 24h price ticker of a futures symbol ### Method GET (Implied) ### Endpoint /api/v1/spot/tickers (Implied, based on example usage) ### Parameters #### Query Parameters - **symbol** (string) - Required - The symbol for which to retrieve ticker information. ### Code Example ```csharp var result = await hyperLiquidClient.SpotApi.ExchangeData.GetExchangeInfoAndTickersAsync(); var symbolTicker = result.Data.Tickers.Single(x => x.Symbol == "ETH"); ``` ``` -------------------------------- ### Inject HyperLiquid Clients into a Service Source: https://github.com/jkorf/hyperliquid.net/blob/main/llms-full.txt Demonstrates how to inject the IHyperLiquidRestClient and IHyperLiquidSocketClient interfaces into a service class constructor. ```csharp using HyperLiquid.Net.Interfaces.Clients; public class MyService { private readonly IHyperLiquidRestClient _restClient; private readonly IHyperLiquidSocketClient _socketClient; public MyService(IHyperLiquidRestClient restClient, IHyperLiquidSocketClient socketClient) { _restClient = restClient; _socketClient = socketClient; } } ``` -------------------------------- ### Set HyperLiquid Environment Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Specify whether to use the live trading environment or the testnet. ```csharp HyperLiquidEnvironment.Live ``` ```csharp HyperLiquidEnvironment.Testnet ``` -------------------------------- ### Get Klines Data Source: https://github.com/jkorf/hyperliquid.net/blob/main/HyperLiquid.Net.UnitTests/Endpoints/Spot/ExchangeData/GetKlines.txt Retrieves historical klines data for a specified trading pair and time interval. ```APIDOC ## POST /info ### Description Retrieves historical klines data for a specified trading pair and time interval. ### Method POST ### Endpoint /info ### Request Body This endpoint accepts a JSON array of objects, where each object specifies the parameters for fetching klines data. The exact structure of these objects is not detailed in the provided source, but an example is given below. ### Request Example ```json [ { "t": 1737331200000, "T": 1737417599999, "s": "@107", "i": "1d" } ] ``` ### Response #### Success Response (200) Returns an array of klines data. Each kline object contains the following fields: - **t** (long) - Timestamp of the start of the kline interval. - **T** (long) - Timestamp of the end of the kline interval. - **s** (string) - Trading pair symbol. - **i** (string) - Interval of the kline (e.g., "1d" for daily). - **o** (string) - Open price. - **c** (string) - Close price. - **h** (string) - High price. - **l** (string) - Low price. - **v** (string) - Volume. - **n** (integer) - Number of trades. #### Response Example ```json [ { "t": 1737331200000, "T": 1737417599999, "s": "@107", "i": "1d", "o": "20.184", "c": "20.547", "h": "22.755", "l": "19.3", "v": "10651612.71", "n": 278401 }, { "t": 1737417600000, "T": 1737503999999, "s": "@107", "i": "1d", "o": "20.552", "c": "21.738", "h": "21.917", "l": "20.027", "v": "1736000.02", "n": 49556 } ] ``` ``` -------------------------------- ### Get Exchange Information Source: https://github.com/jkorf/hyperliquid.net/blob/main/HyperLiquid.Net.UnitTests/Endpoints/Spot/ExchangeData/GetExchangeInfo.txt Fetches detailed information about the exchange's trading universe and token specifications. ```APIDOC ## POST /info ### Description Retrieves information about the exchange's trading pairs and token details. ### Method POST ### Endpoint /info ### Request Body This endpoint does not require a request body. ### Response #### Success Response (200) - **universe** (array) - List of trading pairs, each with tokens and name. - **tokens** (array) - List of tokens, each with name, decimals, index, and other properties. ``` -------------------------------- ### Create Shared Spot REST Client Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Instantiate a shared spot REST client for exchange-agnostic operations. This client can be used across multiple exchanges. ```csharp new HyperLiquidRestClient().SpotApi.SharedClient ``` -------------------------------- ### Use Trading API for Leverage and Margin Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Use `FuturesApi.Trading.SetLeverageAsync` or `UpdateIsolatedMarginAsync` for managing leverage and margin, rather than a separate margin client. ```csharp Separate margin client ``` -------------------------------- ### Subscribe to Spot Trading and Account Updates via WebSocket Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Subscribe to real-time updates for spot trading events, including order status, open orders, user trades, TWAP trades/orders, and ledger/event updates. Requires an address and a handler function. ```csharp socketClient.SpotApi.Trading.SubscribeToOrderUpdatesAsync(address, handler) ``` ```csharp socketClient.SpotApi.Trading.SubscribeToOpenOrderUpdatesAsync(address, dex, handler) ``` ```csharp socketClient.SpotApi.Trading.SubscribeToUserTradeUpdatesAsync(address, handler) ``` ```csharp socketClient.SpotApi.Trading.SubscribeToTwapTradeUpdatesAsync(address, handler) ``` ```csharp socketClient.SpotApi.Trading.SubscribeToTwapOrderUpdatesAsync(address, handler) ``` ```csharp socketClient.SpotApi.Account.SubscribeToUserLedgerUpdatesAsync(address, handler) ``` ```csharp socketClient.SpotApi.Account.SubscribeToUserEventUpdates(...) ``` ```csharp socketClient.SpotApi.Account.SubscribeToWebData3UpdatesAsync(address, handler) ``` -------------------------------- ### Get Funding Rate History Source: https://github.com/jkorf/hyperliquid.net/blob/main/HyperLiquid.Net.UnitTests/Endpoints/Futures/ExchangeData/GetFundingRateHistory.txt Fetches a list of historical funding rates, premiums, and timestamps for a given coin. ```APIDOC ## POST /info ### Description Retrieves historical funding rate data for a specified coin. ### Method POST ### Endpoint /info ### Request Body - **coin** (string) - Required - The trading pair symbol (e.g., "ETH"). ### Response #### Success Response (200) - **coin** (string) - The trading pair symbol. - **fundingRate** (string) - The historical funding rate. - **premium** (string) - The historical premium. - **time** (integer) - The timestamp of the record in milliseconds. ### Response Example ```json [ { "coin":"ETH", "fundingRate": "-0.00022196", "premium": "-0.00052196", "time":1683849600076 } ] ``` ``` -------------------------------- ### Place a Futures Order and Set Leverage Source: https://github.com/jkorf/hyperliquid.net/blob/main/AGENTS.md Set leverage for a futures contract before placing an order. The PlaceOrderAsync method can be used for market orders, providing a price for slippage calculation. Use 'reduceOnly: true' to close positions. ```csharp using HyperLiquid.Net.Enums; var leverage = await restClient.FuturesApi.Trading.SetLeverageAsync( symbol: "ETH", leverage: 5, marginType: MarginType.Cross); if (!leverage.Success) { Console.WriteLine(leverage.Error); return; } var order = await restClient.FuturesApi.Trading.PlaceOrderAsync( symbol: "ETH", side: OrderSide.Buy, orderType: OrderType.Market, quantity: 0.01m, price: 3000m); ``` -------------------------------- ### Get Account Balances Source: https://github.com/jkorf/hyperliquid.net/blob/main/HyperLiquid.Net.UnitTests/Endpoints/Spot/Account/GetBalances.txt This endpoint allows you to retrieve your current asset balances, including total amounts and any held amounts. ```APIDOC ## POST /info ### Description Retrieves the balances for a user's account on the Hyperliquid platform. ### Method POST ### Endpoint /info ### Request Body This endpoint does not require a request body. ### Response #### Success Response (200) - **balances** (array) - An array of balance objects. - **coin** (string) - The name of the asset. - **token** (integer) - The token identifier for the asset. - **total** (string) - The total amount of the asset. - **hold** (string) - The amount of the asset currently held. - **entryNtl** (string) - The entry value in native currency. ### Response Example ```json { "balances": [ { "coin": "USDC", "token": 0, "total": "2.77363", "hold": "0.0", "entryNtl": "0.0" }, { "coin": "HYPE", "token": 150, "total": "0.00959057", "hold": "0.0", "entryNtl": "0.214388" } ] } ``` ``` -------------------------------- ### Place a Futures Limit Order Source: https://github.com/jkorf/hyperliquid.net/blob/main/README.md Place a limit order on the futures market using the HyperLiquidRestClient with API credentials. Ensure to replace 'PUBLICKEY' and 'PRIVATEKEY' with your actual credentials. ```csharp var restClient = new HyperLiquidRestClient(opts => { opts.ApiCredentials = new HyperLiquidCredentials("PUBLICKEY", "PRIVATEKEY"); }); // Place Limit order to go long for 0.1 ETH at 2000 var orderResult = await restClient.FuturesApi.Trading.PlaceOrderAsync( "ETH", OrderSide.Buy, OrderType.Limit, 0.1m, 2000 ); ``` -------------------------------- ### Get Order by ID or Client ID Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Retrieve details of a specific order using its order ID or client-provided order ID. ```csharp client.SpotApi.Trading.GetOrderAsync(orderId, clientOrderId) ``` -------------------------------- ### Check Interface for Server Time Method Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md HyperLiquid.Net does not expose a `GetServerTimeAsync()` method. Inspect the available interfaces to find relevant time-related methods if needed. ```csharp Invented `GetServerTimeAsync()` ``` -------------------------------- ### Get Spot Order Information Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/index.html Retrieve details for a specific spot order using its order ID. Requires API credentials. ```csharp var hyperLiquidClient = new HyperLiquidRestClient(options => { options.ApiCredentials = new ApiCredentials("ADDRESS", "PRIVATE KEY"); }); var result = await hyperLiquidClient.SpotApi.Trading.GetOrderAsync(123); ``` -------------------------------- ### Subscribe to Spot Market Updates via WebSocket Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Subscribe to real-time updates for various spot market data streams, including symbols, balances, order books, klines, trades, and tickers. Requires a symbol and a handler function. ```csharp socketClient.SpotApi.ExchangeData.SubscribeToSymbolUpdatesAsync("HYPE/USDC", handler) ``` ```csharp socketClient.SpotApi.Account.SubscribeToBalanceUpdatesAsync(address, handler) ``` ```csharp socketClient.SpotApi.ExchangeData.SubscribeToOrderBookUpdatesAsync("HYPE/USDC", handler) ``` ```csharp socketClient.SpotApi.ExchangeData.SubscribeToKlineUpdatesAsync("HYPE/USDC", interval, handler) ``` ```csharp socketClient.SpotApi.ExchangeData.SubscribeToTradeUpdatesAsync("HYPE/USDC", handler) ``` ```csharp socketClient.SpotApi.ExchangeData.SubscribeToBookTickerUpdatesAsync("HYPE/USDC", handler) ``` -------------------------------- ### Get Sub Accounts Source: https://github.com/jkorf/hyperliquid.net/blob/main/HyperLiquid.Net.UnitTests/Endpoints/Spot/Account/GetSubAccounts.txt Retrieves a list of sub-accounts associated with a master account, including their current financial status and asset holdings. ```APIDOC ## POST /info ### Description Retrieves information about sub-accounts, including their financial state and asset balances. ### Method POST ### Endpoint /info ### Request Body This endpoint does not explicitly define a request body schema in the provided source. However, the example shows a JSON array of objects, each representing a sub-account with details like name, subAccountUser, master, clearinghouseState, and spotState. ### Request Example ```json [ { "name": "Test", "subAccountUser": "0x035605fc2f24d65300227189025e90a0d947f16c", "master": "0x8c967e73e6b15087c42a10d344cff4c96d877f1d", "clearinghouseState": { "marginSummary": { "accountValue": "29.78001", "totalNtlPos": "0.0", "totalRawUsd": "29.78001", "totalMarginUsed": "0.0" }, "crossMarginSummary": { "accountValue": "29.78001", "totalNtlPos": "0.0", "totalRawUsd": "29.78001", "totalMarginUsed": "0.0" }, "crossMaintenanceMarginUsed": "0.0", "withdrawable": "29.78001", "assetPositions": [], "time": 1733968369395 }, "spotState": { "balances": [ { "coin": "USDC", "token": 0, "total": "0.22", "hold": "0.0", "entryNtl": "0.0" } ] } } ] ``` ### Response #### Success Response (200) - The response is a JSON array containing objects, where each object represents a sub-account with its associated data. The structure mirrors the request body, providing details on clearinghouse and spot states. ``` -------------------------------- ### Place Spot Order Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Submit a new spot trading order with specified parameters like symbol, side, type, quantity, and price. ```csharp client.SpotApi.Trading.PlaceOrderAsync("HYPE/USDC", side, orderType, quantity, price, ...) ``` -------------------------------- ### Place Multiple Spot Orders Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Submit multiple spot trading orders simultaneously. Requires a list of order requests. ```csharp client.SpotApi.Trading.PlaceMultipleOrdersAsync(requests) ``` -------------------------------- ### Get Spot Klines Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Fetch historical candlestick (Kline) data for a spot trading symbol within a specified time range and interval. ```csharp client.SpotApi.ExchangeData.GetKlinesAsync("HYPE/USDC", KlineInterval.OneMinute, start, end) ``` -------------------------------- ### Client Roots Source: https://github.com/jkorf/hyperliquid.net/blob/main/docs/ai-api-map.md Provides fundamental client initialization and configuration options for interacting with the HyperLiquid.Net API. ```APIDOC ## Client Roots This section outlines the core client types and essential configuration options. ### REST Client - **Intent**: REST calls - **Use**: `new HyperLiquidRestClient()` ### WebSocket Client - **Intent**: WebSocket streams and socket API requests - **Use**: `new HyperLiquidSocketClient()` ### API Key Authentication - **Intent**: API key authentication - **Use**: `options.ApiCredentials = new HyperLiquidCredentials("public address", "private key")` ### Environment Configuration - **Intent**: Live environment - **Use**: `HyperLiquidEnvironment.Live` - **Intent**: Testnet environment - **Use**: `HyperLiquidEnvironment.Testnet` ### Dependency Injection - **Intent**: Dependency injection - **Use**: `services.AddHyperLiquid(options => { ... })` ### Builder Fee Configuration - **Intent**: Disable builder fee - **Use**: `options.BuilderFeePercentage = 0` ### Symbol Formatting - **Intent**: Format spot symbol - **Use**: `HyperLiquidExchange.FormatSymbol("HYPE", "USDC", TradingMode.Spot)` - **Intent**: Format futures symbol - **Use**: `HyperLiquidExchange.FormatSymbol("ETH", "USDC", TradingMode.PerpetualLinear)` ```