UNPKG

@nktkas/hyperliquid

Version:

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

377 lines 21.8 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.OrderProcessingStatusSchema = exports.UserFillSchema = exports.ExplorerTransactionSchema = exports.VaultRelationshipSchema = exports.TwapStateSchema = exports.OpenOrderSchema = exports.FrontendOpenOrderSchema = exports.SpotAssetCtxSchema = exports.PerpAssetCtxSchema = void 0; const v = __importStar(require("valibot")); const _schemas_js_1 = require("../../../_schemas.js"); /** Perpetual asset context. */ exports.PerpAssetCtxSchema = (() => { return v.pipe(v.object({ /** Previous day's closing price. */ prevDayPx: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Previous day's closing price.")), /** Daily notional volume. */ dayNtlVlm: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Daily notional volume.")), /** Mark price. */ markPx: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Mark price.")), /** Mid price. */ midPx: v.pipe(v.nullable(_schemas_js_1.UnsignedDecimal), v.description("Mid price.")), /** Funding rate. */ funding: v.pipe(_schemas_js_1.Decimal, v.description("Funding rate.")), /** Total open interest. */ openInterest: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Total open interest.")), /** Premium price. */ premium: v.pipe(v.nullable(_schemas_js_1.Decimal), v.description("Premium price.")), /** Oracle price. */ oraclePx: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Oracle price.")), /** Array of impact prices. */ impactPxs: v.pipe(v.nullable(v.array(v.string())), v.description("Array of impact prices.")), /** Daily volume in base currency. */ dayBaseVlm: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Daily volume in base currency.")), }), v.description("Perpetual asset context.")); })(); /** Spot asset context. */ exports.SpotAssetCtxSchema = (() => { return v.pipe(v.object({ /** Previous day's closing price. */ prevDayPx: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Previous day's closing price.")), /** Daily notional volume. */ dayNtlVlm: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Daily notional volume.")), /** Mark price. */ markPx: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Mark price.")), /** Mid price. */ midPx: v.pipe(v.nullable(_schemas_js_1.UnsignedDecimal), v.description("Mid price.")), /** Circulating supply. */ circulatingSupply: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Circulating supply.")), /** Asset symbol. */ coin: v.pipe(v.string(), v.description("Asset symbol.")), /** Total supply. */ totalSupply: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Total supply.")), /** Daily volume in base currency. */ dayBaseVlm: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Daily volume in base currency.")), }), v.description("Spot asset context.")); })(); /** Open order with additional display information. */ exports.FrontendOpenOrderSchema = (() => { return 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: * - `"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(_schemas_js_1.Cloid), v.description("Client Order ID.")), }), v.description("Open order with additional display information.")); })(); /** Open order. */ exports.OpenOrderSchema = (() => { return 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.")), /** Client Order ID. */ cloid: v.pipe(v.optional(_schemas_js_1.Cloid), v.description("Client Order ID.")), /** Indicates if the order is reduce-only. */ reduceOnly: v.pipe(v.optional(v.literal(true)), v.description("Indicates if the order is reduce-only.")), }), v.description("Open order.")); })(); /** TWAP order state. */ exports.TwapStateSchema = (() => { return v.pipe(v.object({ /** Asset symbol. */ coin: v.pipe(v.string(), v.description("Asset symbol.")), /** Executed notional value. */ executedNtl: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Executed notional value.")), /** Executed size. */ executedSz: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Executed size.")), /** Duration in minutes. */ minutes: v.pipe(_schemas_js_1.UnsignedInteger, v.description("Duration in minutes.")), /** Indicates if the TWAP randomizes execution. */ randomize: v.pipe(v.boolean(), v.description("Indicates if the TWAP randomizes execution.")), /** Indicates if the order is reduce-only. */ reduceOnly: v.pipe(v.boolean(), v.description("Indicates if the order is reduce-only.")), /** 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).')), /** Order size. */ sz: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Order size.")), /** Start time of the TWAP order (in ms since epoch). */ timestamp: v.pipe(_schemas_js_1.UnsignedInteger, v.description("Start time of the TWAP order (in ms since epoch).")), /** User address. */ user: v.pipe(_schemas_js_1.Address, v.description("User address.")), }), v.description("TWAP order state.")); })(); /** Vault relationship type. */ exports.VaultRelationshipSchema = (() => { return v.pipe(v.variant("type", [ v.object({ /** Relationship type. */ type: v.pipe(v.picklist(["normal", "child"]), v.description("Relationship type.")), }), v.object({ /** Relationship type. */ type: v.pipe(v.literal("parent"), v.description("Relationship type.")), /** Child vault information. */ data: v.pipe(v.object({ /** Child vault addresses. */ childAddresses: v.pipe(v.array(_schemas_js_1.Address), v.description("Child vault addresses.")), }), v.description("Child vault information.")), }), ]), v.description("Vault relationship type.")); })(); /** Explorer transaction. */ exports.ExplorerTransactionSchema = (() => { return v.pipe(v.object({ /** Action performed in transaction. */ action: v.pipe(v.looseObject({ /** Action type. */ type: v.pipe(v.string(), v.description("Action type.")), }), v.description("Action performed in transaction.")), /** Block number where transaction was included. */ block: v.pipe(_schemas_js_1.UnsignedInteger, v.description("Block number where transaction was included.")), /** Error message if transaction failed. */ error: v.pipe(v.nullable(v.string()), v.description("Error message if transaction failed.")), /** Transaction hash. */ hash: v.pipe(_schemas_js_1.Hex, v.length(66), v.description("Transaction hash.")), /** Transaction creation timestamp. */ time: v.pipe(_schemas_js_1.UnsignedInteger, v.description("Transaction creation timestamp.")), /** Creator's address. */ user: v.pipe(_schemas_js_1.Address, v.description("Creator's address.")), }), v.description("Explorer transaction.")); })(); /** User fill. */ exports.UserFillSchema = (() => { return v.pipe(v.object({ /** Asset symbol. */ coin: v.pipe(v.string(), v.description("Asset symbol.")), /** Price. */ px: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Price.")), /** Size. */ sz: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Size.")), /** 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).')), /** Timestamp when the trade occurred (in ms since epoch). */ time: v.pipe(_schemas_js_1.UnsignedInteger, v.description("Timestamp when the trade occurred (in ms since epoch).")), /** Start position size. */ startPosition: v.pipe(_schemas_js_1.Decimal, v.description("Start position size.")), /** Direction indicator for frontend display. */ dir: v.pipe(v.string(), v.description("Direction indicator for frontend display.")), /** Realized PnL. */ closedPnl: v.pipe(_schemas_js_1.Decimal, v.description("Realized PnL.")), /** L1 transaction hash. */ hash: v.pipe(_schemas_js_1.Hex, v.length(66), v.description("L1 transaction hash.")), /** Order ID. */ oid: v.pipe(_schemas_js_1.UnsignedInteger, v.description("Order ID.")), /** Indicates if the fill was a taker order. */ crossed: v.pipe(v.boolean(), v.description("Indicates if the fill was a taker order.")), /** Fee charged or rebate received (negative indicates rebate). */ fee: v.pipe(_schemas_js_1.Decimal, v.description("Fee charged or rebate received (negative indicates rebate).")), /** Unique transaction identifier for a partial fill of an order. */ tid: v.pipe(_schemas_js_1.UnsignedInteger, v.description("Unique transaction identifier for a partial fill of an order.")), /** Token in which the fee is denominated (e.g., "USDC"). */ feeToken: v.pipe(v.string(), v.description('Token in which the fee is denominated (e.g., "USDC").')), /** ID of the TWAP. */ twapId: v.pipe(v.nullable(_schemas_js_1.UnsignedInteger), v.description("ID of the TWAP.")), }), v.description("User fill.")); })(); /** * Order processing status: * - `"open"`: Order active and waiting to be filled. * - `"filled"`: Order fully executed. * - `"canceled"`: Order canceled by the user. * - `"triggered"`: Order triggered and awaiting execution. * - `"rejected"`: Order rejected by the system. * - `"marginCanceled"`: Order canceled due to insufficient margin. * - `"vaultWithdrawalCanceled"`: Canceled due to a user withdrawal from vault. * - `"openInterestCapCanceled"`: Canceled due to order being too aggressive when open interest was at cap. * - `"selfTradeCanceled"`: Canceled due to self-trade prevention. * - `"reduceOnlyCanceled"`: Canceled reduced-only order that does not reduce position. * - `"siblingFilledCanceled"`: Canceled due to sibling ordering being filled. * - `"delistedCanceled"`: Canceled due to asset delisting. * - `"liquidatedCanceled"`: Canceled due to liquidation. * - `"scheduledCancel"`: Canceled due to exceeding scheduled cancel deadline (dead man's switch). * - `"tickRejected"`: Rejected due to invalid tick price. * - `"minTradeNtlRejected"`: Rejected due to order notional below minimum. * - `"perpMarginRejected"`: Rejected due to insufficient margin. * - `"reduceOnlyRejected"`: Rejected due to reduce only. * - `"badAloPxRejected"`: Rejected due to post-only immediate match. * - `"iocCancelRejected"`: Rejected due to IOC not able to match. * - `"badTriggerPxRejected"`: Rejected due to invalid TP/SL price. * - `"marketOrderNoLiquidityRejected"`: Rejected due to lack of liquidity for market order. * - `"positionIncreaseAtOpenInterestCapRejected"`: Rejected due to open interest cap. * - `"positionFlipAtOpenInterestCapRejected"`: Rejected due to open interest cap. * - `"tooAggressiveAtOpenInterestCapRejected"`: Rejected due to price too aggressive at open interest cap. * - `"openInterestIncreaseRejected"`: Rejected due to open interest cap. * - `"insufficientSpotBalanceRejected"`: Rejected due to insufficient spot balance. * - `"oracleRejected"`: Rejected due to price too far from oracle. * - `"perpMaxPositionRejected"`: Rejected due to exceeding margin tier limit at current leverage. */ exports.OrderProcessingStatusSchema = (() => { return v.pipe(v.picklist([ "open", "filled", "canceled", "triggered", "rejected", "marginCanceled", "vaultWithdrawalCanceled", "openInterestCapCanceled", "selfTradeCanceled", "reduceOnlyCanceled", "siblingFilledCanceled", "delistedCanceled", "liquidatedCanceled", "scheduledCancel", "tickRejected", "minTradeNtlRejected", "perpMarginRejected", "reduceOnlyRejected", "badAloPxRejected", "iocCancelRejected", "badTriggerPxRejected", "marketOrderNoLiquidityRejected", "positionIncreaseAtOpenInterestCapRejected", "positionFlipAtOpenInterestCapRejected", "tooAggressiveAtOpenInterestCapRejected", "openInterestIncreaseRejected", "insufficientSpotBalanceRejected", "oracleRejected", "perpMaxPositionRejected", ]), v.description("Order processing status:" + '\n- `"open"`: Order active and waiting to be filled.' + '\n- `"filled"`: Order fully executed.' + '\n- `"canceled"`: Order canceled by the user.' + '\n- `"triggered"`: Order triggered and awaiting execution.' + '\n- `"rejected"`: Order rejected by the system.' + '\n- `"marginCanceled"`: Order canceled due to insufficient margin.' + '\n- `"vaultWithdrawalCanceled"`: Canceled due to a user withdrawal from vault.' + '\n- `"openInterestCapCanceled"`: Canceled due to order being too aggressive when open interest was at cap.' + '\n- `"selfTradeCanceled"`: Canceled due to self-trade prevention.' + '\n- `"reduceOnlyCanceled"`: Canceled reduced-only order that does not reduce position.' + '\n- `"siblingFilledCanceled"`: Canceled due to sibling ordering being filled.' + '\n- `"delistedCanceled"`: Canceled due to asset delisting.' + '\n- `"liquidatedCanceled"`: Canceled due to liquidation.' + '\n- `"scheduledCancel"`: Canceled due to exceeding scheduled cancel deadline (dead man\'s switch).' + '\n- `"tickRejected"`: Rejected due to invalid tick price.' + '\n- `"minTradeNtlRejected"`: Rejected due to order notional below minimum.' + '\n- `"perpMarginRejected"`: Rejected due to insufficient margin.' + '\n- `"reduceOnlyRejected"`: Rejected due to reduce only.' + '\n- `"badAloPxRejected"`: Rejected due to post-only immediate match.' + '\n- `"iocCancelRejected"`: Rejected due to IOC not able to match.' + '\n- `"badTriggerPxRejected"`: Rejected due to invalid TP/SL price.' + '\n- `"marketOrderNoLiquidityRejected"`: Rejected due to lack of liquidity for market order.' + '\n- `"positionIncreaseAtOpenInterestCapRejected"`: Rejected due to open interest cap.' + '\n- `"positionFlipAtOpenInterestCapRejected"`: Rejected due to open interest cap.' + '\n- `"tooAggressiveAtOpenInterestCapRejected"`: Rejected due to price too aggressive at open interest cap.' + '\n- `"openInterestIncreaseRejected"`: Rejected due to open interest cap.' + '\n- `"insufficientSpotBalanceRejected"`: Rejected due to insufficient spot balance.' + '\n- `"oracleRejected"`: Rejected due to price too far from oracle.' + '\n- `"perpMaxPositionRejected"`: Rejected due to exceeding margin tier limit at current leverage.')); })(); //# sourceMappingURL=commonSchemas.js.map