• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nktkas / hyperliquid / 17932585565

23 Sep 2025 12:11AM UTC coverage: 96.069% (+5.5%) from 90.582%
17932585565

push

github

nktkas
feat!: tree shaking support (~50% less size)

all API methods were moved to separate files and a new import point `/api` was added

breaking changes:
- import point `/schemas` replaced with `/api/[info,exchange,subscription]`
- standardization of typescript types to single pattern: [api name] + [Request,Response,Event,Parameters,Options,Types]
- private key directly supported only when creating a client instance

365 of 553 branches covered (66.0%)

Branch coverage included in aggregate %.

13134 of 13495 new or added lines in 148 files covered. (97.32%)

13173 of 13539 relevant lines covered (97.3%)

613.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/src/api/subscription/allMids.ts
1
import * as v from "valibot";
328✔
2
import { type DeepImmutable, parser, UnsignedDecimal } from "../_common.ts";
328✔
3
import type { SubscriptionRequestConfig } from "./_common.ts";
4
import type { Subscription } from "../../transport/base.ts";
5

6
// -------------------- Schemas --------------------
7

8
/** Subscription to mid price events for all coins. */
9
export const AllMidsRequest = /* @__PURE__ */ (() => {
328✔
10
  return v.pipe(
555✔
11
    v.object({
555✔
12
      /** Type of subscription. */
13
      type: v.pipe(
555✔
14
        v.literal("allMids"),
555✔
15
        v.description("Type of subscription."),
555✔
16
      ),
17
      /** DEX name (empty string for main dex). */
18
      dex: v.pipe(
555✔
19
        v.optional(v.string()),
555✔
20
        v.description("DEX name (empty string for main dex)."),
555✔
21
      ),
22
    }),
555✔
23
    v.description("Subscription to mid price events for all coins."),
555✔
24
  );
25
})();
328✔
26
export type AllMidsRequest = v.InferOutput<typeof AllMidsRequest>;
27

28
/** Event of mid prices for all assets. */
29
export const AllMidsEvent = /* @__PURE__ */ (() => {
328✔
30
  return v.pipe(
555✔
31
    v.object({
555✔
32
      /** Mapping of coin symbols to mid prices. */
33
      mids: v.pipe(
555✔
34
        v.record(v.string(), UnsignedDecimal),
555✔
35
        v.description("Mapping of coin symbols to mid prices."),
555✔
36
      ),
37
    }),
555✔
38
    v.description("Event of mid prices for all assets."),
555✔
39
  );
40
})();
328✔
41
export type AllMidsEvent = v.InferOutput<typeof AllMidsEvent>;
42

43
// -------------------- Function --------------------
44

45
/** Request parameters for the {@linkcode allMids} function. */
46
export type AllMidsParameters = Omit<v.InferInput<typeof AllMidsRequest>, "type">;
47

48
/**
49
 * Subscribe to mid prices for all actively traded assets.
50
 * @param config - General configuration for Subscription API subscriptions.
51
 * @param params - Parameters specific to the API subscription.
52
 * @param listener - A callback function to be called when the event is received.
53
 * @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
54
 *
55
 * @throws {TransportError} When the transport layer throws an error.
56
 *
57
 * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
58
 * @example
59
 * ```ts
60
 * import { WebSocketTransport } from "@nktkas/hyperliquid";
61
 * import { allMids } from "@nktkas/hyperliquid/api/subscription";
62
 *
63
 * const transport = new WebSocketTransport();
64
 *
65
 * const sub = await allMids(
66
 *   { transport },
67
 *   (data) => console.log(data),
68
 * );
69
 * ```
70
 */
71
export function allMids(
72
  config: SubscriptionRequestConfig,
73
  listener: (data: AllMidsEvent) => void,
74
): Promise<Subscription>;
75
export function allMids(
76
  config: SubscriptionRequestConfig,
77
  params: DeepImmutable<AllMidsParameters>,
78
  listener: (data: AllMidsEvent) => void,
79
): Promise<Subscription>;
80
export function allMids(
328✔
81
  config: SubscriptionRequestConfig,
328✔
82
  paramsOrListener: DeepImmutable<AllMidsParameters> | ((data: AllMidsEvent) => void),
328✔
83
  maybeListener?: (data: AllMidsEvent) => void,
328✔
84
): Promise<Subscription> {
NEW
85
  const params = typeof paramsOrListener === "function" ? {} : paramsOrListener;
×
NEW
86
  const listener = typeof paramsOrListener === "function" ? paramsOrListener : maybeListener!;
×
87

88
  const payload = parser(AllMidsRequest)({ type: "allMids", ...params });
1,316✔
89
  return config.transport.subscribe<AllMidsEvent>(payload.type, payload, (e) => {
329✔
90
    listener(e.detail);
331✔
91
  });
329✔
92
}
329✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc