|
|
|
|
Purpose |
Get historical high-low-open-close bars for a financial instrument. | ||||
|
|
| ||||
|
Call Syntax |
#include <aspen.h> … AspenRequest(GLOBAL_session,ASPEN_GetBarHistory,&input,&output); … | ||||
|
|
| ||||
|
Parameters |
Input The input parameter for this service is a pointer to a ASPEN_GETBARS_INPUT that indicates which instrument bar information should be returned by the Aspen Server, and receives the bars information from the Server.
Output The output parameter for this service is a pointer to a ASPEN_GETBARS_OUTPUT structure that identifies how many bars the server provided and indicates the start time, if any, of an additional request necessary to fulfill the current request. | ||||
|
|
| ||||
|
Structures |
typedef struct { ASPEN_INUM inum; ASPEN_BAR *bars; ASPEN_TIME start_time; ASPEN_TIME end_time; int max_bars; int bar_width;
typedef struct { int num_bars; ASPEN_TIME next_time; | ||||
|
|
| ||||
|
Remarks |
ASPEN_GetBarHistory requires:
Call AspenRequest() with either ASPEN_GetInstrumentNumber or ASPEN_GetInstrumentInfo to get a symbol’s inum.
A single ASPEN_GetBarHistory request is capable of populating an array of 250 bars. If a request asks for more than 250 bars, the output structure indicates the time of the next bar required to fullfill the request—in essence, a new start-time for subsequent calls. By nesting an ASPEN_GetBarHistory in a for loop or a while statement, you can successfully fulfill a lengthy request.
Within the context of an ASPEN_GetBarHistory request, you can limit the number of bars received by specifying a number less than 250 (ASPEN_MAX_BARS).
ASPEN_GetBarHistory allows you to specify whether you want daily or intraday bars. If you do not indicate the type of bar you want, a call will return daily bars. | ||||
|
|
| ||||
|
Return Value |
| ||||
|
|
| ||||
|
See Also |
|||||
|
|
| ||||
|
Example |
int CAspenRequestDlg::DoASPEN_GetBarHistory() { server_list *slp = list; ASPEN_GETBARS_INPUT input; ASPEN_GETBARS_OUTPUT output; int service; int retval; int i; CString strText; char openStr[16]; char closeStr[16]; char highStr[16]; char lowStr[16]; char barTimeStr[80];
service = ASPEN_GetBarHistory; // Do StartTime and convert to AspenTime time_of_day = time(NULL); localTime = gmtime(&time_of_day); localTime->tm_mon = start_month - 1; localTime->tm_mday = start_day; localTime->tm_year = start_year - 1900; localTime->tm_hour = 6; localTime->tm_min = 0; localTime->tm_sec = 0; ANSITimeToAspenTime(localTime, localTimeZone, &(input.start_time)); // Do EndTime and convert to AspenTime time_of_day = time(NULL); localTime = gmtime(&time_of_day); localTime->tm_mon = end_month - 1; localTime->tm_mday = end_day; localTime->tm_year = end_year - 1900; localTime->tm_hour = 18; localTime->tm_min = 0; localTime->tm_sec = 0; ANSITimeToAspenTime(localTime, localTimeZone, &(input.end_time)); input.inum = a_getins_input.inum; input.bars = a_bar; input.max_bars = ASPEN_MAX_BARS; input.bar_width = barwidth; retval = AspenRequest(slp->server_session, service, &input, &output); if (!retval) { strText.Format("Num_bars : %d", output.num_bars); m_HistoryEdit.AppendString(strText); strText.Format("Next_time : %d", output.next_time); m_HistoryEdit.AppendString(strText);
for (i = 0; i < output.num_bars; i++) { struct tm localTime; q.base = a_inst.quantum.base; q.exponent = a_inst.quantum.exponent; AspenTimeToANSITime(a_bar[i].time, 0, 0, &localTime, NULL); strftime(barTimeStr, sizeof(barTimeStr), "%A, %B %d, %Y %H:%M", &localTime); strText.Format("%s", barTimeStr); m_HistoryEdit.AppendString(strText); AspenDecodePrice(a_bar[i].open, q, ASPEN_YES, openStr, NULL, NULL, NULL); AspenDecodePrice(a_bar[i].close, q, ASPEN_YES, closeStr, NULL, NULL, NULL); AspenDecodePrice(a_bar[i].high, q, ASPEN_YES, highStr, NULL, NULL, NULL); AspenDecodePrice(a_bar[i].low, q, ASPEN_YES, lowStr, NULL, NULL, NULL); strText.Format("OHLC: %s, %s, %s, %s",openStr,highStr,lowStr,closeStr); m_HistoryEdit.AppendString(strText); } } return retval; } |
©2006 Aspen Research Group, Ltd. All rights reserved. Terms of Use.