Metadata-Version: 2.4
Name: algoglide
Version: 0.1.1
Summary: Algoglide agent runtime SDK
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: grpcio>=1.63
Requires-Dist: grpcio-tools>=1.63
Requires-Dist: protobuf>=4.25
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Requires-Dist: pytest-asyncio>=1.0; extra == "test"

<p align="center">
  <img src="https://raw.githubusercontent.com/algoglide/mcp/main/logo.svg" alt="algoglide" width="72" />
</p>

<p align="center">
  <b>Algoglide agent runtime SDK for Python</b>
</p>

<p align="center">
  Build, backtest, and deploy prediction-market trading agents.
</p>

<p align="center">
  <a href="https://docs.algoglide.com">Docs</a> &nbsp;·&nbsp;
  <a href="https://algoglide.com">algoglide.com</a> &nbsp;·&nbsp;
  <a href="https://github.com/algoglide/mcp">MCP Plugin</a>
</p>

---

## Install

```bash
pip install algoglide
```

## Quick start

```python
from algoglide import BaseStrategy, TickContext

class MomentumAgent(BaseStrategy):
    markets = ["will-bitcoin-hit-100k-by-2026"]

    def on_market_update(self, ctx: TickContext) -> None:
        yes = ctx.market.outcome("Yes")
        if not yes:
            return

        # Buy YES when price is below 40 cents
        if yes.price < 0.40 and ctx.market.elapsed_pct > 0.3:
            ctx.buy("Yes", size_usd=10.0, limit_price=yes.price + 0.01)
            ctx.log(f"Buying YES at {yes.price:.3f}")

        # Take profit above 65 cents
        if yes.price > 0.65:
            ctx.sell("Yes", size_usd=10.0)
            ctx.log(f"Taking profit at {yes.price:.3f}")
```

## Concepts

**Strategies are event-driven.** You define a class that extends `BaseStrategy`, list the markets you want to trade, and implement `on_market_update`. The runtime calls your method on every price tick.

**No polling loops.** Never use `while True` or `time.sleep`. The runtime handles scheduling.

**Context object.** Every hook receives a `TickContext` (or `FillContext`) with market state, position info, and order methods.

## Market state

```python
def on_market_update(self, ctx: TickContext) -> None:
    # Current market snapshot
    yes = ctx.market.outcome("Yes")   # OutcomeSnapshot or None
    no  = ctx.market.outcome("No")

    # Price, spread, volume
    price = yes.price        # 0.0 - 1.0
    spread = ctx.market.spread
    volume = ctx.market.volume_24h

    # How far through the market's lifetime (0.0 = start, 1.0 = end)
    elapsed = ctx.market.elapsed_pct
```

## Orders

```python
# Market buy
ctx.buy("Yes", size_usd=10.0)

# Limit buy
ctx.buy("Yes", size_usd=10.0, limit_price=0.55)

# Sell
ctx.sell("Yes", size_usd=10.0)

# Cancel
ctx.cancel(order_id)
```

## Fill handling

```python
from algoglide import BaseStrategy, FillContext

class MyAgent(BaseStrategy):
    markets = ["some-market-slug"]

    def on_market_update(self, ctx):
        pass

    def on_fill(self, ctx: FillContext) -> None:
        ctx.log(f"Filled: {ctx.outcome} @ {ctx.price:.3f}, size={ctx.size:.2f}")
        ctx.log(f"Position: {ctx.position.size} @ avg {ctx.position.avg_price:.3f}")
```

## Event decorators

```python
from algoglide import BaseStrategy, on_news, on_signal_change

class NewsAgent(BaseStrategy):
    markets = ["fed-rate-decision-june"]

    def on_market_update(self, ctx):
        pass

    @on_news("federal reserve rate decision")
    def handle_fed_news(self, item):
        self.log(f"News: {item.headline}")

    @on_signal_change("fed-rate-decision-june", threshold=0.1)
    def handle_signal_shift(self, before, after):
        self.log(f"Signal shifted: {before.confidence:.2f} -> {after.confidence:.2f}")
```

## Deploy

```bash
# Validate locally
algoglide validate agent.py

# Deploy to algoglide cloud
algoglide deploy agent.py --name "my-momentum-bot"
```

Or deploy via the [MCP plugin](https://github.com/algoglide/mcp) in Claude Code / Cursor / Cline.

## Links

- [Documentation](https://docs.algoglide.com)
- [MCP Plugin](https://github.com/algoglide/mcp)
- [TypeScript SDK](https://npmjs.com/package/@algoglide/sdk)
- [Rust SDK](https://crates.io/crates/algoglide)
