Metadata-Version: 2.1
Name: lettrade
Version: 0.0.8b2
Summary: Lightweight trading framwork
Home-page: https://github.com/AwesomeTrading/LetTrade
Author: Santatic
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
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 :: Scientific/Engineering :: Visualization
Requires-Python: >=3.10,<3.13
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pandas
Requires-Dist: numpy
Requires-Dist: numexpr
Provides-Extra: plot
Requires-Dist: plotly; extra == "plot"
Provides-Extra: jupyter
Requires-Dist: nbformat; extra == "jupyter"
Requires-Dist: rich[jupyter]; extra == "jupyter"
Provides-Extra: commander
Requires-Dist: lettrade[plot]; extra == "commander"
Provides-Extra: commander-telegram
Requires-Dist: lettrade[commander]; extra == "commander-telegram"
Requires-Dist: python-telegram-bot; extra == "commander-telegram"
Provides-Extra: backtest
Requires-Dist: lettrade[plot]; extra == "backtest"
Requires-Dist: rich; extra == "backtest"
Provides-Extra: backtest-extra
Requires-Dist: lettrade[backtest]; extra == "backtest-extra"
Requires-Dist: lettrade[jupyter]; extra == "backtest-extra"
Requires-Dist: yfinance; extra == "backtest-extra"
Provides-Extra: live
Requires-Dist: lettrade[plot]; extra == "live"
Provides-Extra: exchange-metatrader
Requires-Dist: lettrade[live]; extra == "exchange-metatrader"
Requires-Dist: python-box; extra == "exchange-metatrader"
Requires-Dist: mt5linux; extra == "exchange-metatrader"
Provides-Extra: exchange-ccxt
Requires-Dist: lettrade[live]; extra == "exchange-ccxt"
Requires-Dist: ccxt; extra == "exchange-ccxt"
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Provides-Extra: all
Requires-Dist: lettrade[backtest-extra]; extra == "all"
Requires-Dist: lettrade[exchange-metatrader]; extra == "all"
Requires-Dist: lettrade[exchange-ccxt]; extra == "all"
Requires-Dist: lettrade[commander-telegram]; extra == "all"
Requires-Dist: lettrade[test]; extra == "all"

# LetTrade

[![Documentation](https://img.shields.io/badge/docs-lettrade-708FCC.svg?style=for-the-badge)](https://AwesomeTrading.github.io/LetTrade/)
[![Code Coverage](https://img.shields.io/codecov/c/gh/AwesomeTrading/lettrade.svg?style=for-the-badge)](https://codecov.io/gh/AwesomeTrading/lettrade)
[![PyPI](https://img.shields.io/pypi/v/lettrade.svg?color=blue&style=for-the-badge)](https://pypi.org/project/lettrade)
[![PyPI Python Version](https://img.shields.io/pypi/pyversions/lettrade.svg?color=skyblue&style=for-the-badge)](https://pypi.org/project/lettrade)
[![PyPI Downloads](https://img.shields.io/pypi/dd/lettrade.svg?color=skyblue&style=for-the-badge)](https://pypi.org/project/lettrade)

A lightweight trading framework compatible with Stock, Forex, Crypto... markets

Find more at [**Documentation**](https://AwesomeTrading.github.io/LetTrade/)

## Installation

> [!WARNING]  
> LetTrade is under heavy construction, features and functions may be changed.
>
> Using Developing version to get latest update.

Stable version

```sh
pip install lettrade[all]
```

Developing version

```sh
pip install 'lettrade[all] @ git+https://git@github.com/AwesomeTrading/LetTrade.git@main'
```

## Example

```python
import talib.abstract as ta

from lettrade import indicator as i
from lettrade.all import DataFeed, ForexBackTestAccount, Strategy, let_backtest


class SmaCross(Strategy):
    ema1_period = 9
    ema2_period = 21

    def indicators(self, df: DataFeed):
        df["ema1"] = ta.EMA(df, timeperiod=self.ema1_period)
        df["ema2"] = df.i.ema(period=self.ema2_period)

        df["crossover"] = i.crossover(df.ema1, df.ema2)
        df["crossunder"] = df.i.crossunder(df.ema1, df.ema2)

    def next(self, df: DataFeed):
        if df.l.crossover[-1]:
            self.positions_exit()
            self.buy(size=0.1)
        elif df.l.crossunder[-1]:
            self.positions_exit()
            self.sell(size=0.1)


lt = let_backtest(
    strategy=SmaCross,
    datas="example/data/data/EURUSD_5m-0_1000.csv",
    account=ForexBackTestAccount,
)

lt.run()
lt.plot()
```

```text
# Strategy                <class '__main__.SmaCross'>
Start                       2024-05-13 21:15:00+00:00
End                         2024-05-17 08:30:00+00:00
Duration                              3 days 11:15:00
Start Balance                                  1000.0
Equity [$]                                    1003.16
Equity Peak [$]                               1013.54
PL [$]                                           3.16
PL [%]                                           0.32
Buy & Hold PL [%]                                0.63
Max. Drawdown [%]                               -4.98
Avg. Drawdown [%]                                -1.5
Max. Drawdown Duration                1 days 16:15:00
Avg. Drawdown Duration                0 days 12:30:00
                                                     
# Positions                                        34
Win Rate [%]                                     0.38
Fee [$]                                         -1.34
Best Trade [%]                                  29.36
Worst Trade [%]                                -18.14
SQN                                              0.07
Kelly Criterion                               0.01392
Profit Factor                                1.037781
```

![Plot](https://raw.githubusercontent.com/AwesomeTrading/lettrade/main/docs/image/plot.png)

### Start a strategy

More examples can be found in [`example/`](https://github.com/AwesomeTrading/lettrade/tree/main/example)

#### Download data

```bash
python -m example.data.yfinance
```

#### Backtest strategy
```bash
python -m example.strategy.backtest_sma_cross
```

## Live Trading

### Official

- `MetaTrader`: Support MetaTrader 5 Terminal trading
- `CCXT`: [WIP] Support most of cryptocurrency exchange from CCXT library

## Development

Set up conda environment

```sh
conda create -y -n LetTrade python=3.12
conda activate LetTrade
pip install -r requirements-dev.txt
```
