A Guide to Automating Your Stock Analysis With Python

Mohammad Nurdin

In order for you to use i-Bursa API first, you need to subscribe to the API key provided by DEEPAGI, you may find the registration link here

Once you acquire the API key, you need to install Python and Jupyter Notebook in order to use this notebook as we go through this guide

  1. Python (Windows) >
  2. Python (macOS) >
  3. Python (Linux) > run “sudo apt install python3” in your terminal

After you installed Python, opens up your Command Prompt on your Windows machine or Terminal in your Linux or Mac machine and try running the command “python –version” to check Python availability in your machine.

P/s: Your Python version may not similar to mine, so just proceed with this guide.

command line

Next, you need to install Jupyter Notebook by using pip, the package library for Python. In the same Command Prompt or terminal session, run “pip install notebook” to install Jupyter Notebook

P/s: The output may differs between your installation and mine cause I already have Jupyter in my machine.

command line

Download and put this notebook in the Documents folder of your machine or any folder, and navigate to the folder using “cd” command in your terminal, and then run “jupyter notebook” commands.

command line

Open the ipynb file or this notebook that you have downloaded, and press Run on the next cell to install pandas and requests package to use DEEPAGI i-Bursa API.

pip install pandas requests

Remove YOUR_API_KEY below and replace with the API key provided by DEEPAGI without removing the quotes and run all the cells below.


Getting single stock details.

import requests
import pandas
pandas.options.display.max_rows = 300

stocksdata = requests.get("" + API_key)
rec = stocksdata.json()['res']
data = pandas.json_normalize(rec)
del data['index']
data['date'] = (pandas.to_datetime(data['date'], unit='ms').dt.tz_localize('utc'))

jupyter notebook

Get stocks list

stockslist = requests.get("" + API_key)
availablestocks = stockslist.json()['stocks_list']

jupyter notebook

Find uptrend stocks.

uptrend_res = requests.get("" + API_key)
uptrends = uptrend_res.json()['uptrend']
uptrends_pandas = pandas.json_normalize(uptrends)

jupyter notebook

Select DNEX.

macd_res = requests.get("" + API_key)
macd = macd_res.json()['MACD']
macd_pandas = pandas.json_normalize(macd)


jupyter notebook
jupyter notebook

If MACD > MACDhist, high > EMA &  MACD < 0 , you should buy.

Below is the Bollinger Band chart.

macd_stocksplot = macd_res.json()['stocksplot']

jupyter notebook

Copy the text and paste it here, you can get the chart (

bollinger band

Entry point, stop loss, and take profit.

pivot_res = requests.get("" + API_key)
pivot = pivot_res.json()['pivot']
pivot_pandas = pandas.json_normalize(pivot)

jupyter notebook

If you take classic pivot, you can set your entry point (Classic_S1-close price), stop loss (Classic_S20), and take profit (Classic_R2-Classic_R3).

You can view other API endpoints available here ( Let us know if you got any difficulties or issues using it.


Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top