Metadata-Version: 2.4
Name: stock-gen
Version: 0.2.0
Summary: Order-book event generator and CLOB simulator (price moves only via matching)
Author: Small Turtle 2
License: MIT License
        
        Copyright (c) 2026 Small Turtle 2
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Requires-Python: >=3.11
Requires-Dist: matplotlib>=3.8
Requires-Dist: numpy>=1.26
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == 'dev'
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.5; extra == 'dev'
Description-Content-Type: text/markdown

# stock-gen v0.2

`stock-gen` is an event-driven limit order book simulator. Mid-price changes only through matched order-book events.

## Install

```bash
python -m pip install stock-gen
```

For local development:

```bash
python -m pip install -e '.[dev]'
```

## Quickstart

```python
from stock_gen import (
    EventCapPolicy,
    LiquidityPolicy,
    SimulationResult,
    StepResult,
    StockGenerator,
    StockGeneratorConfig,
)

cfg = StockGeneratorConfig(
    tick_size=0.01,
    dt=1.0,
    end_time=60.0,
    depth_levels=10,
    seed=123,
    liquidity_policy=LiquidityPolicy.REPAIR,
    event_cap_policy=EventCapPolicy.RAISE,
)

sg = StockGenerator(cfg)

step: StepResult = sg.step()
print(
    "t=", step.frame.t,
    "mid=", step.frame.mid_price,
    "events=", step.events_processed,
    "truncated=", step.truncated,
)

sim: SimulationResult = sg.gen()
print(
    "frames=", len(sim.frames),
    "steps=", len(sim.steps),
    "events=", len(sim.events),
    "trades=", len(sim.trades),
)
```

## Policy Knobs

- `LiquidityPolicy.REPAIR` (default): auto-inserts synthetic liquidity if a side is empty.
- `LiquidityPolicy.ALLOW_EMPTY`: allows one-sided books; `spread_ticks`/best quote fields can be missing.
- `LiquidityPolicy.HALT_ON_EMPTY`: raises immediately on one-sided book.
- `EventCapPolicy.RAISE` (default): raises if `max_events_per_step` is exceeded.
- `EventCapPolicy.TRUNCATE_AND_FLAG`: ends the step early and sets `StepResult.truncated=True`.

## Core API

- `step(dt=None) -> StepResult`: runs one frame.
- `gen(until_time=None) -> SimulationResult`: runs until target time and returns full accumulated history.
- `get_history().to_numpy(as_ticks=True|False)`: vectorized arrays for downstream modeling.

## Examples

```bash
python examples/basic_run.py
python examples/plot_demo.py
```

## Documentation

- `docs/api.md`
- `docs/data-contract.md`
- `docs/config-reference.md`
- `docs/reproducibility.md`
- `docs/release.md`
