@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
134 lines • 6.49 kB
JavaScript
"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.UserTwapSliceFillsResponse = exports.UserTwapSliceFillsRequest = void 0;
exports.userTwapSliceFills = userTwapSliceFills;
const v = __importStar(require("valibot"));
// ============================================================
// API Schemas
// ============================================================
const _schemas_js_1 = require("../../_schemas.js");
/**
* Request user TWAP slice fills.
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-users-twap-slice-fills
*/
exports.UserTwapSliceFillsRequest = (() => {
return v.pipe(v.object({
/** Type of request. */
type: v.pipe(v.literal("userTwapSliceFills"), v.description("Type of request.")),
/** User address. */
user: v.pipe(_schemas_js_1.Address, v.description("User address.")),
}), v.description("Request user TWAP slice fills."));
})();
/**
* Array of user's twap slice fills.
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-users-twap-slice-fills
*/
exports.UserTwapSliceFillsResponse = (() => {
return v.pipe(v.array(
/** User twap slice fill. */
v.pipe(v.object({
/** TWAP fill record. */
fill: 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(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("TWAP fill record.")),
/** ID of the TWAP. */
twapId: v.pipe(_schemas_js_1.UnsignedInteger, v.description("ID of the TWAP.")),
}), v.description("User twap slice fill."))), v.description("Array of user's twap slice fills."));
})();
/**
* Request user TWAP slice fills.
*
* @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 user's twap slice fills.
*
* @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 { userTwapSliceFills } from "@nktkas/hyperliquid/api/info";
*
* const transport = new HttpTransport(); // or `WebSocketTransport`
*
* const data = await userTwapSliceFills(
* { transport },
* { user: "0x..." },
* );
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-users-twap-slice-fills
*/
function userTwapSliceFills(config, params, signal) {
const request = v.parse(exports.UserTwapSliceFillsRequest, {
type: "userTwapSliceFills",
...params,
});
return config.transport.request("info", request, signal);
}
//# sourceMappingURL=userTwapSliceFills.js.map