To get a historical time serie (open, high, low, close prices and volume) for a quotation the following steps must be done:
using System;
using log4net;
{
class HistoricalTimeSeries
{
private static ILog log = LogManager.GetLogger("Historical");
private MessageSerializer serializer;
private RoutingDataStore rds;
public void Main()
{
ConfigurationHelper.Initialize();
serializer = new MessageSerializer();
rds = ConfigurationHelper.RoutingDataStore;
DateTime from = new DateTime(2019, 01, 30, 9, 0, 0);
DateTime to = new DateTime(2019, 01, 31, 13, 00, 0);
HistoricalTimeSeriesRequestMessage requestMessage = new HistoricalTimeSeriesRequestMessage
{
header = new RequestHeaderMessage
{
user = Authentication.GetUser(),
password = Authentication.GetPassword()
},
aggregation = HistoricAggregationParam.Day,
instrument = "846900.ETR",
withDividens = false,
withCorporateActions = false,
withIntraday = false,
tickType = TickTypeParam.Trade,
dateFrom = DateTimeConverter.Convert(ref from),
dateTo = DateTimeConverter.Convert(ref to)
};
StaticDataResponse response = rds.CallFunction(StaticDataFunctions.HISTORIC_DATA_V2,
InputFormat.PROTO.ToString(),
OutputFormat.PROTO.ToString(),
serializer.Serialize<HistoricalTimeSeriesRequestMessage>(OutputFormat.PROTO, requestMessage)
);
if (response.GetErrorCode() < 0)
{
log.Warn("Error when calling DMC: " + response.GetErrorMessage());
return;
}
HistoricalTimeSeriesMessage responseMessage = null;
try
{
byte[] responseData = response.GetData();
if (responseData != null && responseData.Length > 0)
{
responseMessage = serializer.Deserialize<HistoricalTimeSeriesMessage>(InputFormat.PROTO, responseData);
if (responseMessage.header != null)
{
if (responseMessage.header.error_code != ErrorCodes.Ok)
{
log.Warn("Error: " + responseMessage.header.error_message);
}
}
else
{
log.Error("The response from the call was empty. Please inform the vwd support to check the server configuration.");
}
}
}
catch (Exception e)
{
log.Error("", e);
}
if (responseMessage == null || responseMessage.header.error_code != ErrorCodes.Ok)
{
log.Error("Response empty or an error occured.");
return;
}
if (responseMessage.entry.Count < 5)
{
log.Error("no entries in response!!!!");
}
foreach (HistoricalTimeSeriesEntryMessage row in responseMessage.entry)
{
DateTime date = DateTime.MinValue;
if (row.time.HasValue)
date = DateTimeConverter.FromUtcMillis(row.time.Value);
Console.WriteLine("Date: " + date.ToShortDateString() + " Open: " + row.open
+ " High: " + row.high
+ " Low: " + row.low
+ " Close: " + row.close
+ " Isue: " + row.issue
+ " Redemtion: " + row.redemption
+ " Volume: " + row.volume);
}
}
}
}