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

nktkas / hyperliquid / 21729335997

05 Feb 2026 09:33PM UTC coverage: 92.652% (-2.8%) from 95.464%
21729335997

push

github

nktkas
test: weaken coverage testing of schemas

613 of 806 branches covered (76.05%)

Branch coverage included in aggregate %.

9210 of 9796 relevant lines covered (94.02%)

883.4 hits per line

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

88.57
/src/api/subscription/_methods/allMids.ts
1
import * as v from "@valibot/valibot";
388✔
2

3
// ============================================================
4
// API Schemas
5
// ============================================================
6

7
import { AllMidsResponse } from "../../info/_methods/allMids.ts";
388✔
8

9
/** Subscription to mid price events for all coins. */
10
export const AllMidsRequest = /* @__PURE__ */ (() => {
388✔
11
  return v.object({
658✔
12
    /** Type of subscription. */
13
    type: v.literal("allMids"),
658✔
14
    /** DEX name (empty string for main dex). */
15
    dex: v.optional(v.string()),
658✔
16
  });
658✔
17
})();
388✔
18
export type AllMidsRequest = v.InferOutput<typeof AllMidsRequest>;
19

20
/** Event of mid prices for all assets. */
21
export const AllMidsEvent = /* @__PURE__ */ (() => {
388✔
22
  return v.object({
658✔
23
    /** Mapping of coin symbols to mid prices. */
24
    mids: AllMidsResponse,
658✔
25
    /** DEX name (empty string for main dex). */
26
    dex: v.optional(v.string()),
658✔
27
  });
658✔
28
})();
388✔
29
export type AllMidsEvent = v.InferOutput<typeof AllMidsEvent>;
30

31
// ============================================================
32
// Execution Logic
33
// ============================================================
34

35
import type { SubscriptionConfig } from "./_types.ts";
36
import type { ISubscription } from "../../../transport/mod.ts";
37

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

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

85
  const payload = v.parse(AllMidsRequest, {
390✔
86
    type: "allMids",
390✔
87
    ...params,
390✔
88
    dex: params.dex || undefined, // same value as in response
390✔
89
  });
390✔
90
  return config.transport.subscribe<AllMidsEvent>(payload.type, payload, (e) => {
390✔
91
    if (e.detail.dex === payload.dex) {
430✔
92
      listener(e.detail);
450✔
93
    }
450✔
94
  });
390✔
95
}
390✔
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