How to calculate programtically Basis or spread ?(This difference in price between the futures price and the spot price is called the “basis or spread”.)
You can use Web Socket or bulk fetch API to fetch real time LTP for both underlying and future scrip(go through this and this documentation ) and calculate difference.