Unofficial Python Methods for AliceBlue API

Theoretically, Every broker’s API is free. Historical Data is also free. Like it is done here for 5paisa https://www.youtube.com/watch?v=2PXSfi0Rsho (Note - I had taken permission from 5Paisa.).

Now, If a human can see the data of stock from chart, a machine can do the same. An official API can’t. We can only make wrapper or share methods that are allowed by Alice.

But, Alice’s management is very flexible than other brokers. I already asked for permission for adding some extra functions. If We’re given, Krishna will add to the main API.

  • Alice Blue Screeners.
  • Market Watch Addition
  • Alerts
  • Bid Ask Level 20 data
  • Historical Data API

Here is a list of screener URLs -
In case we don’t get approval, Coders are free to PyRequest these URLs

https://ant.aliceblueonline.com/api/v1/screeners/gainerslosers?index=nifty_50
https://ant.aliceblueonline.com/api/v1/screeners/mostactivestocks?index=nifty_50
https://ant.aliceblueonline.com/api/v1/screeners/volume_shockers?index=nifty_50&days=3
https://ant.aliceblueonline.com/api/v1/screeners/upper_circuit_breakers?index=nifty_50
https://ant.aliceblueonline.com/api/v1/screeners/lower_circuit_breakers?index=nifty_50
https://ant.aliceblueonline.com/api/v1/screeners/roi?index=nifty_50&days=3
https://ant.aliceblueonline.com/api/v1/screeners/yearly_high?index=nifty_50
https://ant.aliceblueonline.com/api/v1/screeners/yearly_low?index=nifty_50
https://ant.aliceblueonline.com/api/v1/screeners/near_yearly_high?index=nifty_50
https://ant.aliceblueonline.com/api/v1/screeners/near_yearly_low?index=nifty_50
https://ant.aliceblueonline.com/api/v1/screeners/near_upper_circuit_breakers?index=nifty_50
https://ant.aliceblueonline.com/api/v1/screeners/near_lower_circuit_breakers?index=nifty_50

The payloads will be different for different URL structures though. alicebot.in already has this screener function too. The commands are not updated because if the market is closed, the screeners give blank output as a return.

===========

Here is an URL that allows you to add the tickers into the Market Watch to the main GUI. Their GUI is very buggy.

https://ant.aliceblueonline.com/api/v2/marketwatch
Type: POST
Sample Payload: {“exchange”:“NSE”,“instrument_token”:“26059”,“symbol”:“NIFTY Alpha 50”,“mw_number”:“mw3”}

There are 5 mw’s.

===========

Here is an URL that allows you to set an alert in the system,
Request URL: https://ant.aliceblueonline.com/api/v1/alerts
Type: POST
Sample Payload: {"exchange":"NSE","instrument_token":"26059","wait_time":"60","condition":"lesser_than","user_set_values":[15459.94],"frequency":"recurring","expiry":1598285779,"state_after_expiry":"deleted","user_message":"NIFTY Alpha 50 Lesser than ₹15459.94"}

========================
Here is an URL that allows you to see bid/ask system up to Level20 at ease.
Request URL: Request URL: https://ant.aliceblueonline.com/api/v2/marketdata?exchange=NSE&instrument_token=3045&type=snapquote
Type: GET

=======================
Here is the famous Historical API You are talking about.
Request URL: Request URL: https://ant.aliceblueonline.com/api/v1/charts?exchange=NSE&token=3045&candletype=1&starttime=1596825000&endtime=1598121000&type=historical&data_duration=10
Type: GET

The times are in Epoch. The cute part is You can fetch Historical Info as much far You can see in the chart.

As said earlier, If humans can do it, So can a machine.

=========

But right now, It’s unofficial.

I will keep you guys updated if we get it approved.

1 Like

Great. We have similar thing with nseindia.

