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

nktkas / hyperliquid / 20260168111

16 Dec 2025 07:33AM UTC coverage: 95.34% (-1.3%) from 96.688%
20260168111

push

github

nktkas
docs: improve code documentation

661 of 881 branches covered (75.03%)

Branch coverage included in aggregate %.

5 of 5 new or added lines in 2 files covered. (100.0%)

151 existing lines in 17 files now uncovered.

12843 of 13283 relevant lines covered (96.69%)

1103.6 hits per line

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

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

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

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

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

29
/** Event of mid prices for all assets. */
30
export const AllMidsEvent = /* @__PURE__ */ (() => {
364✔
31
  return v.pipe(
618✔
32
    v.object({
618✔
33
      /** Mapping of coin symbols to mid prices. */
34
      mids: v.pipe(
618✔
35
        AllMidsResponse,
618✔
36
        v.description("Mapping of coin symbols to mid prices."),
618✔
37
      ),
38
      /** DEX name (empty string for main dex). */
39
      dex: v.pipe(
618✔
40
        v.optional(v.string()),
618✔
41
        v.description("DEX name (empty string for main dex)."),
618✔
42
      ),
43
    }),
618✔
44
    v.description("Event of mid prices for all assets."),
618✔
45
  );
46
})();
364✔
47
export type AllMidsEvent = v.InferOutput<typeof AllMidsEvent>;
48

49
// ============================================================
50
// Execution Logic
51
// ============================================================
52

53
import type { SubscriptionConfig } from "./_types.ts";
54
import type { ISubscription } from "../../../transport/mod.ts";
55

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

59
/**
60
 * Subscribe to mid prices for all actively traded assets.
61
 *
62
 * @param config - General configuration for Subscription API subscriptions.
63
 * @param params - Parameters specific to the API subscription.
64
 * @param listener - A callback function to be called when the event is received.
65
 *
66
 * @returns A request-promise that resolves with a {@link ISubscription} object to manage the subscription lifecycle.
67
 *
68
 * @throws {ValiError} When the request parameters fail validation (before sending).
69
 * @throws {TransportError} When the transport layer throws an error.
70
 *
71
 * @example
72
 * ```ts
73
 * import { WebSocketTransport } from "@nktkas/hyperliquid";
74
 * import { allMids } from "@nktkas/hyperliquid/api/subscription";
75
 *
76
 * const transport = new WebSocketTransport(); // only `WebSocketTransport`
77
 *
78
 * const sub = await allMids(
79
 *   { transport },
80
 *   (data) => console.log(data),
81
 * );
82
 * ```
83
 *
84
 * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
85
 */
86
export function allMids(
87
  config: SubscriptionConfig,
88
  listener: (data: AllMidsEvent) => void,
89
): Promise<ISubscription>;
90
export function allMids(
91
  config: SubscriptionConfig,
92
  params: AllMidsParameters,
93
  listener: (data: AllMidsEvent) => void,
94
): Promise<ISubscription>;
95
export function allMids(
364✔
96
  config: SubscriptionConfig,
364✔
97
  paramsOrListener: AllMidsParameters | ((data: AllMidsEvent) => void),
364✔
98
  maybeListener?: (data: AllMidsEvent) => void,
364✔
99
): Promise<ISubscription> {
UNCOV
100
  const params = typeof paramsOrListener === "function" ? {} : paramsOrListener;
×
UNCOV
101
  const listener = typeof paramsOrListener === "function" ? paramsOrListener : maybeListener!;
×
102

103
  const payload = v.parse(AllMidsRequest, {
366✔
104
    type: "allMids",
366✔
105
    ...params,
366✔
106
    dex: params.dex || undefined, // same value as in response
366✔
107
  });
366✔
108
  return config.transport.subscribe<AllMidsEvent>(payload.type, payload, (e) => {
366✔
109
    if (e.detail.dex === payload.dex) {
402✔
110
      listener(e.detail);
420✔
111
    }
420✔
112
  });
366✔
113
}
366✔
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