Skip to main content

Professional-grade SDK for algorithmic trading on prediction markets (Beta - Core features stable, advanced modules experimental)

Project description

Neural SDK

PyPI version Python Versions License: MIT

Professional-grade SDK for algorithmic trading on prediction markets.

DocumentationExamplesContributing

Overview

Neural SDK is a Python framework for building algorithmic trading strategies on prediction markets. It provides data collection, strategy development, backtesting, and trade execution with production-grade reliability.

All market data comes from Kalshi's live production API via RSA-authenticated requests, using the same infrastructure that powers their trading platform.

Features

  • Authentication: RSA signature implementation for Kalshi API
  • Historical Data: Collect and analyze real trade data with cursor-based pagination
  • Real-time Streaming: REST API and FIX protocol support for live market data
  • Strategy Framework: Pre-built strategies (mean reversion, momentum, arbitrage)
  • Risk Management: Kelly Criterion, position sizing, stop-loss automation
  • Backtesting Engine: Test strategies on historical data before going live
  • Order Execution: Ultra-low latency FIX protocol integration (5-10ms)

Quick Start

Installation

pip install neural-sdk
pip install "neural-sdk[trading]"  # with trading extras

Credentials Setup

Create a .env file with your Kalshi credentials:

KALSHI_API_KEY_ID=your_api_key_id
KALSHI_PRIVATE_KEY_BASE64=base64_encoded_private_key
KALSHI_ENV=prod

The SDK automatically loads credentials from the .env file.

Usage

Authentication

from neural.auth.http_client import KalshiHTTPClient

client = KalshiHTTPClient()
markets = client.get('/markets')
print(f"Connected! Found {len(markets['markets'])} markets")

Historical Data Collection

from neural.data_collection.kalshi_historical import KalshiHistoricalDataSource
from neural.data_collection.base import DataSourceConfig

config = DataSourceConfig(
    source_type="kalshi_historical",
    ticker="NFLSUP-25-KCSF",
    start_time="2024-01-01",
    end_time="2024-12-31"
)

source = KalshiHistoricalDataSource(config)
trades_data = []

async def collect_trades():
    async for trade in source.collect():
        trades_data.append(trade)
        if len(trades_data) >= 1000:
            break

import asyncio
asyncio.run(collect_trades())
print(f"Collected {len(trades_data)} trades")

Strategy Development

from neural.analysis.strategies import MeanReversionStrategy
from neural.analysis import Backtester

strategy = MeanReversionStrategy(lookback_period=20, z_score_threshold=2.0)
engine = Backtester(initial_capital=10000)
results = engine.backtest(strategy, start_date="2024-01-01", end_date="2024-12-31")

print(f"Total Return: {results['total_return']:.2%}")
print(f"Sharpe Ratio: {results['sharpe_ratio']:.2f}")

Trading

from neural.trading.client import TradingClient

trader = TradingClient()
order = trader.place_order(
    ticker="NFLSUP-25-KCSF",
    side="yes",
    count=10,
    price=52
)
print(f"Order placed: {order['order_id']}")

Modules

Module Description
neural.auth RSA authentication for Kalshi API
neural.data_collection Historical and real-time market data
neural.analysis.strategies Pre-built trading strategies
neural.analysis.backtesting Strategy testing framework
neural.analysis.risk Position sizing and risk management
neural.trading Order execution (REST + FIX)

Examples

See the examples/ directory for working code samples:

  • 01_init_user.py - Authentication setup
  • stream_prices.py - Real-time price streaming
  • test_historical_sync.py - Historical data collection
  • 05_mean_reversion_strategy.py - Strategy implementation
  • 07_live_trading_bot.py - Automated trading bot

Testing

pytest
pytest --cov=neural tests/

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make changes and add tests
  4. Run tests: pytest
  5. Commit: git commit -m "Add amazing feature"
  6. Push: git push origin feature/amazing-feature
  7. Open a Pull Request

See CONTRIBUTING.md for detailed guidelines.

Development Setup

git clone https://github.com/IntelIP/Neural.git
cd neural
pip install -e ".[dev]"
pytest
ruff check .
black --check .

Resources

License

This project is licensed under the MIT License - see LICENSE file for details.

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

neural_sdk-0.4.0.tar.gz (184.6 kB view details)

Uploaded Source

Built Distribution

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

neural_sdk-0.4.0-py3-none-any.whl (139.6 kB view details)

Uploaded Python 3

File details

Details for the file neural_sdk-0.4.0.tar.gz.

File metadata

  • Download URL: neural_sdk-0.4.0.tar.gz
  • Upload date:
  • Size: 184.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for neural_sdk-0.4.0.tar.gz
Algorithm Hash digest
SHA256 90982ccca5922d93807ddbd8e99c3fa517db862177bf198194ccbe61fa9e3f90
MD5 dbf4f1ee2ac70168351631dcb9a7a90e
BLAKE2b-256 66432f12a9853a598da5320881812be0ebfec3a5cb30df53144844c682968a23

See more details on using hashes here.

File details

Details for the file neural_sdk-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: neural_sdk-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 139.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for neural_sdk-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8cc23bac9f1843e91947597686d9bc6eaa41efa468d7172ce65ebe1a3806be6
MD5 a8d09a2511584c7b2cc0f44dc4ae09ca
BLAKE2b-256 9eb20402dd24dbe7b14659c7451cba9a40d5372c46973d5ee1ec69e6ff31d93b

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