Skip to content

SDK Recipes

Common patterns for working with HypQuant data in Python.


Convert to pandas

with MarketData(api_key="qp_...") as md:
    df = md.ohlcv("BTC-USDC", exchange="hyperliquid", timeframe="1h",
                  start="2024-01-01", as_pandas=True)
    print(type(df))  # <class 'pandas.core.frame.DataFrame'>

Or convert a polars DataFrame manually:

df_polars = md.ohlcv("BTC-USDC", exchange="hyperliquid", timeframe="1h", start="2024-01-01")
df_pandas = df_polars.to_pandas()

Save to CSV / Parquet

df = md.ohlcv("BTC-USDC", exchange="hyperliquid", timeframe="1h", start="2024-01-01")

# CSV
df.write_csv("btc_1h.csv")

# Parquet (recommended for large datasets)
df.write_parquet("btc_1h.parquet")

# Read back
import polars as pl
df = pl.read_parquet("btc_1h.parquet")

Join OHLCV with features

import polars as pl
from hypquant import MarketData

with MarketData(api_key="qp_...") as md:
    ohlcv = md.ohlcv("BTC-USDC", exchange="hyperliquid", timeframe="1h", start="2024-01-01")
    feat = md.features(
        "BTC-USDC", exchange="hyperliquid", timeframe="1h",
        features=["rsi_14", "macd", "atr_14"],
        start="2024-01-01",
    )

combined = ohlcv.join(feat, on="time", how="left")
print(combined.columns)
# ['time', 'open', 'high', 'low', 'close', 'volume', 'rsi_14', 'macd', 'atr_14']

Correlation matrix across assets

import polars as pl
from hypquant import MarketData

with MarketData(api_key="qp_...") as md:
    df = md.multi_asset(
        symbols=["BTC-USDC", "ETH-USDC", "SOL-USDC", "ARB-USDC"],
        exchange="hyperliquid",
        timeframe="1h",
        field="close",
        start="2024-01-01",
        end="2024-06-01",
    )

# Drop the time column, compute correlation
corr = df.select(pl.exclude("time")).to_pandas().corr()
print(corr.round(3))

Parallel async fetch for multiple symbols

import asyncio
from hypquant import AsyncMarketData

SYMBOLS = ["BTC-USDC", "ETH-USDC", "SOL-USDC", "ARB-USDC", "OP-USDC"]

async def fetch_all():
    async with AsyncMarketData(api_key="qp_...") as md:
        tasks = [
            md.ohlcv(sym, exchange="hyperliquid", timeframe="1h", start="2024-01-01")
            for sym in SYMBOLS
        ]
        results = await asyncio.gather(*tasks)
    return dict(zip(SYMBOLS, results))

dfs = asyncio.run(fetch_all())

Check DQS before backtesting

from hypquant import MarketData

SYMBOLS = ["BTC-USDC", "ETH-USDC", "SOL-USDC"]

with MarketData(api_key="qp_...") as md:
    for sym in SYMBOLS:
        q = md.quality(sym, exchange="hyperliquid", timeframe="1h")
        dqs = float(q["timeframes"]["1h"]["dqs"])
        if dqs < 0.90:
            print(f"WARNING: {sym} DQS={dqs:.3f} — data quality may affect results")
        else:
            print(f"OK: {sym} DQS={dqs:.3f}")

RSI-based signal generation

import polars as pl
from hypquant import MarketData

with MarketData(api_key="qp_...") as md:
    feat = md.features(
        "BTC-USDC", exchange="hyperliquid", timeframe="1h",
        features=["rsi_14"],
        start="2024-01-01",
        end="2024-06-01",
    )

signals = feat.with_columns([
    pl.when(pl.col("rsi_14") < 30).then(pl.lit("oversold"))
      .when(pl.col("rsi_14") > 70).then(pl.lit("overbought"))
      .otherwise(pl.lit("neutral"))
      .alias("signal")
])

oversold_count = (signals["signal"] == "oversold").sum()
print(f"Oversold periods: {oversold_count}")

Funding arbitrage signal

from hypquant import MarketData

with MarketData(api_key="qp_...") as md:
    df = md.funding(
        "BTC-USDC",
        exchange="hyperliquid",
        start="2024-01-01",
        normalized=True,
    )

# High positive funding: consider shorting perp + buying spot
extreme = df.filter(df["rate_normalized"] > 2.0)
print(f"Extreme funding periods (z>2): {len(extreme)}")
print(extreme.tail(5))