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

nktkas / hyperliquid / 22525620077

28 Feb 2026 05:36PM UTC coverage: 94.608% (+2.0%) from 92.652%
22525620077

push

github

nktkas
test(exchange/topUpIsolatedOnlyMargin): update asset

606 of 778 branches covered (77.89%)

Branch coverage included in aggregate %.

7640 of 7938 relevant lines covered (96.25%)

724.64 hits per line

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

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

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

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

9
/**
10
 * Subscription to mid price events for all coins.
11
 * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
12
 */
13
export const AllMidsRequest = /* @__PURE__ */ (() => {
157✔
14
  return v.object({
314✔
15
    /** Type of subscription. */
16
    type: v.literal("allMids"),
314✔
17
    /** DEX name (empty string for main dex). */
18
    dex: v.optional(v.string()),
314✔
19
  });
314✔
20
})();
157✔
21
export type AllMidsRequest = v.InferOutput<typeof AllMidsRequest>;
22

23
/**
24
 * Event of mid prices for all assets.
25
 * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
26
 */
27
export type AllMidsEvent = {
28
  /** Mapping of coin symbols to mid prices. */
29
  mids: AllMidsResponse;
30
  /** DEX name (empty string for main dex). */
31
  dex?: string;
32
};
33

34
// ============================================================
35
// Execution Logic
36
// ============================================================
37

38
import { parse } from "../../../_base.ts";
157✔
39
import type { ISubscription } from "../../../transport/mod.ts";
40
import type { SubscriptionConfig } from "./_types.ts";
41

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

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

88
  const payload = parse(AllMidsRequest, {
159✔
89
    type: "allMids",
159✔
90
    ...params,
159✔
91
    dex: params.dex || undefined, // Same value as in response
159✔
92
  });
159✔
93
  return config.transport.subscribe<AllMidsEvent>(payload.type, payload, (e) => {
159✔
94
    if (e.detail.dex === payload.dex) {
199✔
95
      listener(e.detail);
219✔
96
    }
219✔
97
  });
159✔
98
}
159✔
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