Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

alphasift

Foundational data-access component for Kraken OHLC data, plus minimal strategy, backtest, experiment, paper trading, and AI workflow layers that operate on normalized candles.

What this is

  • A minimal, modular data-access layer
  • A normalized OHLCV schema with local caching
  • A clean separation between HTTP client, provider logic, and IO
  • A small long/flat backtest engine driven by target positions
  • A minimal strategy layer for generating target positions
  • A minimal single-symbol long/flat paper trading simulation layer
  • A minimal local AI workflow layer for hypothesis generation, strategy drafting, and AI-planned local backtest reporting (Gemini-first)
  • A minimal local AI workflow layer for hypothesis generation, strategy drafting, and sandboxed AI code-report execution
  • A minimal local FastAPI service layer with SQLite metadata for frontend-facing orchestration
  • A thin local React frontend shell for viewing state and triggering runs

What this is not

  • Live trading or websockets
  • Databases or Docker

Setup

  1. Create and activate a virtual environment
  2. Install dependencies
  3. Copy .env.example to .env and set values if desired

Environment Variables

KRAKEN_API_KEY=
KRAKEN_API_SECRET=
KRAKEN_BASE_URL=https://api.kraken.com
DEFAULT_DATA_DIR=./data
APP_DB_PATH=./data/app/metadata.sqlite3
ARTIFACTS_DIR=./data/artifacts
API_HOST=127.0.0.1
API_PORT=8000
GEMINI_API_KEY=
GEMINI_BASE_URL=https://generativelanguage.googleapis.com/v1beta
GEMINI_MODEL_NAME=gemini-2.5-flash
GEMINI_TEMPERATURE=0.2
GEMINI_TIMEOUT_SECONDS=45
DEFAULT_AI_PROVIDER=gemini
AI_ARTIFACTS_DIR=./data/artifacts/ai
SANDBOX_DOCKER_BIN=docker
SANDBOX_IMAGE=alphasift-sandbox:latest
SANDBOX_RUNTIME=runsc
SANDBOX_TIMEOUT_SECONDS=120
SANDBOX_MEMORY_LIMIT=1024m
SANDBOX_CPU_LIMIT=1.0
SANDBOX_PIDS_LIMIT=128
SANDBOX_MAX_REPAIR_ATTEMPTS=2

Build Sandbox Image

Before running AI sandbox code reports, build the local sandbox image once:

docker build -f docker/sandbox.Dockerfile -t alphasift-sandbox:latest .

If you use gVisor, ensure the runsc runtime is installed and available to Docker. Public OHLC endpoints do not require auth, but the config supports future private endpoints.

Project Structure

.
|-- data/
|   |-- raw/
|   `-- cache/
|-- scripts/
|   |-- fetch_kraken_ohlc.py
|   |-- run_backtest.py
|   |-- run_strategy_backtest.py
|   |-- run_sma_experiments.py
|   |-- run_paper_trader.py
|   `-- run_api.py
|-- frontend/
|   `-- (Vite + React + TypeScript local UI shell)
`-- src/
    `-- alphasift/
        |-- config.py
        |-- logging_config.py
        |-- utils/
        |-- data/
        |   |-- base.py
        |   |-- models.py
        |   |-- cache.py
        |   |-- kraken_client.py
        |   |-- kraken_provider.py
        |   `-- loaders.py
        |-- backtest/
        |   |-- engine.py
        |   |-- metrics.py
        |   `-- models.py
        |-- strategies/
        |   |-- base.py
        |   |-- buy_and_hold.py
        |   `-- sma_cross.py
        |-- experiments/
        |   |-- models.py
        |   |-- export.py
        |   `-- runner.py
        |-- paper/
        |   |-- models.py
        |   |-- export.py
        |   `-- engine.py
        |-- ai/
        |   |-- base.py
        |   |-- models.py
        |   |-- prompts.py
        |   |-- gemini_client.py
        |   `-- service.py
        `-- app/
            |-- api.py
            |-- schemas.py
            |-- services.py
            |-- jobs.py
            `-- db.py

Fetch Data

After installing, run:

python scripts/fetch_kraken_ohlc.py --pair BTC/USD --interval 60

This fetches Kraken OHLC data, normalizes to the schema: timestamp, open, high, low, close, volume, trades, vwap and caches it under data/cache.

Run Minimal Backtest

python scripts/run_backtest.py --pair BTC/USD --interval 60

This uses cached data and runs a basic long/flat backtest with a buy-and-hold target position.

Run Strategy Backtest

python scripts/run_strategy_backtest.py --pair BTC/USD --interval 60 --strategy buy_and_hold
python scripts/run_strategy_backtest.py --pair BTC/USD --interval 60 --strategy sma_cross --short-window 10 --long-window 30

This loads cached data, generates target positions from the chosen strategy, and runs the backtest engine.

Run SMA Experiments

python scripts/run_sma_experiments.py --pair BTC/USD --interval 60 --short-min 5 --short-max 20 --long-min 30 --long-max 80 --step 5
python scripts/run_sma_experiments.py --pair BTC/USD --interval 60 --export-csv data/experiments/sma_results.csv

This runs a simple SMA cross parameter sweep and prints ranked results. Optionally, --export-csv writes ranked results to CSV. Use --overwrite-export to replace an existing file.

Run Minimal Paper Trading

python scripts/run_paper_trader.py --pair BTC/USD --interval 60 --strategy buy_and_hold --initial-cash 10000
python scripts/run_paper_trader.py --pair BTC/USD --interval 60 --strategy sma_cross --short-window 10 --long-window 30
python scripts/run_paper_trader.py --pair BTC/USD --interval 60 --strategy sma_cross --export-dir data/paper_sessions --export-prefix btcusd_60m

This runs a fake-cash long/flat simulation on completed candles. Target changes are executed on the next completed bar open. Optionally, --export-dir writes account history and fills as deterministic CSV files. Use --overwrite-export to replace existing files.

Run Local API

python scripts/run_api.py

This starts a local FastAPI service that exposes:

  • health/system info,
  • strategy listing,
  • SMA experiment run creation and lookup,
  • paper session creation and lookup,
  • AI hypothesis and strategy-draft run creation and lookup,
  • AI sandbox code-report run creation and lookup,
  • AI model and prompt-profile metadata listing,
  • job listing and lookup,
  • artifact metadata listing and lookup.

Run Local Frontend

  1. Start the API:
python scripts/run_api.py
  1. In another terminal:
cd frontend
cp .env.example .env
npm install
npm run dev

The UI reads VITE_API_BASE_URL (default http://127.0.0.1:8000) and provides:

  • dashboard summary
  • strategies listing/detail
  • experiment run listing/detail + SMA run trigger form
  • paper session listing/detail + paper session trigger form
  • AI workspace with:
    • hypothesis generation form
    • strategy draft generation form with optional AI-selected local backtest execution
    • sandbox code-report form (AI-generated code runs in isolated Docker container with bounded repair attempts)
    • AI run listing/detail and artifact visibility
  • jobs listing/detail
  • artifact metadata listing

Why This Base Layer Exists

This project is intentionally scoped as a clean, modular research foundation so future prompts can add:

  • Broader result persistence
  • Live execution components
  • More data providers

without refactoring the foundations.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages