Metadata-Version: 2.5
Name: llama-index-tools-aperiodic
Version: 0.1.0
Summary: llama-index tools aperiodic integration: point-in-time perpetual futures market data
Project-URL: Homepage, https://aperiodic.io
Project-URL: Repository, https://github.com/aperiodic-io/llama-index-tools-aperiodic
Author-email: Aperiodic <info@aperiodic.io>
License-Expression: MIT
License-File: LICENSE
Requires-Python: <4.0,>=3.11
Requires-Dist: aperiodic[pandas]<5.0.0,>=4.5.0
Requires-Dist: httpx>=0.25.0
Requires-Dist: llama-index-core<0.15,>=0.13.0
Requires-Dist: pandas>=2.0.0
Description-Content-Type: text/markdown

# Aperiodic Tool

This tool connects LlamaIndex agents to [Aperiodic](https://aperiodic.io): point-in-time market microstructure, liquidity and order-flow data for perpetual futures on Binance, OKX and Hyperliquid (crypto, tokenized stocks, indices and commodities, delisted contracts included). It uses the [`aperiodic`](https://github.com/aperiodic-io/client) Python client.

Each tool answers with a compact JSON summary (row count, first and last interval, per-column statistics and the last few rows), not the full series, so a result fits in a model's context.

## Usage

```bash
pip install llama-index-tools-aperiodic
export APERIODIC_API_KEY="your-api-key"  # make a key at https://aperiodic.io/home/api
```

Without a key the tools use Aperiodic's public preview, which serves only a small fixed sample (see <https://aperiodic.io/catalog#preview>). A free account key covers a fixed sample of markets and dates; plans are listed at <https://aperiodic.io/pricing>.

```python
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
from llama_index.tools.aperiodic import AperiodicToolSpec

tool_spec = AperiodicToolSpec()  # reads APERIODIC_API_KEY

agent = FunctionAgent(
    tools=tool_spec.to_tool_list(),
    llm=OpenAI(model="gpt-4.1"),
)

print(await agent.run("How did BTC funding on Binance move in May 2025?"))
```

## Tools

`AperiodicToolSpec` exposes four tools, with the same names and arguments as [`langchain-aperiodic`](https://github.com/aperiodic-io/langchain-aperiodic):

| Tool | What it returns |
| --- | --- |
| `aperiodic_symbol_search` | Symbol ids for an asset across the three venues, with the first and last day Aperiodic holds data for each. |
| `aperiodic_ohlcv` | OHLCV bars for one contract and date range. |
| `aperiodic_derivatives` | `funding`, `open_interest`, `basis` or `derivative_price` for one contract. |
| `aperiodic_metrics` | Order flow, liquidity and microstructure metrics (`flow`, `impact`, `slippage`, `l1_liquidity`, `l2_imbalance` and others). |

Symbols are Atlas ids such as `perpetual-BTC-USDT:USDT` (Binance, OKX), `perpetual-BTC-USDC:USDC` (Hyperliquid) or `perpetual-XYZ:TSLA-USDC:USDC` (a Hyperliquid HIP-3 market). Dates are UTC days, `end_date` inclusive.

Errors from the API (an unknown symbol, a request outside the key's plan, a preview refusal) and invalid arguments are returned as the tool's text, so the agent can correct its next call. Unexpected errors are raised.

## Options

```python
AperiodicToolSpec(
    api_key=None,        # else APERIODIC_API_KEY, else the key saved by aperiodic.login()
    preview=None,        # None: key if found, else preview. True: always preview. False: require a key
    max_bars=250_000,    # refuse requests that would return more rows than this
    cache_seconds=3600,  # how long symbol lists are reused
)
```

To work with the full data, call the client directly (`aperiodic.get_ohlcv`, `aperiodic.get_derivative_metrics`, `aperiodic.get_metrics`).

## Development

```bash
uv run -- pytest
```

The unit tests replace the client with a fake and make no network calls.
