Skip to main content

hyperliquid-position-csv

Zero-dependency Python (decimal.Decimal) & JavaScript (ESM) library + CLI to reconstruct flat-to-flat perpetual position cycles (0 → position → 0) from Hyperliquid's public userFills endpoint and export clean RFC-4180 CSV summaries.


Python Installation & Quick Start

pip install hyperliquid-position-csv
hl-position-csv --address 0x... > positions.csv
from hyperliquid_position_csv import group_position_cycles, cycles_to_csv

cycles = group_position_cycles(raw_fills)
print(cycles_to_csv(cycles))

Why Reconstruct Position Cycles?

Hyperliquid's public POST https://api.hyperliquid.xyz/info ({"type": "userFills", "user": "0x..."}) returns up to 2,000 individual order execution fragments. A single position entered across 15 partial maker fills and closed across 12 taker fills appears as 27 separate rows, and a single flip order crossing zero splits across two logical trades.

hyperliquid-position-csv groups raw fills per market (preserving both native perpetuals like BTC and HIP-3 namespaced builder markets like xyz:NVDA) into clean position cycles:

  • Exact BigInt 18-decimal fixed-point math — no IEEE-754 floating-point precision drift on sizes, fees, or realized PnL.
  • Honest window boundaries — if a wallet's 2,000-fill history starts mid-position (startPosition != 0), complete is marked false rather than fabricating an entry price.
  • Single-fill reversals handled — orders that cross through 0 close the prior cycle cleanly and open a new opposite-side cycle.

Usage

1. CLI (Export any 0x wallet directly to CSV)

# Fetch live public fills for a Hyperliquid wallet and write CSV
node ./bin/cli.mjs 0x0000000000000000000000000000000000000000 --out positions.csv

# Or reconstruct offline from a saved userFills JSON array
node ./bin/cli.mjs --input ./sample-fills.json --out positions.csv

2. ESM Library

import { fetchHyperliquidUserFills, groupPositionCycles, cyclesToCsv } from './src/index.mjs';

const fills = await fetchHyperliquidUserFills('0x...');
const cycles = groupPositionCycles(fills);
console.log(cyclesToCsv(cycles));

Output CSV Columns

Column Description
coin Perpetual symbol (e.g. BTC, ETH, or HIP-3 namespace:SYMBOL)
side long or short
status closed (returned to 0) or open
opened_at / closed_at ISO-8601 timestamps (blank if outside the 2,000-fill window)
opened_size / closed_size Total base quantity opened and closed within the cycle
avg_entry_px / avg_exit_px Volume-weighted average entry and exit prices
realized_pnl Sum of closedPnl across all executions in the cycle
fees / fee_token Total execution fees and fee currency
fills_count Number of partial fills aggregated into this cycle
complete true only when both flat entry (0 → pos) and flat exit (pos → 0) are inside the loaded history

License

MIT © HoldWins

Metadata

Release files for hyperliquid-position-csv 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hyperliquid-position-csv 1.0.0
File Size Uploaded Provenance Actions
hyperliquid_position_csv-1.0.0.tar.gz 6.6 kB Without provenance Details for hyperliquid_position_csv-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hyperliquid-position-csv 1.0.0
File Interpreter ABI Platform Actions
hyperliquid_position_csv-1.0.0-py3-none-any.whl Python 3 none any Details for hyperliquid_position_csv-1.0.0-py3-none-any.whl

Total release size: 15.0 kB

Release files / hyperliquid_position_csv-1.0.0.tar.gz

Download URL hyperliquid_position_csv-1.0.0.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
735b2b4f6787f5ef363c9f72778d2b602501d725254f2c71478fb27cecfdbcbd
BLAKE2b-256 checksum
How to use checksums
3afc2290cf083d70316c7618e40d474108f39a16f2e7c9515ca28df4b0da821e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / hyperliquid_position_csv-1.0.0-py3-none-any.whl

Download URL hyperliquid_position_csv-1.0.0-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ee5022c4285a45f2d4d917b7fe61fdc2107564d907b4902aae039900287c7946
BLAKE2b-256 checksum
How to use checksums
4ab7bebd6d712fb16bfeae5b0d933d02a780adbd4a5dcf462eb2e94e5ca5c72b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for hyperliquid-position-csv 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page