Metadata-Version: 2.4
Name: tasilab
Version: 0.2.1
Summary: Tasilab is the first API-native paper trading sandbox for the Saudi Stock Exchange, empowering developers to build, test, and deploy AI-driven trading strategies with zero financial risk.
Author-email: Jafar Albinmousa <binmousa@gmail.com>
License: Proprietary
Project-URL: Homepage, https://tasilab.com
Project-URL: Documentation, https://api.tasilab.com/docs
Project-URL: API Guide, https://tasilab.com/tadawul-api
Project-URL: Issues, https://tasilab.com/contact
Keywords: tasi,tadawul,saudi,stock,exchange,paper-trading,backtesting,trading,sdk
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Office/Business :: Financial :: Investment
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: httpx>=0.25.0

# Tasilab Python SDK

Tasilab is the first API-native paper trading sandbox for the Saudi Stock Exchange, empowering developers to build, test, and deploy AI-driven trading strategies with zero financial risk.

This package is the official Python client. Use it to pull historical TASI data, log backtests as experiments, and view results in the Tasilab dashboard.

- Dashboard: <https://tasilab.com>
- API docs: <https://api.tasilab.com/docs>

## Install

```bash
pip install tasilab
```

## Quick start

```python
from tasilab import Tasilab

tasi = Tasilab(api_key="YOUR_API_KEY")

# 1. Pull historical bars (Tasilab caches them for you)
hist = tasi.get_historical("1120", "2024-01-01", "2025-12-31")

# 2. Run your strategy locally → list of trade dicts
trades = my_strategy(hist["bars"])

# 3. Log the run as a Tasilab experiment (auto-seals on exit)
with tasi.create_experiment(
    name="MACD 12/26/9 on Al Rajhi",
    symbol="1120",
    start_date="2024-01-01",
    end_date="2025-12-31",
    parameters={"fast": 12, "slow": 26, "signal": 9},
) as exp:
    exp.log_trades(trades)
    exp.log_metrics({"total_return_sar": 439.64, "win_rate": 0.412})
```

The `with` block automatically marks the experiment `completed` on clean exit and `failed` if an exception propagates, so experiments never get stuck in `running`.

## Paper trading

The SDK also supports live paper-trading against the simulated exchange:

```python
order = tasi.buy("2222", quantity=100)
portfolio = tasi.portfolio()
```

See <https://tasilab.com> for the full surface.

## The Lab

Thin wrappers over the Lab's REST endpoints. Every call returns the API's
JSON unchanged — the SDK adds no client-side metrics of its own.

**Edge Explorer** — does a condition change what happens next?

```python
conditions = tasi.list_conditions()          # what can be tested
situations = tasi.list_situations()          # the Guided Lab's presets

result = tasi.edge_explorer(
    "2222",
    {"type": "consecutive_down", "sessions": 3},
    period="5Y",
    forward_days=10,
)
print(result["data_version"])                # bars fingerprint — reproducible
```

Pass `persist=False` to compute without writing a row to Experiments.
Use it for exploratory calls you do not want in run history.

**Historical Testing** — run a strategy over past bars:

```python
print(tasi.backtest_limits())                # your tier's limits

run = tasi.backtest(
    "1120",
    period="3Y",
    strategy_type="ma_crossover",
    fast_ma="SMA", fast_period=10,
    slow_ma="SMA", slow_period=50,
    stop_loss_pct=0.05,
)
```

Which strategy fields apply depends on `strategy_type` — `threshold`,
`ma_crossover`, `price_ma_cross` or `macd_signal_cross`. The API validates
the combination and returns a 422 naming the offending field.

**Model Test** — a quick predictive model over the same history:

```python
model = tasi.quick_predictor("2010", period="3Y", model="logreg")
for feature in model["feature_importances"]:
    print(feature["name"], feature["importance"], feature["direction"])
```

For LogReg the `direction` is meaningful. For Random Forest it is `None`
and the value is an absolute mean-decrease-in-impurity score — an
importance, not a signed coefficient. Do not read it as one.


## License

Proprietary — see <https://tasilab.com> for terms.
