@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
74 lines • 3.04 kB
JavaScript
import * as v from "valibot";
// ============================================================
// API Schemas
// ============================================================
import { Address, Hex, UnsignedDecimal, UnsignedInteger } from "../../_schemas.js";
/**
* Request recent trades.
*/
export const RecentTradesRequest = /* @__PURE__ */ (() => {
return v.pipe(v.object({
/** Type of request. */
type: v.pipe(v.literal("recentTrades"), v.description("Type of request.")),
/** Asset symbol (e.g., BTC). */
coin: v.pipe(v.string(), v.description("Asset symbol (e.g., BTC).")),
}), v.description("Request recent trades."));
})();
/**
* Array of recent trades.
*/
export const RecentTradesResponse = /* @__PURE__ */ (() => {
return v.pipe(v.array(
/** Trade for a specific asset. */
v.pipe(v.object({
/** Asset symbol (e.g., BTC). */
coin: v.pipe(v.string(), v.description("Asset symbol (e.g., BTC).")),
/** Trade side ("B" = Bid/Buy, "A" = Ask/Sell). */
side: v.pipe(v.picklist(["B", "A"]), v.description('Trade side ("B" = Bid/Buy, "A" = Ask/Sell).')),
/** Trade price. */
px: v.pipe(UnsignedDecimal, v.description("Trade price.")),
/** Trade size. */
sz: v.pipe(UnsignedDecimal, v.description("Trade size.")),
/** Trade timestamp (in ms since epoch). */
time: v.pipe(UnsignedInteger, v.description("Trade timestamp (in ms since epoch).")),
/** Transaction hash. */
hash: v.pipe(v.pipe(Hex, v.length(66)), v.description("Transaction hash.")),
/** Trade ID. */
tid: v.pipe(UnsignedInteger, v.description("Trade ID.")),
/** Addresses of users involved in the trade [Maker, Taker]. */
users: v.pipe(v.tuple([Address, Address]), v.description("Addresses of users involved in the trade [Maker, Taker].")),
}), v.description("Trade for a specific asset."))), v.description("Array of recent trades."));
})();
/**
* Request recent trades.
*
* @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 recent trades.
*
* @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 { recentTrades } from "@nktkas/hyperliquid/api/info";
*
* const transport = new HttpTransport(); // or `WebSocketTransport`
*
* const data = await recentTrades(
* { transport },
* { coin: "ETH" },
* );
* ```
*/
export function recentTrades(config, params, signal) {
const request = v.parse(RecentTradesRequest, {
type: "recentTrades",
...params,
});
return config.transport.request("info", request, signal);
}
//# sourceMappingURL=recentTrades.js.map