View Source mix hyperliquid.gen.schemas (hyperliquid v0.4.1)

Generates Elixir Ecto schemas from the @nktkas/hyperliquid TypeScript SDK.

This task helps maintain type parity between the TypeScript SDK and the Elixir implementation by parsing Valibot schemas and generating equivalent Ecto schemas.

Usage

# Generate all schemas
mix hyperliquid.gen.schemas

# Generate specific category
mix hyperliquid.gen.schemas --category=subscription

# Generate specific endpoint
mix hyperliquid.gen.schemas --endpoint=webData2

# Dry run (don't write files)
mix hyperliquid.gen.schemas --dry-run

Options

  • --category - Generate schemas for a specific category (info, exchange, subscription)
  • --endpoint - Generate schema for a specific endpoint
  • --dry-run - Show what would be generated without writing files
  • --ts-sdk-path - Path to the TypeScript SDK repository (default: ../../../@nktkas_hyperliquid)

Examples

# Generate all subscription schemas
mix hyperliquid.gen.schemas --category=subscription

# Generate only webData2 schema
mix hyperliquid.gen.schemas --endpoint=webData2 --category=subscription

# Preview changes without writing
mix hyperliquid.gen.schemas --dry-run

Architecture

This generator:

  1. Reads TypeScript files from the @nktkas/hyperliquid SDK
  2. Parses Valibot schemas to extract type information
  3. Generates Elixir Ecto embedded schemas
  4. Writes single-file modules with all nested schemas
  5. Tracks SDK version for future sync checks

Type Mapping

The following TypeScript/Valibot types are mapped to Elixir/Ecto:

  • v.string() → :string
  • v.number() / UnsignedInteger → :integer
  • v.boolean() → :boolean
  • UnsignedDecimal / Decimal → :string (for precision)
  • v.array(...) → {:array, type} or embeds_many
  • v.object(...) → embeds_one or embeds_many
  • v.record(...) → :map
  • v.union([...]) → :string with validation
  • Address → :string with regex validation
  • Hex → :string

Generated File Structure

lib/hyperliquid/api/
├── info/
│   ├── all_mids.ex
│   ├── clearinghouse_state.ex
│   └── ...
├── exchange/
│   ├── order.ex
│   ├── cancel.ex
│   └── ...
└── subscription/
    ├── web_data2.ex
    ├── web_data3.ex
    └── ...

Each file contains:

  • Request parameter schema
  • Response/Event schema with embedded nested types
  • Changesets for validation
  • Helper functions
  • Usage examples in @moduledoc

Summary

Functions

Callback implementation for Mix.Task.run/1.

Functions

Callback implementation for Mix.Task.run/1.