Lightweight trading framwork
Project description
LetTrade
A lightweight trading framework compatible with Stock, Forex, Crypto... markets
Find more at Documentation
Installation
[!WARNING]
LetTrade is under heavy construction, features and functions may be changed.Using Developing version to get latest update.
Stable version
pip install lettrade[all]
Developing version
pip install 'lettrade[all] @ git+https://git@github.com/AwesomeTrading/LetTrade.git@main'
Example
from lettrade import indicator as i
from lettrade.all import DataFeed, ForexBackTestAccount, Strategy, let_backtest
class SmaCross(Strategy):
ema1_window = 9
ema2_window = 21
def indicators(self, df: DataFeed):
df["ema1"] = ta.EMA(df, timeperiod=self.ema1_window)
df.i.ema(name="ema2", window=self.ema2_window, inplace=True, plot=True)
df["crossover"] = i.crossover(df.ema1, df.ema2)
df.i.crossunder("ema1", "ema2", inplace=True, plot=True)
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)
def plot(self, config: dict, df: DataFeed) -> dict:
from lettrade.plot.plotly import PlotColor, plot_line, plot_mark, plot_merge
plot_ema1 = plot_line(df["ema1"], dataframe=df, color="green")
plot_crossover = plot_mark(
df["close"],
filter=df["crossover"] >= 100,
dataframe=df,
name="crossover",
color=PlotColor.BLUE,
)
return plot_merge(config, plot_ema1, plot_crossover)
if __name__ == "__main__":
lt = let_backtest(
strategy=SmaCross,
datas="example/data/data/EURUSD_5m-0_1000.csv",
account=ForexBackTestAccount,
)
lt.run()
lt.plot()
# 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
Start a strategy
More examples can be found in example/
Download data
python -m example.data.yfinance
Backtest strategy
python -m example.strategy.backtest_sma_cross
Live Trading
Official
MetaTrader
: Support MetaTrader 5 Terminal tradingCCXT
: [WIP] Support most of cryptocurrency exchange from CCXT library
Development
Set up conda environment
conda create -y -n LetTrade python=3.12
conda activate LetTrade
pip install -r requirements-dev.txt
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lettrade-0.0.10b0.tar.gz
(105.9 kB
view hashes)
Built Distribution
lettrade-0.0.10b0-py3-none-any.whl
(139.3 kB
view hashes)
Close
Hashes for lettrade-0.0.10b0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63d601977579d32a16d8c5ac238224f305d674edb3066980dbbcdbe273c8792d |
|
MD5 | cf5f3f7ac7dcb5808c70fdeec9ba2e88 |
|
BLAKE2b-256 | 35afb9a619ac950a03b1273730f10ed3f045a7e10a96cc3a7da2558bf06bca7e |