UNPKG

@nktkas/hyperliquid

Version:

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

128 lines 5.93 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.CandleSnapshotResponse = exports.CandleSnapshotRequest = void 0; exports.candleSnapshot = candleSnapshot; const v = __importStar(require("valibot")); // ============================================================ // API Schemas // ============================================================ const _schemas_js_1 = require("../../_schemas.js"); /** * Request candlestick snapshots. * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#candle-snapshot */ exports.CandleSnapshotRequest = (() => { return v.pipe(v.object({ /** Type of request. */ type: v.pipe(v.literal("candleSnapshot"), v.description("Type of request.")), /** Request parameters. */ req: v.pipe(v.object({ /** Asset symbol (e.g., BTC). */ coin: v.pipe(v.string(), v.description("Asset symbol (e.g., BTC).")), /** Time interval. */ interval: v.pipe(v.picklist(["1m", "3m", "5m", "15m", "30m", "1h", "2h", "4h", "8h", "12h", "1d", "3d", "1w", "1M"]), v.description("Time interval.")), /** Start time (in ms since epoch). */ startTime: v.pipe(_schemas_js_1.UnsignedInteger, v.description("Start time (in ms since epoch).")), /** End time (in ms since epoch). */ endTime: v.pipe(v.nullish(_schemas_js_1.UnsignedInteger), v.description("End time (in ms since epoch).")), }), v.description("Request parameters.")), }), v.description("Request candlestick snapshots.")); })(); /** * Array of candlestick data points. * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#candle-snapshot */ exports.CandleSnapshotResponse = (() => { return v.pipe(v.array( /** Candlestick data point. */ v.pipe(v.object({ /** Opening timestamp (ms since epoch). */ t: v.pipe(_schemas_js_1.UnsignedInteger, v.description("Opening timestamp (ms since epoch).")), /** Closing timestamp (ms since epoch). */ T: v.pipe(_schemas_js_1.UnsignedInteger, v.description("Closing timestamp (ms since epoch).")), /** Asset symbol. */ s: v.pipe(v.string(), v.description("Asset symbol.")), /** Time interval. */ i: v.pipe(v.picklist(["1m", "3m", "5m", "15m", "30m", "1h", "2h", "4h", "8h", "12h", "1d", "3d", "1w", "1M"]), v.description("Time interval.")), /** Opening price. */ o: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Opening price.")), /** Closing price. */ c: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Closing price.")), /** Highest price. */ h: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Highest price.")), /** Lowest price. */ l: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Lowest price.")), /** Total volume traded in base currency. */ v: v.pipe(_schemas_js_1.UnsignedDecimal, v.description("Total volume traded in base currency.")), /** Number of trades executed. */ n: v.pipe(_schemas_js_1.UnsignedInteger, v.description("Number of trades executed.")), }), v.description("Candlestick data point."))), v.description("Array of candlestick data points.")); })(); /** * Request candlestick snapshots. * * @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 candlestick data points. * * @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 { candleSnapshot } from "@nktkas/hyperliquid/api/info"; * * const transport = new HttpTransport(); // or `WebSocketTransport` * * const data = await candleSnapshot( * { transport }, * { coin: "ETH", interval: "1h", startTime: Date.now() - 1000 * 60 * 60 * 24 }, * ); * ``` * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#candle-snapshot */ function candleSnapshot(config, params, signal) { const request = v.parse(exports.CandleSnapshotRequest, { type: "candleSnapshot", req: params, }); return config.transport.request("info", request, signal); } //# sourceMappingURL=candleSnapshot.js.map