Search This Blog

Showing posts with label pulling. Show all posts
Showing posts with label pulling. Show all posts

Thursday, November 7, 2019

NSE options Data Pulling with beta.nseindia.com

Beta version they are giving it as JSON which is very easy for us.

See the sample url. 

1. JSON output,
2. Directly use the JSON for your business logic.
3. Before install requests, simplejson plugin
     pip install simplejson
     pip install requests

Same for older version - sample code and output

http://drvijayy2k2.blogspot.com/2019/08/python-code-to-pull-nse-option.html

Code

import requests
import simplejson as json

result = requests.get ( "https://beta.nseindia.com/api/quote-derivative?symbol=NIFTY&identifier=OPTIDXNIFTY07-11-2019" );
resultJson = json.loads( result.content )
#print ( resultJson["info"] );
strikePricesDetailsJson = resultJson["stocks"]
for strikePrice in strikePricesDetailsJson:
    spDetails = strikePrice["metadata"];
    #print ( spDetails );
    print ( spDetails["optionType"] , " : ", spDetails["strikePrice"] , " : ", spDetails["lastPrice"]);



Output

Call  :  12350  :  0
Put  :  11050  :  0

Call  :  12750  :  0


{'metadata': {'instrumentType': 'Index Options', 'expiryDate': '28-Dec-2023', 'optionType': 'Put', 'strikePrice': 12700, 'identifier': 'OPTIDXNIFTY28-12-2023PE12700.00', 'openPrice': 0, 'highPrice': 0, 'lowPrice': 0, 'closePrice': 0, 'prevClose': 1005, 'lastPrice': 0, 'change': -1005, 'pChange': -100, 'numberOfContractsTraded': 0, 'totalTurnover': 0}, 'underlyingValue': 11998.1, 'volumeFreezeQuantity': 5001, 'marketDeptOrderBook': {'totalBuyQuantity': 225, 'totalSellQuantity': 0, 'bid': [{'price': 645.05, 'quantity': 75}, {'price': 645, 'quantity': 75}, {'price': 597, 'quantity': 75}, {'price': 0, 'quantity': 0}, {'price': 0, 'quantity': 0}], 'ask': [{'price': 0, 'quantity': 0}, {'price': 645, 'quantity': 0}, {'price': 0, 'quantity': 0}, {'price': 0, 'quantity': 0}, {'price': 0, 'quantity': 0}], 'carryOfCost': {'price': {'bestBuy': 645.05, 'bestSell': 0, 'lastPrice': 0}, 'carry': {'bestBuy': -70.5660812600072, 'bestSell': 0, 'lastPrice': 0}}, 'tradeInfo': {'tradedVolume': 0, 'value': 0, 'vmap': 0, 'premiumTurnover': 0, 'openInterest': 6, 'changeinOpenInterest': 0, 'pchangeinOpenInterest': 0, 'marketLot': 75}, 'otherInfo': {'settlementPrice': 0, 'dailyvolatility': 0.91, 'annualisedVolatility': 17.45, 'impliedVolatility': 0, 'clientWisePositionLimits': 19597661, 'marketWidePositionLimits': 0}}}



Tuesday, September 17, 2019

Excel VBA - Loading POST REST Webservice JSON

1. Open excel -> developer -> visual basic
2. Tools -> reference (enabled : Microsoft win http services , version 5.1 xx )
3. paste the below code on click sheet1.
4. Click run.
5. Save As excel macro enabled from file type . else your VBA code will not be save.


Dim strResult As String
Dim objHTTP As Object
Dim URL As String
  
Private Sub Worksheet_Activate()
    Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
    
    json_body = "{'Commodity':'CRUDEOIL','Expiry':'17SEP2019'}"
    URL = "https://www.mcxindia.com/backpage.aspx/GetOptionChain"
    
    objHTTP.Open "POST", URL, False
    objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
    objHTTP.SetRequestHeader "Content-type", "application/json"
    objHTTP.Send (json_body)
    strResult = objHTTP.ResponseText
    Worksheets("Sheet1").Range("A10:A10") = strResult
    
End Sub




Hit Counter


View My Stats