Skip to main content

Python client for AI Price Patterns API - Search engine for financial price action

Project description

AI Price Patterns Python SDK (aipp)

The official Python client for AI Price Patterns - the search engine for financial price action.

Source Code | Bug Tracker

This library allows Quants and Traders to programmatically access our pattern matching engine, run walk-forward backtests, and integrate "Market Memory" into their existing ML and Reinforcement Learning pipelines.

Installation

# Basic installation
pip install aipricepatterns

# With Reinforcement Learning support
pip install "aipricepatterns[rl]"

# With Research/Notebook support
pip install "aipricepatterns[research]"

Quick Start

1. Initialize Client

from aipricepatterns import Client

# Connect to the public API (or your on-premise instance)
# Default base_url is https://aipricepatterns.com/api/rust
client = Client()

2. Find Similar Patterns (Idea Generation)

Find historical analogues for the current BTC price action.

# Search for patterns similar to the last 60 hours of BTCUSDT
results = client.search(symbol="BTCUSDT", interval="1h", q=60, top_k=5)

print(f"Found {len(results['matches'])} matches.")
for match in results['matches']:
    print(f"Date: {match['date']}, Similarity: {match['similarity']:.2f}%")

3. Run a Walk-Forward Backtest (Validation)

Validate the predictive power of the pattern engine on historical data.

# Run a simulation on the last 50,000 bars
bt = client.backtest(
    symbol="BTCUSDT",
    interval="1h",
    q=60,
    f=24,
    min_prob=0.6,  # Only trade if >60% probability
    include_stats=True
)

# Convert to Pandas for analysis
df = client.backtest_to_df(bt)
equity = client.equity_curve_to_df(bt)

print(f"Total Return: {bt['stats']['totalReturnPct']:.2f}%")
print(f"Sharpe Ratio: {bt['stats']['sharpeRatio']:.2f}")

# Plot equity curve (using Plotly)
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scatter(x=equity.index, y=equity['equity'], name='Equity'))
fig.show()

4. Reinforcement Learning (Market Memory)

Train agents on historical episodes retrieved by the pattern engine.

# Fetch 1000 historical episodes similar to the current market state
episodes = client.get_rl_simple(
    symbol="BTCUSDT",
    interval="1h",
    num_episodes=1000
)

# Use these episodes to "warm up" your RL agent
# See examples/rl/ for full implementation

Project Structure

  • src/aipricepatterns: Core SDK source code.
  • examples/: Practical scripts and notebooks for traders.
  • research/: Advanced quant research notebooks (Plotly-based).
  • showcase/: Ready-to-use demo playbooks for different market scenarios.

CLI (aipp)

When installed, the package provides a console command aipp.

Examples:

Tip: you can set default friction for backtests via env vars:

export AIPP_FEE_PCT="0.04"
export AIPP_SLIPPAGE_PCT="0.02"
# Pattern search
aipp --base-url https://aipricepatterns.com/api/rust search --symbol BTCUSDT --interval 1h --q 60 --f 30 --limit 20

# Watchlist heartbeat (GO/NO-GO)
aipp --base-url https://aipricepatterns.com/api/rust scan \
    --symbols BTCUSDT,ETHUSDT,SOLUSDT \
    --interval 1h --q 60 --f 24 --limit 16 \
    --block-regimes BEARISH_MOMENTUM,STABLE_DOWNTREND \
    --no-stability \
    --grid-hint --grid-hint-human

# Repeat scan every 60 seconds
aipp --base-url https://aipricepatterns.com/api/rust scan --symbols BTCUSDT,ETHUSDT --interval 1h --watch --every 60

# Backtest (walk-forward) with realistic costs
aipp --base-url https://aipricepatterns.com/api/rust backtest \
    --symbol BTCUSDT --interval 1h --q 24 --f 12 --step 24 \
    --fee-pct 0.04 --slippage-pct 0.02

# Micro-validation for a specific moment (timestamp in ms)
aipp --base-url https://aipricepatterns.com/api/rust backtest-specific \
    --symbol BTCUSDT --interval 1h --q 24 --f 12 \
    --timestamp 1710000000000 \
    --fee-pct 0.04 --slippage-pct 0.02

# RL: get "parallel universe" episodes for context-aware RL (recommended: anchor-ts)
aipp --base-url https://aipricepatterns.com/api/rust rl-episodes \
    --symbol BTCUSDT --interval 1h \
    --anchor-ts 1678406400000 \
    --forecast-horizon 24 --num-episodes 50 --min-similarity 0.80

# RL: get flattened (s, r, s', d) arrays for offline RL
aipp --base-url https://aipricepatterns.com/api/rust rl-training-batch \
    --symbol BTCUSDT --interval 1h \
    --query-length 40 --forecast-horizon 24 \
    --batch-size 1000 --min-similarity 0.70

Features

  • Pattern Search: Find nearest neighbors in high-dimensional space using HNSW.
  • Walk-Forward Backtesting: Strict, look-ahead bias free simulation.
  • Pandas Integration: Native support for DataFrames.
  • Regime Awareness: Detect current regimes and use them in aipp scan / aipp audit.

Requirements

  • Python 3.7+
  • pandas
  • requests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aipricepatterns-0.1.0.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aipricepatterns-0.1.0-py3-none-any.whl (22.8 kB view details)

Uploaded Python 3

File details

Details for the file aipricepatterns-0.1.0.tar.gz.

File metadata

  • Download URL: aipricepatterns-0.1.0.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for aipricepatterns-0.1.0.tar.gz
Algorithm Hash digest
SHA256 17bce9280054e82ebd31f5dd04090263e5b10308d62fd13f101b4918213ec10d
MD5 674110f129983ac37ceb3cfe729ff803
BLAKE2b-256 3f3eaed0d21ad3f7613552ca46b74b9ecfafe41afe53143bd5df46149fe280ea

See more details on using hashes here.

File details

Details for the file aipricepatterns-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aipricepatterns-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9783ef3881cd94169e3dac9502bc7ad9d6ae082eaedbdb717031db17a05b6f0
MD5 315c272307b970a63197deb47ad2b9a7
BLAKE2b-256 d4edd7d04a0fa54931bb0d208af536c1324e3a34dbf4875f1d542f5193110dfe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page