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

nktkas / hyperliquid / 18519501404

15 Oct 2025 05:40AM UTC coverage: 95.329% (-0.8%) from 96.117%
18519501404

push

github

nktkas
chore: improve internal code

- move recurring and frequently used schemas to a separate common file
- use a more live asset and update the schemaCoverage conditions in the tests
- replace `union` with `variant` in schemas (if possible)

373 of 558 branches covered (66.85%)

Branch coverage included in aggregate %.

814 of 814 new or added lines in 135 files covered. (100.0%)

6 existing lines in 3 files now uncovered.

10770 of 11131 relevant lines covered (96.76%)

651.21 hits per line

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

94.52
/src/api/info/metaAndAssetCtxs.ts
1
import * as v from "valibot";
332✔
2
import { Decimal, type DeepImmutable, parser, UnsignedDecimal } from "../_base.ts";
332✔
3
import type { InfoRequestConfig } from "./_base.ts";
4

5
import { MetaResponse } from "./meta.ts";
332✔
6

7
// -------------------- Schemas --------------------
8

9
/**
10
 * Request metadata and asset contexts.
11
 * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-perpetuals-asset-contexts-includes-mark-price-current-funding-open-interest-etc
12
 */
13
export const MetaAndAssetCtxsRequest = /* @__PURE__ */ (() => {
332✔
14
  return v.pipe(
562✔
15
    v.object({
562✔
16
      /** Type of request. */
17
      type: v.pipe(
562✔
18
        v.literal("metaAndAssetCtxs"),
562✔
19
        v.description("Type of request."),
562✔
20
      ),
21
      /** DEX name (empty string for main dex). */
22
      dex: v.pipe(
562✔
23
        v.optional(v.string()),
562✔
24
        v.description("DEX name (empty string for main dex)."),
562✔
25
      ),
26
    }),
562✔
27
    v.description("Request metadata and asset contexts."),
562✔
28
  );
29
})();
332✔
30
export type MetaAndAssetCtxsRequest = v.InferOutput<typeof MetaAndAssetCtxsRequest>;
31

32
/**
33
 * Metadata and context for perpetual assets.
34
 * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-perpetuals-asset-contexts-includes-mark-price-current-funding-open-interest-etc
35
 */
36
export const MetaAndAssetCtxsResponse = /* @__PURE__ */ (() => {
332✔
37
  return v.pipe(
562✔
38
    v.tuple([
562✔
39
      MetaResponse,
562✔
40
      /** Array of contexts for each perpetual asset. */
41
      v.pipe(
562✔
42
        v.array(
562✔
43
          /** Context for a specific perpetual asset. */
44
          v.pipe(
562✔
45
            v.object({
562✔
46
              /** Previous day's closing price. */
47
              prevDayPx: v.pipe(
562✔
48
                UnsignedDecimal,
562✔
49
                v.description("Previous day's closing price."),
562✔
50
              ),
51
              /** Daily notional volume. */
52
              dayNtlVlm: v.pipe(
562✔
53
                UnsignedDecimal,
562✔
54
                v.description("Daily notional volume."),
562✔
55
              ),
56
              /** Mark price. */
57
              markPx: v.pipe(
562✔
58
                UnsignedDecimal,
562✔
59
                v.description("Mark price."),
562✔
60
              ),
61
              /** Mid price. */
62
              midPx: v.pipe(
562✔
63
                v.nullable(UnsignedDecimal),
562✔
64
                v.description("Mid price."),
562✔
65
              ),
66
              /** Funding rate. */
67
              funding: v.pipe(
562✔
68
                Decimal,
562✔
69
                v.description("Funding rate."),
562✔
70
              ),
71
              /** Total open interest. */
72
              openInterest: v.pipe(
562✔
73
                UnsignedDecimal,
562✔
74
                v.description("Total open interest."),
562✔
75
              ),
76
              /** Premium price. */
77
              premium: v.pipe(
562✔
78
                v.nullable(Decimal),
562✔
79
                v.description("Premium price."),
562✔
80
              ),
81
              /** Oracle price. */
82
              oraclePx: v.pipe(
562✔
83
                UnsignedDecimal,
562✔
84
                v.description("Oracle price."),
562✔
85
              ),
86
              /** Array of impact prices. */
87
              impactPxs: v.pipe(
562✔
88
                v.nullable(v.array(v.string())),
562✔
89
                v.description("Array of impact prices."),
562✔
90
              ),
91
              /** Daily volume in base currency. */
92
              dayBaseVlm: v.pipe(
562✔
93
                UnsignedDecimal,
562✔
94
                v.description("Daily volume in base currency."),
562✔
95
              ),
96
            }),
562✔
97
            v.description("Context for a specific perpetual asset."),
562✔
98
          ),
99
        ),
100
        v.description("Array of contexts for each perpetual asset."),
562✔
101
      ),
102
    ]),
562✔
103
    v.description("Metadata and context for perpetual assets."),
562✔
104
  );
105
})();
332✔
106
export type MetaAndAssetCtxsResponse = v.InferOutput<typeof MetaAndAssetCtxsResponse>;
107

108
// -------------------- Function --------------------
109

110
/** Request parameters for the {@linkcode metaAndAssetCtxs} function. */
111
export type MetaAndAssetCtxsParameters = Omit<v.InferInput<typeof MetaAndAssetCtxsRequest>, "type">;
112

113
/**
114
 * Request metadata and asset contexts.
115
 * @param config - General configuration for Info API requests.
116
 * @param signal - An [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) can be used to cancel the request by calling [`abort()`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort) on the corresponding [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
117
 * @returns Metadata and context for perpetual assets.
118
 *
119
 * @throws {TransportError} When the transport layer throws an error.
120
 *
121
 * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-perpetuals-asset-contexts-includes-mark-price-current-funding-open-interest-etc
122
 * @example
123
 * ```ts
124
 * import { HttpTransport } from "@nktkas/hyperliquid";
125
 * import { metaAndAssetCtxs } from "@nktkas/hyperliquid/api/info";
126
 *
127
 * const transport = new HttpTransport(); // or `WebSocketTransport`
128
 * const data = await metaAndAssetCtxs({ transport });
129
 * ```
130
 */
131
export function metaAndAssetCtxs(
132
  config: InfoRequestConfig,
133
  params?: DeepImmutable<MetaAndAssetCtxsParameters>,
134
  signal?: AbortSignal,
135
): Promise<MetaAndAssetCtxsResponse>;
136
export function metaAndAssetCtxs(
137
  config: InfoRequestConfig,
138
  signal?: AbortSignal,
139
): Promise<MetaAndAssetCtxsResponse>;
140
export function metaAndAssetCtxs(
332✔
141
  config: InfoRequestConfig,
332✔
142
  paramsOrSignal?: DeepImmutable<MetaAndAssetCtxsParameters> | AbortSignal,
332✔
143
  maybeSignal?: AbortSignal,
332✔
144
): Promise<MetaAndAssetCtxsResponse> {
UNCOV
145
  const params = paramsOrSignal instanceof AbortSignal ? {} : paramsOrSignal;
×
UNCOV
146
  const signal = paramsOrSignal instanceof AbortSignal ? paramsOrSignal : maybeSignal;
×
147

148
  const request = parser(MetaAndAssetCtxsRequest)({
355✔
149
    type: "metaAndAssetCtxs",
355✔
150
    ...params,
355✔
151
  });
355✔
152
  return config.transport.request("info", request, signal);
355✔
153
}
355✔
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