const axios = require('axios').default;
const converter = require('json-2-csv');
const fs = require('fs');
const performance = require('perf_hooks').performance
var sleep = require('sleep')
var urlencode = require('urlencode');
console.time('getallcsv');
console.time("getcsv");
function getcsv(indexname) {
  const index = urlencode(indexname.toUpperCase())
  axios.get('https://www.nseindia.com/api/equity-stockIndices?index=' + index)
    .then(function (response) {
      console.log("name :: ", response.data.name);
      console.log("declines :: ", response.data.advance.declines);
      console.log("advances :: ", response.data.advance.advances);
      console.log("unchanged :: ", response.data.advance.unchanged);
      const test = response.data.name.replace(/ /g, '_');
      const name_of_csv = test.replace('/', '_');
      converter.json2csv(response.data.data, (err, csv) => {
        if (err) {
          throw err;
        }
        // write CSV to a file
        fs.writeFileSync('./csv/' + name_of_csv + '.csv', csv);
      });
    });
}

function get_equity_master() {
  let start_time_b = Date.now();
  axios.get('https://www.nseindia.com/api/equity-master')
    .then(function (response) {
      fs.writeFileSync('./equity_master.json', JSON.stringify(response.data));
      const duration_b = Date.now() - start_time_b;
      console.log("time taken eq master :: ", duration_b, 'ms');
    });
}
// index_names = ['NIFTY BANK','NIFTY PHARMA', 'NIFTY 50', 'NIFTY 100', 'NIFTY 200', 'SECURITIES IN F&O']
// index_names = ["NIFTY 50", "NIFTY NEXT 50", "NIFTY MIDCAP 50", "NIFTY MIDCAP 100", "NIFTY MIDCAP 150",
//   "NIFTY SMALLCAP 50", "NIFTY SMALLCAP 100", "NIFTY SMALLCAP 250", "NIFTY MIDSMALLCAP 400", "NIFTY 100",
//   "NIFTY 200", "NIFTY AUTO", "NIFTY BANK", "NIFTY ENERGY", "NIFTY FINANCIAL SERVICES",
//   "NIFTY FINANCIAL SERVICES 25/50", "NIFTY FMCG", "NIFTY IT", "NIFTY MEDIA", "NIFTY METAL",
//   "NIFTY PHARMA", "NIFTY PSU BANK", "NIFTY REALTY", "NIFTY PRIVATE BANK", "NIFTY COMMODITIES",
//   "NIFTY INDIA CONSUMPTION", "NIFTY CPSE", "NIFTY INFRASTRUCTURE", "NIFTY MNC", "NIFTY GROWTH SECTORS 15",
//   "NIFTY PSE", "NIFTY SERVICES SECTOR", "NIFTY100 LIQUID 15", "NIFTY MIDCAP LIQUID 15",
//   "NIFTY DIVIDEND OPPORTUNITIES 50", "NIFTY50 VALUE 20", "NIFTY100 QUALITY 30", "NIFTY50 EQUAL WEIGHT",

//   "NIFTY100 EQUAL WEIGHT", "NIFTY100 LOW VOLATILITY 30", "NIFTY ALPHA 50", "NIFTY200 QUALITY 30",
//   "NIFTY ALPHA LOW-VOLATILITY 30", "Securities in F&O", "Permitted to Trade"]
// index_names.forEach(getcsv)
get_equity_master()
function getallcsv() {
  var masters = require('../equity_master.json');
  for (item in masters) {
    // console.log(item)
    masters[item].forEach(getcsv);
  }
  console.timeLog("getcsv");
  console.timeEnd("getcsv");
}

getallcsv();
console.timeLog("getallcsv");
console.timeEnd("getallcsv");
// masters['Others'].forEach(getcsv)
  // masters["Broad Market Indices"].forEach(getcsv)
  // masters["Strategy Indices"].forEach(getcsv)
  // masters["Sectoral Indices"].forEach(getcsv)
  // masters["Thematic Indices"].forEach(getcsv)
1 Like