Support Board
Date/Time: Sun, 24 Nov 2024 02:03:12 +0000
Post From: Make HTTP request on each bar
[2024-07-13 23:07:35] |
d9e5c763 - Posts: 108 |
if anyone else needs this functionality, you can refer to my code: #include "sierrachart.h" SCDLLName("SC Custom Studies") SCSFExport scsf_ReadOpenInterest(SCStudyGraphRef sc) { if (sc.SetDefaults) { sc.GraphName = "Intraday Open Interest"; sc.StudyDescription = "Reads Open Interest data from RESTful interface in intraday charts"; sc.AutoLoop = 1; sc.GraphRegion = 1; sc.ValueFormat = 26; sc.Subgraph[0].Name = "Open Interest"; sc.Subgraph[0].DrawStyle = DRAWSTYLE_BAR; sc.Subgraph[0].PrimaryColor = RGB(0, 255, 0); return; } SCString Message; SCString Symbol = sc.Symbol; n_ACSIL::s_BarPeriod BarPeriod; sc.GetBarPeriodParameters(BarPeriod); int SecondsPerBar = BarPeriod.IntradayChartBarPeriodParameter1; if (Symbol && sc.Index == sc.DataStartIndex) { if (BarPeriod.ChartDataType != INTRADAY_DATA) { sc.AddMessageToLog("this study is only for intraday charts", 1); return; } if (BarPeriod.IntradayChartBarPeriodType != IBPT_DAYS_MINS_SECS) { sc.AddMessageToLog("this study is only for time-based intraday charts", 1); return; } Message.Format("chart bar period parameter (seconds): %d", SecondsPerBar); sc.AddMessageToLog(Message, 1); SCString timeZone = sc.GetChartTimeZone(sc.ChartNumber); if (timeZone.Compare("UTC+00") != 0) { Message.Format("chart time zone is not UTC: %s", timeZone.GetChars()); sc.AddMessageToLog(Message, 1); return; } } int& RequestState = sc.GetPersistentInt(1); int& CurrentBarIndex = sc.GetPersistentInt(2); if (RequestState == HTTP_REQUEST_ERROR || RequestState == HTTP_REQUEST_RECEIVED) { SCDateTime CurrentBarDateTime = sc.BaseDateTimeIn[CurrentBarIndex]; uint32_t DateTime = static_cast<uint32_t>(CurrentBarDateTime.ToUNIXTime()); SCString RequestURL; RequestURL.Format("http://127.0.0.1:8001/%s/%d/%u", Symbol.GetChars(), SecondsPerBar, DateTime); if (!sc.MakeHTTPRequest(RequestURL)) { return; } RequestState = HTTP_REQUEST_MADE; } if (RequestState == HTTP_REQUEST_MADE && sc.HTTPRequestID != 0) { const char* HTTPResponseChars = sc.HTTPResponse.GetChars(); if (isdigit(HTTPResponseChars[0])) { RequestState = HTTP_REQUEST_RECEIVED; int OpenInterestValue = atoi(HTTPResponseChars); sc.Subgraph[0][CurrentBarIndex] = OpenInterestValue; Message.Format("CurrentBarIndex: %d; OpenInterestValue: %d", CurrentBarIndex, OpenInterestValue); sc.AddMessageToLog(Message, 1); if (OpenInterestValue > 0) {CurrentBarIndex++;} } } } btw, is there any way to disable the 'Making HTTP request.' message from being displayed in the message log? this message will appears every time when the chart is refreshed or updated |