UNPKG

@nktkas/hyperliquid

Version:

Hyperliquid API SDK for all major JS runtimes, written in TypeScript.

158 lines 8.57 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.FrontendOpenOrdersResponse = exports.FrontendOpenOrdersRequest = void 0; exports.frontendOpenOrders = frontendOpenOrders; const v = __importStar(require("valibot")); // ============================================================ // API Schemas // ============================================================ const _schemas_js_1 = require("../../_schemas.js"); /** * Request frontend open orders. * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-users-open-orders-with-additional-frontend-info */ exports.FrontendOpenOrdersRequest = (() => { return v.pipe(v.object({ /** Type of request. */ type: v.pipe(v.literal("frontendOpenOrders"), v.description("Type of request.")), /** User address. */ user: v.pipe(_schemas_js_1.Address, v.description("User address.")), /** DEX name (empty string for main dex). */ dex: v.pipe(v.optional(v.string()), v.description("DEX name (empty string for main dex).")), }), v.description("Request frontend open orders.")); })(); /** * Array of open orders with additional display information. * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-users-open-orders-with-additional-frontend-info */ exports.FrontendOpenOrdersResponse = (() => { return v.pipe(v.array(v.pipe(v.object({ /** Asset symbol. */ coin: v.pipe(v.string(), v.description("Asset symbol.")), /** Order side ("B" = Bid/Buy, "A" = Ask/Sell). */ side: v.pipe(v.picklist(["B", "A"]), v.description('Order side ("B" = Bid/Buy, "A" = Ask/Sell).')), /** Limit price. */ limitPx: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Limit price.")), /** Size. */ sz: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Size.")), /** Order ID. */ oid: v.pipe(_schemas_js_1.UnsignedInteger, v.description("Order ID.")), /** Timestamp when the order was placed (in ms since epoch). */ timestamp: v.pipe(_schemas_js_1.UnsignedInteger, v.description("Timestamp when the order was placed (in ms since epoch).")), /** Original size at order placement. */ origSz: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Original size at order placement.")), /** Condition for triggering the order. */ triggerCondition: v.pipe(v.string(), v.description("Condition for triggering the order.")), /** Indicates if the order is a trigger order. */ isTrigger: v.pipe(v.boolean(), v.description("Indicates if the order is a trigger order.")), /** Trigger price. */ triggerPx: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Trigger price.")), /** Child orders associated with this order. */ children: v.pipe(v.array(v.unknown()), v.description("Child orders associated with this order.")), /** Indicates if the order is a position TP/SL order. */ isPositionTpsl: v.pipe(v.boolean(), v.description("Indicates if the order is a position TP/SL order.")), /** Indicates whether the order is reduce-only. */ reduceOnly: v.pipe(v.boolean(), v.description("Indicates whether the order is reduce-only.")), /** * Order type for market execution. * - `"Market"`: Executes immediately at the market price. * - `"Limit"`: Executes at the specified limit price or better. * - `"Stop Market"`: Activates as a market order when a stop price is reached. * - `"Stop Limit"`: Activates as a limit order when a stop price is reached. * - `"Take Profit Market"`: Executes as a market order when a take profit price is reached. * - `"Take Profit Limit"`: Executes as a limit order when a take profit price is reached. * @see https://hyperliquid.gitbook.io/hyperliquid-docs/trading/order-types */ orderType: v.pipe(v.picklist(["Market", "Limit", "Stop Market", "Stop Limit", "Take Profit Market", "Take Profit Limit"]), v.description("Order type for market execution." + '\n- `"Market"`: Executes immediately at the market price.' + '\n- `"Limit"`: Executes at the specified limit price or better.' + '\n- `"Stop Market"`: Activates as a market order when a stop price is reached.' + '\n- `"Stop Limit"`: Activates as a limit order when a stop price is reached.' + '\n- `"Take Profit Market"`: Executes as a market order when a take profit price is reached.' + '\n- `"Take Profit Limit"`: Executes as a limit order when a take profit price is reached. ')), /** * Time-in-force options. * - `"Gtc"`: Remains active until filled or canceled. * - `"Ioc"`: Fills immediately or cancels any unfilled portion. * - `"Alo"`: Adds liquidity only. * - `"FrontendMarket"`: Similar to Ioc, used in Hyperliquid UI. * - `"LiquidationMarket"`: Similar to Ioc, used in Hyperliquid UI. */ tif: v.pipe(v.nullable(v.picklist(["Gtc", "Ioc", "Alo", "FrontendMarket", "LiquidationMarket"])), v.description("Time-in-force." + '\n- `"Gtc"`: Remains active until filled or canceled.' + '\n- `"Ioc"`: Fills immediately or cancels any unfilled portion.' + '\n- `"Alo"`: Adds liquidity only.' + '\n- `"FrontendMarket"`: Similar to Ioc, used in Hyperliquid UI.' + '\n- `"LiquidationMarket"`: Similar to Ioc, used in Hyperliquid UI.')), /** Client Order ID. */ cloid: v.pipe(v.nullable(v.pipe(_schemas_js_1.Hex, v.length(34))), v.description("Client Order ID.")), }), v.description("Open order with additional display information."))), v.description("Array of open orders with additional display information.")); })(); /** * Request frontend open orders. * * @param config - General configuration for Info API requests. * @param params - Parameters specific to the API request. * @param signal - [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) to cancel the request. * * @returns Array of open orders with additional display information. * * @throws {ValiError} When the request parameters fail validation (before sending). * @throws {TransportError} When the transport layer throws an error. * * @example * ```ts * import { HttpTransport } from "@nktkas/hyperliquid"; * import { frontendOpenOrders } from "@nktkas/hyperliquid/api/info"; * * const transport = new HttpTransport(); // or `WebSocketTransport` * * const data = await frontendOpenOrders( * { transport }, * { user: "0x..." }, * ); * ``` * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-users-open-orders-with-additional-frontend-info */ function frontendOpenOrders(config, params, signal) { const request = v.parse(exports.FrontendOpenOrdersRequest, { type: "frontendOpenOrders", ...params, }); return config.transport.request("info", request, signal); } //# sourceMappingURL=frontendOpenOrders.js.map