'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
Sub Process_Globals
End Sub
Public Sub MidExtract (StringText As String, Start As String, EndAt As String) As String
Dim i1 As Int = StringText.IndexOf(Start) + Start.Length
Dim i2 As Int = StringText.IndexOf2(EndAt, i1)
Return StringText.SubString2(i1, i2)
End Sub
Sub AppStart (Args() As String)
getBarChart
Log("Hello world!!!")
StartMessageLoop
End Sub
Sub getBarChart()
Dim xsrfToken As String
Dim su As StringUtils
Dim job As HttpJob
job.Initialize("", Me)
job.Download("https://www.barchart.com/futures/quotes/CLZ24/price-history/historical")
job.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36")
Wait For (job) JobDone(job As HttpJob)
If job.Success Then
Dim cookies As List
cookies.Initialize
cookies = job.Response.GetHeaders.Get("set-cookie")
xsrfToken = cookies.Get(1).As(String)
xsrfToken = su.DecodeUrl(MidExtract(xsrfToken, "XSRF-TOKEN=", ";"), "UTF8")
Dim job2 As HttpJob
job2.Initialize("", Me)
job2.Download("https://www.barchart.com/proxies/core-api/v1/historical/get?symbol=CLZ24&fields=tradeTime.format(m/d/Y),openPrice,highPrice,lowPrice,lastPrice,priceChange,percentChange,volume,openInterest,symbolCode,symbolType&type=eod&orderBy=tradeTime&orderDir=desc&limit=65&meta=field.shortName,field.type,field.description&raw=1")
job2.GetRequest.SetHeader("X-XSRF-TOKEN", xsrfToken)
job2.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36")
If job2.Success Then
Log(job2.GetString)
End If
job2.Release
End If
job.Release
End Sub