Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Function GetQuoteRange(ByVal SymbolName As String, ByVal StartDate As Date, ByVal EndDate As Date, Optional ByVal AdjustSplits As Boolean = True) As Quote()
- Dim Data(), DataQuote() As String
- Dim tempquote() As Quote
- Dim i As Integer
- Dim NoQuotes As Boolean = False
- Dim MainQuoteHolder() As Quote
- Try
- '-----------------------------------------------------------
- Dim myReq As System.Net.HttpWebRequest = System.Net.WebRequest.Create("http://google.com/finance/historical?q=tadawul:" & SymbolName & "&enddate=" & Microsoft.VisualBasic.DateAndTime.MonthName(EndDate.Month, True) & "+" + CStr(EndDate.Day) + "+" + CStr(EndDate.Year) + "&startdate=" & Microsoft.VisualBasic.DateAndTime.MonthName(StartDate.Month, True) & "+" & CStr(StartDate.Day) & "+" + CStr(StartDate.Year) + "&output=csv")
- 'Dim myReq As System.Net.HttpWebRequest = System.Net.WebRequest.Create("http://google.com/finance/historical?q=tadawul:" & SymbolName & "&output=csv")
- Dim wres As System.Net.HttpWebResponse = myReq.GetResponse
- Dim sr As New IO.StreamReader(wres.GetResponseStream)
- Dim str As String = sr.ReadToEnd
- wres.Close()
- Debug.Write("Data:")
- Debug.WriteLine(str)
- Dim j As Integer
- j = 1
- Data = Split(Replace(str, Chr(13), "", 1, -1, CompareMethod.Binary), Chr(10))
- If ((Data.Length - 3) > 0) Then
- ReDim tempquote(Data.Length - 3)
- For i = 1 To Data.Length - 2 Step 1 'start on the second row, skip the header
- DataQuote = Split(Data(i), ",")
- If (Replace(FixDateMod(DataQuote(0)), "/0", "/", , , CompareMethod.Binary) <> StartDate) Then 'skip the quote if its the same day as StartDate to avoid duplicate quotes
- If AdjustSplits = True Then
- tempquote(j - 1) = New Quote(FixDateMod(DataQuote(0)), DataQuote(1), DataQuote(2), DataQuote(3), DataQuote(4), 0, DataQuote(5))
- Else
- tempquote(j - 1) = New Quote(FixDateMod(DataQuote(0)), DataQuote(1), DataQuote(2), DataQuote(3), DataQuote(4), 0, DataQuote(5))
- End If
- j = j + 1
- Else
- If (tempquote.Length > 0) Then
- ReDim Preserve tempquote(tempquote.Length - 2)
- End If
- End If
- Next
- End If
- If (Not (tempquote Is Nothing)) Then
- If (Not (MainQuoteHolder Is Nothing)) Then
- Dim p As Single
- For p = 0 To MainQuoteHolder.Length - 1 Step 1
- If (tempquote.Length > 1) Then
- If (tempquote(1).QDate = MainQuoteHolder(p).QDate) Then
- NoQuotes = True
- End If
- Else
- NoQuotes = True
- Exit For
- End If
- Next
- End If
- If (NoQuotes = False) Then
- If (MainQuoteHolder Is Nothing) Then
- ReDim MainQuoteHolder(tempquote.Length - 1)
- System.Array.Copy(tempquote, MainQuoteHolder, tempquote.Length)
- Else
- Dim tempquote2() As Quote
- ReDim tempquote2(MainQuoteHolder.Length - 1)
- tempquote2 = MainQuoteHolder
- ReDim MainQuoteHolder(tempquote.Length - 1 + MainQuoteHolder.Length - 1) 'Reduce the size of the array is a line is skipped
- Dim k As Integer
- For k = 0 To tempquote2.Length - 1 Step 1
- MainQuoteHolder(k) = tempquote2(k)
- Next
- For k = 1 To tempquote.Length - 1 Step 1
- MainQuoteHolder(k + tempquote2.Length - 1) = tempquote(k)
- Next
- End If
- End If
- EndDate = MainQuoteHolder(MainQuoteHolder.Length - 1).QDate
- Else
- NoQuotes = True
- End If
- 'End While
- GetQuoteRange = MainQuoteHolder
- Catch ex As Net.WebException
- Debug.WriteLine(ex.Message)
- Return Nothing
- Catch ex As Exception
- End Try
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement