Scripts & Routines
OpenBB Routine Scripts,
.openbb, are simple scripts for automating processes and repetitive tasks. They represent a 1:1 relationship with any command in the OpenBB Terminal; one line represents one function. Other software like STATA, SPSS and R-Studio share similar functionality in the area of Econometrics and the OpenBB routine scripts venture into the area of financial analysis and data collection to speed up the process. For example, not only is it possible to automate a set of functionality, it is also possible to export a large amount of data to Excel through the usage of
--sheet-name making data collection efficient, reproducible and customizable.
A routine file can be created or modified in any basic text editor. The only difference between a plain-text file and an OpenBB Routine file is the
.openbb file extension. Additionally, routine files can be captured with the macro recorder, controlled with global commands,
stop. The script is automatically saved to the,
Routine files stored there are callable from the main menu, using the
exe function. By deploying variable arguments -
$ARGV - to any line in the script, dates, symbols, exported filenames, or any Terminal function argument, scripts become dynamic.
Run a routine file from the main menu, with the
exe command. A great start would be to use
exe --example to get a sense of what this functionality does. Below, the
--help dialogue is displayed.
usage: exe [--file PATH] [-i ROUTINE_ARGS] [-e] [-h]
Execute automated routine script. For an example, please use `exe --example` and for documentation and to learn how create your own script type `about exe`.
--file PATH The path or .openbb file to run. (default: None)
-i ROUTINE_ARGS, --input ROUTINE_ARGS
Select multiple inputs to be replaced in the routine and separated by commas. E.g. GME,AMC,BTC-USD (default: None)
-e, --example Run an example script to understand how routines can be used. (default: False)
-h, --help show this help message (default: False)
The Macro Recorder
As a starting point, you can use the
stop functionalitsy. This shares similarities with that of Excel's VBA methods. This means that any command you run will be automatically recorded for the routine script and once you type
stop it automatically saves the file. For example, if you cope the following code in the OpenBB Terminal and run it, you will see an example.
The following shows the script being ran and the charts that are created because of it.
After the script is finished, you are able to access the routine file when using
exe --file. The naming of the file can differ for you based on the time you are executing the script. You can find this script inside the
routines folder within the
OpenBBUserData folder (as found here)
Create your own Script
As mentioned earlier, the scripts and routines reside in the
routines folder within the
OpenBBUserData folder (as found here) and are automatically shown when you type
exe from the home screen (
- Download the file that can be used as a template here.
- Move the file inside the
routinesfolder within the OpenBBUserData folder and, optionally, adjust the name to your liking.
- Open the file with a Text Editor (e.g. Notepad or TextEdit) and adjust the file accordingly.
- Open up the OpenBB Terminal, and type
exe --file. The file should then be one of the options.
- Select the file to run the routine script.
As long as the file remains in the
routines folder, you will be able to find your file automatically as shown below. Note that this also shows the script that was created within The Macro Recorder section.
Explanation of Scripts
The script file follows the following logic:
- Comments: any text after a hashtag (
#) is referred to as a comment. This is used to explain what is happening within the script and is not taking into account when running terminal commands.
- Commands: any text without a hashtag is being ran inside the OpenBB Terminal. E.g. on the second line it says
stocksthus within the OpenBB Terminal the script will enter
stocksand run this for you.
These scripts have a 1-to-1 relationship with how you would normally use the terminal. To get a better understanding of how the terminal is used, please see Structure of the OpenBB Terminal. The example below can be executed by running
# Go into the stocks context
# Load a company ticker, e.g. Apple
# Show a candle chart with a 20 day Moving Average
candle --ma 20
# Switch over to the Fundamental Analysis menu
# Show Earnings per Share (EPS) estimates
# Show price targets charts
# Show future estimations
# Return to home
Executing a Script
By going to the main menu as depicted below (accessible with
exe command can be used. With this command you can run any
.openbb script. These scripts are located where the application is located inside the
routines folder as found in the
Thus, using the earlier mentioned script, we can enter
exe --file routines_template.openbb which automatically runs all commands within the script file. Thus, it will return a candle chart with a moving average of 20 days, expectations and price targets from analysts and estimated future performance before returning to the home window.
Next to that, it is also possible to add in custom arguments to your script making the script more interactive and allow you to do the same analysis for multiple companies. This is done in the following script (and can be downloaded here):
# This script requires you to use arguments. This can be done with the following:
# exe --file routines_template_with_inputs.openbb -i TSLA,AAPL,MSFT
# Go to the stocks menu
# Load a ticker, given the argument used. E.g. -i TSLA
# Enter the Technical Analysis (ta) menu
# Show the fibonacci retracement levels
# Enter the comparison analysis (ca) menu
# Set two extra tickers based on the arguments used. E.g. -i TSLA,AAPL,MSFT
# Plot the historical prices
# Return to home
This script includes
$ARGV. This means that the script requires you to submit three arguments. In this case, they refer to stock tickers. Therefore, like the script also says, you can include these arguments with
-i followed by three tickers (e.g.
routines_template_with_inputs.openbb). This results in the following:
It is a simple script but it gives an understanding what the possibilities are. Do make sure you saved this script in the
routines folder else you are not able to execute it.