Skip to content

Add aws deployment mode #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 63 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,30 @@ This will create:
---

## 📈 Example: A Simple Trading Bot
The following example connects to Binance and buys BTC every 2 hours.
The following example trading bot implements a simple moving average strategy.
The strategy will use data from bitvavo exchange and will calculate
the 20, 50 and 100 period exponential moving averages (EMA) and the
14 period relative strength index (RSI).

> This example uses [PyIndicators](https://github.com/coding-kitties/pyindicators) for technical analysis.
> This dependency is not part of the framework, but is used to perform technical analysis on the dataframes.
> You can install it using pip: pip install pyindicators.

```bash

```python
import logging.config
from dotenv import load_dotenv

from pyindicators import ema, rsi

from investing_algorithm_framework import create_app, TimeUnit, Context, BacktestDateRange, \
CCXTOHLCVMarketDataSource, CCXTTickerMarketDataSource, DEFAULT_LOGGING_CONFIG, \
TradingStrategy, SnapshotInterval
TradingStrategy, SnapshotInterval, convert_polars_to_pandas

load_dotenv()
logging.config.dictConfig(DEFAULT_LOGGING_CONFIG)
logger = logging.getLogger(__name__)

# OHLCV data for candles
bitvavo_btc_eur_ohlcv_2h = CCXTOHLCVMarketDataSource(
Expand All @@ -111,21 +123,58 @@ class MyStrategy(TradingStrategy):
data_sources = [bitvavo_btc_eur_ohlcv_2h, bitvavo_btc_eur_ticker]

def run_strategy(self, context: Context, market_data):
# Access the data sources with the indentifier
polars_df = market_data["BTC-ohlcv"]
ticker_data = market_data["BTC-ticker"]
unallocated_balance = context.get_unallocated()
positions = context.get_positions()
trades = context.get_trades()
open_trades = context.get_open_trades()
closed_trades = context.get_closed_trades()

if context.has_open_orders(target_symbol="BTC"):
logger.info("There are open orders, skipping strategy iteration.")
return

print(market_data)

data = convert_polars_to_pandas(market_data["BTC-ohlcv"])
data = ema(data, source_column="Close", period=20, result_column="ema_20")
data = ema(data, source_column="Close", period=50, result_column="ema_50")
data = ema(data, source_column="Close", period=100, result_column="ema_100")
data = rsi(data, source_column="Close", period=14, result_column="rsi_14")

if context.has_position("BTC") and self.sell_signal(data):
context.create_limit_sell_order(
"BTC", percentage_of_position=100, price=data["Close"].iloc[-1]
)
return

if not context.has_position("BTC") and self.buy_signal(data):
context.create_limit_buy_order(
"BTC", percentage_of_portfolio=20, price=data["Close"].iloc[-1]
)
return

def buy_signal(self, data):
if len(data) < 100:
return False
last_row = data.iloc[-1]
if last_row["ema_20"] > last_row["ema_50"] and last_row["ema_50"] > last_row["ema_100"]:
return True
return False

def sell_signal(self, data):

if data["ema_20"].iloc[-1] < data["ema_50"].iloc[-1] and \
data["ema_20"].iloc[-2] >= data["ema_50"].iloc[-2]:
return True

return False

date_range = BacktestDateRange(
start_date="2023-08-24 00:00:00",
end_date="2023-12-02 00:00:00"
start_date="2023-08-24 00:00:00", end_date="2023-12-02 00:00:00"
)
backtest_report = app.run_backtest(backtest_date_range=date_range, initial_amount=100, snapshot_interval=SnapshotInterval.STRATEGY_ITERATION)
backtest_report.show()
app.add_strategy(MyStrategy)

if __name__ == "__main__":
# Run the backtest with a daily snapshot interval for end-of-day granular reporting
backtest_report = app.run_backtest(
backtest_date_range=date_range, initial_amount=100, snapshot_interval=SnapshotInterval.STRATEGY_ITERATION
)
backtest_report.show()
```

> You can find more examples [here](./examples) folder.
Expand Down
366 changes: 0 additions & 366 deletions examples/data/BTC_EUR_bitvavo_1d_2023010100_2023123100.csv

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading