• 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.11
/src/api/subscription/_methods/assetCtxs.ts
1
import * as v from "@valibot/valibot";
364✔
2

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

7
import { PerpAssetCtxSchema } from "../../info/_methods/_base/commonSchemas.ts";
364✔
8

9
/** Subscription to context events for all perpetual assets. */
10
export const AssetCtxsRequest = /* @__PURE__ */ (() => {
364✔
11
  return v.pipe(
618✔
12
    v.object({
618✔
13
      /** Type of subscription. */
14
      type: v.pipe(
618✔
15
        v.literal("assetCtxs"),
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 context events for all perpetual assets."),
618✔
25
  );
26
})();
364✔
27
export type AssetCtxsRequest = v.InferOutput<typeof AssetCtxsRequest>;
28

29
/** Event of asset contexts for all perpetual assets on a specified DEX. */
30
export const AssetCtxsEvent = /* @__PURE__ */ (() => {
364✔
31
  return v.pipe(
618✔
32
    v.object({
618✔
33
      /** DEX name (empty string for main dex). */
34
      dex: v.pipe(
618✔
35
        v.string(),
618✔
36
        v.description("DEX name (empty string for main dex)."),
618✔
37
      ),
38
      /** Array of context information for each perpetual asset. */
39
      ctxs: v.pipe(
618✔
40
        v.array(PerpAssetCtxSchema),
618✔
41
        v.description("Array of context information for each perpetual asset."),
618✔
42
      ),
43
    }),
618✔
44
    v.description("Event of asset contexts for all perpetual assets on a specified DEX."),
618✔
45
  );
46
})();
364✔
47
export type AssetCtxsEvent = v.InferOutput<typeof AssetCtxsEvent>;
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 assetCtxs} function. */
57
export type AssetCtxsParameters = Omit<v.InferInput<typeof AssetCtxsRequest>, "type">;
58

59
/**
60
 * Subscribe to asset contexts for all perpetual 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 { assetCtxs } from "@nktkas/hyperliquid/api/subscription";
75
 *
76
 * const transport = new WebSocketTransport(); // only `WebSocketTransport`
77
 *
78
 * const sub = await assetCtxs(
79
 *   { transport },
80
 *   (data) => console.log(data),
81
 * );
82
 * ```
83
 */
84
export function assetCtxs(
85
  config: SubscriptionConfig,
86
  listener: (data: AssetCtxsEvent) => void,
87
): Promise<ISubscription>;
88
export function assetCtxs(
89
  config: SubscriptionConfig,
90
  params: AssetCtxsParameters,
91
  listener: (data: AssetCtxsEvent) => void,
92
): Promise<ISubscription>;
93
export function assetCtxs(
364✔
94
  config: SubscriptionConfig,
364✔
95
  paramsOrListener: AssetCtxsParameters | ((data: AssetCtxsEvent) => void),
364✔
96
  maybeListener?: (data: AssetCtxsEvent) => void,
364✔
97
): Promise<ISubscription> {
UNCOV
98
  const params = typeof paramsOrListener === "function" ? {} : paramsOrListener;
×
UNCOV
99
  const listener = typeof paramsOrListener === "function" ? paramsOrListener : maybeListener!;
×
100

101
  const payload = v.parse(AssetCtxsRequest, {
365✔
102
    type: "assetCtxs",
365✔
103
    ...params,
365✔
104
    dex: params.dex ?? "", // same value as in response
365✔
105
  });
365✔
106
  return config.transport.subscribe<AssetCtxsEvent>(payload.type, payload, (e) => {
365✔
107
    if (e.detail.dex === payload.dex) {
368✔
108
      listener(e.detail);
368✔
109
    }
368✔
110
  });
365✔
111
}
365✔
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