Code
Code
Sheet 1
_________________________________________________
ThisWorkbook
_________________________________________________
Call pullOptionChain
End Sub
_________________________________________________
Module1
_________________________________________________
Option Explicit
Sub pullOptionChain()
selectedScrip = Sheets("Sheet1").ComboBox1.Value
specific_browser ("https://www.nseindia.com/")
FetchAgain:
With CreateObject("msxml2.xmlhttp")
specific_browser (webURL)
.send
mainString = .responseText
specific_browser (webURL)
Application.Wait (Now + TimeValue("0:00:5"))
GoTo FetchAgain
Else
End If
End With
ReDim strikePricesArr(Json("records")("strikePrices").Count)
For i = 1 To Json("records")("strikePrices").Count
strikePricesArr(i) = Json("records")("strikePrices")(i)
Next
ReDim expiryDatesArr(Json("records")("expiryDates").Count)
For i = 1 To Json("records")("expiryDates").Count
expiryDatesArr(i) = Json("records")("expiryDates")(i)
Next
Worksheets("Sheet1").Activate
Range("A4:K999").ClearContents
expiryDateStr = expiryDatesArr(1)
Range("A1").Value = "Fetched on: " & Json("records")("timestamp")
Range("F2").Value = Json("records")("underlyingValue")
j = 0
k = 1
aMyArray = Range("A4:K999")
Application.ScreenUpdating = False
For i = 1 To Json("records")("data").Count
j = j + 1
If IsObject(Json("records")("data")(i)("CE")) Then
aMyArray(j, k) = Json("records")("data")(i)("CE")("openInterest")
aMyArray(j, k + 1) = Format(Json("records")("data")(i)("CE")
("changeinOpenInterest"), "#.00")
aMyArray(j, k + 2) = Json("records")("data")(i)("CE")("totalTradedVolume")
aMyArray(j, k + 3) = Json("records")("data")(i)("CE")("impliedVolatility")
aMyArray(j, k + 4) = Json("records")("data")(i)("CE")("lastPrice")
aMyArray(j, k + 5) = Json("records")("data")(i)("strikePrice")
Else
aMyArray(j, k) = ""
aMyArray(j, k + 1) = ""
aMyArray(j, k + 2) = ""
aMyArray(j, k + 3) = ""
aMyArray(j, k + 4) = ""
aMyArray(j, k + 5) = ""
End If
If IsObject(Json("records")("data")(i)("PE")) Then
aMyArray(j, k + 6) = Json("records")("data")(i)("PE")("lastPrice")
aMyArray(j, k + 7) = Json("records")("data")(i)("PE")("impliedVolatility")
aMyArray(j, k + 8) = Json("records")("data")(i)("PE")("totalTradedVolume")
aMyArray(j, k + 9) = Format(Json("records")("data")(i)("PE")
("changeinOpenInterest"), "#.00")
aMyArray(j, k + 10) = Json("records")("data")(i)("PE")("openInterest")
Else
aMyArray(j, k + 6) = ""
aMyArray(j, k + 7) = ""
aMyArray(j, k + 8) = ""
aMyArray(j, k + 9) = ""
aMyArray(j, k + 10) = ""
End If
End If
Next i
Application.ScreenUpdating = True
End Sub
_________________________________________________
Module2
_________________________________________________
Option Explicit
Sub fetchOptionChain()
selectedScrip = Sheets("Sheet1").ComboBox1.Value
specific_browser ("https://www.nseindia.com/")
FetchAgain:
With CreateObject("msxml2.xmlhttp")
specific_browser (webURL)
.send
mainString = .responseText
specific_browser (webURL)
Application.Wait (Now + TimeValue("0:00:5"))
GoTo FetchAgain
GoTo FetchAgain
Else
End If
End With
ReDim strikePricesArr(Json("records")("strikePrices").Count)
For i = 1 To Json("records")("strikePrices").Count
strikePricesArr(i) = Json("records")("strikePrices")(i)
Next
ReDim expiryDatesArr(Json("records")("expiryDates").Count)
For i = 1 To Json("records")("expiryDates").Count
expiryDatesArr(i) = Json("records")("expiryDates")(i)
Next
Worksheets("Sheet1").Activate
Range("A4:K999").ClearContents
expiryDateStr = expiryDatesArr(1)
Range("A1").Value = "Fetched on: " & Json("records")("timestamp")
Range("F2").Value = Json("records")("underlyingValue")
j = 0
k = 1
aMyArray = Range("A4:K999")
Application.ScreenUpdating = False
For i = 1 To Json("records")("data").Count
emptyInfo = 0
j = j + 1
If IsObject(Json("records")("data")(i)("CE")) Then
aMyArray(j, k) = Json("records")("data")(i)("CE")("openInterest")
aMyArray(j, k + 1) = Format(Json("records")("data")(i)("CE")
("changeinOpenInterest"), "#.00")
aMyArray(j, k + 2) = Json("records")("data")(i)("CE")("totalTradedVolume")
aMyArray(j, k + 3) = Json("records")("data")(i)("CE")("impliedVolatility")
aMyArray(j, k + 4) = Json("records")("data")(i)("CE")("lastPrice")
aMyArray(j, k + 5) = Json("records")("data")(i)("strikePrice")
Else
emptyInfo = 1
aMyArray(j, k) = ""
aMyArray(j, k + 1) = ""
aMyArray(j, k + 2) = ""
aMyArray(j, k + 3) = ""
aMyArray(j, k + 4) = ""
aMyArray(j, k + 5) = ""
End If
If IsObject(Json("records")("data")(i)("PE")) Then
If emptyInfo = 0 Then
aMyArray(j, k + 6) = Json("records")("data")(i)("PE")("lastPrice")
aMyArray(j, k + 7) = Json("records")("data")(i)("PE")("impliedVolatility")
aMyArray(j, k + 8) = Json("records")("data")(i)("PE")("totalTradedVolume")
aMyArray(j, k + 9) = Format(Json("records")("data")(i)("PE")
("changeinOpenInterest"), "#.00")
aMyArray(j, k + 10) = Json("records")("data")(i)("PE")("openInterest")
ElseIf emptyInfo = 1 Then
aMyArray(j, k + 5) = Json("records")("data")(i)("strikePrice")
aMyArray(j, k + 6) = Json("records")("data")(i)("PE")("lastPrice")
aMyArray(j, k + 7) = Json("records")("data")(i)("PE")("impliedVolatility")
aMyArray(j, k + 8) = Json("records")("data")(i)("PE")("totalTradedVolume")
aMyArray(j, k + 9) = Format(Json("records")("data")(i)("PE")
("changeinOpenInterest"), "#.00")
aMyArray(j, k + 10) = Json("records")("data")(i)("PE")("openInterest")
Else
aMyArray(j, k + 6) = ""
aMyArray(j, k + 7) = ""
aMyArray(j, k + 8) = ""
aMyArray(j, k + 9) = ""
aMyArray(j, k + 10) = ""
End If
End If
End If
Next i
Application.ScreenUpdating = True
End Sub
________________________________________
Module3
_________________________________________________
Option Explicit
Sub specific_browser(ByVal sURL As String)
End Sub