Skip to content

Commit 48c5059

Browse files
committed
Add docusaurus
1 parent 11ff0b1 commit 48c5059

44 files changed

Lines changed: 24843 additions & 41 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/babel.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
3+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "Advanced concepts",
3+
"position": 1,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "Advanced concepts and features of the framework."
7+
}
8+
}

docs/docs/Cook Book/how-to-check-open-orders.md.js

Whitespace-only changes.

docs/docs/Cook Book/how-to-structure-your-code.js

Whitespace-only changes.

docs/docs/Cook Book/using-take-profit-and-stop-loss.js

Whitespace-only changes.

docs/docs/Data/__category__.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "Data",
3+
"position": 0,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "Learn the basic concepts of using data sources in the investing algorithm framework"
7+
}
8+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
---
2+
3+
sidebar_position: 1
4+
5+
---
6+
7+
# Market data sources
8+
Algorithmic trading needs quick access to real-time data and effective data manipulation for successful analysis.
9+
To meet these needs, the framework provides a data object that can be used in your trading strategies.
10+
11+
For data availability, we use a push-based approach. This means we send the desired information directly as
12+
an argument to each trading strategy handler function or trading strategy class.
13+
It's easy to use – just annotate your handler with the information you need.
14+
15+
Here is an example of a handler that uses the `TICKER` data object:
16+
17+
```python
18+
# A ticker market data source for the BTC/EUR symbol on the bitvavo exchange
19+
bitvavo_ticker_btc_eur = CCXTTickerMarketDataSource(
20+
identifier="BTC-ticker",
21+
market="BITVAVO",
22+
symbol="BTC/EUR",
23+
)
24+
25+
class MyTradingStrategy(TradingStrategy):
26+
time_unit = TimeUnit.SECOND
27+
interval = 5
28+
market_data_sources = ["BTC-ticker"] # Registering the market data source by using its identifier
29+
30+
def apply_strategy(self, algorithm: Algorithm, data: dict):
31+
print(data)
32+
33+
# Make sure to register your market data sources with the app
34+
app.add_trading_strategy(MyTradingStrategy)
35+
app.add_market_data_source(bitvavo_ticker_btc_eur)
36+
```
37+
38+
By doing so your handler function parameter data will be assigned a data Object containing ticker for BTC/EUR from
39+
the bitvavo exchange under the key "BTC-ticker".
40+
41+
## Accessing data
42+
You can easily access the data object by using the `identifier` attribute of your MarketDataSource object.
43+
The following code snippet shows how to access the data object:
44+
45+
:::tip
46+
The data object that is passed in your trading strategy is a dictionary. This allows you to access multiple data objects
47+
in your trading strategy. The key of the dictionary is the identifier of the market data source.
48+
:::
49+
50+
```python
51+
# A ticker market data source for the BTC/EUR symbol on the bitvavo exchange
52+
bitvavo_ticker_btc_eur = CCXTTickerMarketDataSource(
53+
identifier="BTC-ticker",
54+
market="BITVAVO",
55+
symbol="BTC/EUR",
56+
)
57+
58+
class MyTradingStrategy(TradingStrategy):
59+
time_unit = TimeUnit.SECOND
60+
interval = 5
61+
market_data_sources = ["BTC-ticker"] # Registering the market data source by using its identifier
62+
63+
def apply_strategy(self, algorithm: Algorithm, data):
64+
ticker_data = data["BTC-ticker"] # Accessing the data object directly by using the identifier
65+
66+
# Make sure to register your market data sources with the app
67+
app.add_trading_strategy(MyTradingStrategy)
68+
app.add_market_data_source(bitvavo_ticker_btc_eur)
69+
```
70+
71+
72+
## CCXT market data sources
73+
The framework comes out of the box with support for the [ccxt](https://github.com/ccxt/ccxt).
74+
This allows you the use the following ccxt market data sources:
75+
76+
- CCXTTickerMarketDataSource
77+
- CCXTOHLCVMarketDataSource
78+
- CCXTOrderBookMarketDataSource
79+
80+
### CCXTTickerMarketDataSource
81+
The CCXTTickerMarketDataSource is used to get the latest ticker data for a symbol. It is based
82+
on the popular [ccxt](https://github.com/ccxt/ccxt) library.
83+
84+
```python
85+
from investing_algorithm_framework import CCXTTickerMarketDataSource, TradingStrategy, \
86+
Algorithm, TimeUnit
87+
88+
# A ohlcv market data source for the BTC/EUR symbol on the BITVAVO exchange
89+
bitvavo_ticker_btc_eur = CCXTTickerMarketDataSource(
90+
identifier="BTC-ticker",
91+
market="BITVAVO",
92+
symbol="BTC/EUR",
93+
)
94+
95+
class MyTradingStrategy(TradingStrategy):
96+
time_unit = TimeUnit.SECOND # The time unit of the strategy
97+
interval = 5 # The interval of the strategy, runs every 5 seconds
98+
# Registering the market data source
99+
market_data_sources = [bitvavo_ticker_btc_eur]
100+
101+
def apply_strategy(self, algorithm: Algorithm, market_data: Dict[str, Any]):
102+
print(market_data[bitvavo_ticker_btc_eur.get_identifier()])
103+
```
104+
105+
### CCXTOHLCVMarketDataSource
106+
The CCXTOHLCVMarketDataSource is used to get candle stick/OHLCV data for a symbol. It is based
107+
on the popular [ccxt](https://github.com/ccxt/ccxt) library.
108+
109+
:::info
110+
For ohlcv data you need to specify a start date, and/or an end date.
111+
If you don't specify an end date, the framework will use the current date as the end date. The daterange between
112+
the start and end date is used to determine the number of candlesticks in your ohlcv data. E.g. if you
113+
specify a start date of `start_date=datetime.utcnow() - timedelta(days=17)` and a timeframe of 2h, the framework will
114+
fetch 216 candlesticks (17 days * 12 candlesticks per day). Keep in mind that by leveraging a function like `datetime.utcnow()`
115+
you will get the current date in UTC time everytime the market data source is used. This allows you to get the latest data
116+
everytime the strategy runs.
117+
:::
118+
119+
```python
120+
from investing_algorithm_framework import CCXTOHLCVMarketDataSource, TradingStrategy, \
121+
Algorithm, TimeUnit
122+
123+
# A order book market data source for the BTC/EUR symbol on the BITVAVO exchange
124+
bitvavo_btc_eur_ohlcv_2h = CCXTTickerMarketDataSource(
125+
identifier="BTC-ohlcv-2h",
126+
market="BITVAVO",
127+
symbol="BTC/EUR",
128+
)
129+
130+
class MyTradingStrategy(TradingStrategy):
131+
time_unit = TimeUnit.SECOND # The time unit of the strategy
132+
interval = 5 # The interval of the strategy, runs every 5 seconds
133+
# Registering the market data source
134+
market_data_sources = [bitvavo_btc_eur_ohlcv_2h]
135+
136+
def apply_strategy(self, algorithm: Algorithm, market_data: Dict[str, Any]):
137+
print(market_data[bitvavo_btc_eur_ohlcv_2h.get_identifier()])
138+
```
139+
140+
### CCXTOrderBookMarketDataSource
141+
The CCXTOrderBookMarketDataSource is used to get order book data for a symbol. It is based
142+
on the popular [ccxt](https://github.com/ccxt/ccxt) library.
143+
144+
145+
```python
146+
from investing_algorithm_framework import CCXTOrderBookMarketDataSource, TradingStrategy, \
147+
Algorithm, TimeUnit
148+
149+
# A ticker market data source for the BTC/EUR symbol on the BITVAVO exchange
150+
bitvavo_btc_eur_order_book = CCXTOrderBookMarketDataSource(
151+
identifier="BTC-order-book",
152+
market="BITVAVO",
153+
symbol="BTC/EUR",
154+
)
155+
156+
class MyTradingStrategy(TradingStrategy):
157+
time_unit = TimeUnit.SECOND # The time unit of the strategy
158+
interval = 5 # The interval of the strategy, runs every 5 seconds
159+
# Registering the market data source
160+
market_data_sources = [bitvavo_btc_eur_order_book]
161+
162+
def apply_strategy(self, algorithm: Algorithm, market_data: Dict[str, Any]):
163+
print(market_data[bitvavo_btc_eur_order_book.get_identifier()])
164+
```
165+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
3+
sidebar_position: 2
4+
5+
---
6+
7+
# Multiple data sources
8+
The framework allows you to configure multiple data sources for your trading strategies.
9+
You can use this to combine different data sources. This allowes you to easily use different exchanges
10+
or brokers in your trading strategy.
11+
12+
A quick example of how to use multiple data sources in your trading strategy:
13+
```python
14+
# A ticker market data source for the BTC/EUR symbol on the bitvavo exchange
15+
bitvavo_ticker_btc_eur = CCXTTickerMarketDataSource(
16+
identifier="BTC-ticker",
17+
market="BITVAVO",
18+
symbol="BTC/EUR",
19+
)
20+
21+
# A ohlcv market data source for the BTC/EUR symbol on the BITVAVO exchange
22+
bitvavo_btc_eur_ohlcv_2h = CCXTOHLCVMarketDataSource(
23+
identifier="BTC-ohlcv",
24+
market="BITVAVO",
25+
symbol="BTC/EUR",
26+
timeframe="2h",
27+
start_date_func=lambda : datetime.utcnow() - timedelta(days=17)
28+
)
29+
30+
class MyTradingStrategy(TradingStrategy):
31+
time_unit = TimeUnit.SECOND
32+
interval = 5
33+
market_data_sources = ["BTC-ticker", "BTC-ohlcv"] # Registering the market data sources by using their identifiers
34+
35+
def apply_strategy(self, algorithm: Algorithm, data):
36+
ticker_data = data["BTC-ticker"] # Accessing the ticker data object directly by using the identifier
37+
ohlcv_data = data["BTC-ohlcv"] # Accessing the ohlcv data object directly by using the identifier
38+
39+
# Make sure to register your market data sources with the app
40+
app.add_trading_strategy(MyTradingStrategy)
41+
app.add_market_data_source(bitvavo_ticker_btc_eur)
42+
app.add_market_data_source(bitvavo_btc_eur_ohlcv_2h)
43+
```
44+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "Getting Started",
3+
"position": 0,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "Learn the basic concepts of the investing algorithm framework"
7+
}
8+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
3+
sidebar_position: 2
4+
5+
---
6+
7+
# Application Setup
8+
The best way to get started with the framework is to create an application through the init cli command.
9+
You can do this by running the following command in your terminal:
10+
11+
```bash
12+
investing-algorithm-framework init
13+
```
14+
15+
This will create the following directory structure:
16+
17+
```bash
18+
.
19+
├── README.md
20+
├── app.py
21+
├── strategies
22+
│ └── my_trading_strategy.py
23+
└── gitignore
24+
```
25+
26+
The `app.py` file is the main entry point for your application. Ideally, you should only use this file to register your
27+
strategies, portfolio configurations and market data sources. Its also
28+
not recommended to add any logic to this file because the framework will use this file to run your application.
29+
30+
The `strategies` directory is where you can add your trading strategies. You can create multiple files in this directory
31+
and add your trading strategies to them. The framework will use this directory to save and link your
32+
trading strategies to your backtest runs. This allows you to easily run multiple backtests with different trading strategies
33+
and bundle them with your backtest results.
34+
35+
By default the REST API and UI are disabled. You can enable them by running the init command with the `--web` flag:
36+
37+
```bash
38+
investing-algorithm-framework init --web
39+
```
40+
41+
or you can enable them later by adding the following lines to your `app.py` file:
42+
43+
```python
44+
import logging.config
45+
from dotenv import load_dotenv
46+
47+
from investing_algorithm_framework import create_app, DEFAULT_LOGGING_CONFIG
48+
49+
load_dotenv()
50+
logging.config.dictConfig(DEFAULT_LOGGING_CONFIG)
51+
52+
app = create_app(
53+
web=True, # Enable the REST API and UI
54+
)
55+
56+
# Register your trading strategies here
57+
...
58+
59+
# Register your market data sources here
60+
...
61+
62+
# Register your portfolio configurations here
63+
...
64+
65+
# Run the app
66+
if __name__ == "__main__":
67+
app.run()
68+
```

0 commit comments

Comments
 (0)