internal MarketMessageSubscriptionData(Subscription sub, Dictionary <string, object> fields) : base(new Name("MarketDataEvents"), sub.CorrelationID, null) { this._fields = new Dictionary <string, Element>(); foreach (var item in fields) { Element elm = null; if (item.Value is double) { elm = new MarketElementDouble(item.Key, (double)item.Value); } else if (item.Value is Datetime) { Datetime temp = (Datetime)item.Value; bool isDate = temp.HasParts(Datetime.DATE); bool isTime = temp.HasParts(Datetime.TIME); bool isDatetime = isDate && isTime; if (isDatetime) { elm = new MarketElementDatetime(item.Key, temp.ToSystemDateTime()); } else if (isDate) { elm = new MarketElementDate(item.Key, temp.ToSystemDateTime()); } else if (isTime) { elm = new MarketElementTime(item.Key, temp.ToSystemDateTime()); } } else if (item.Value is int) { elm = new MarketElementInt(item.Key, (int)item.Value); } else if (item.Value is string) { elm = new MarketElementString(item.Key, (string)item.Value); } else if (item.Value is bool) { elm = new MarketElementBool(item.Key, (bool)item.Value); } if (elm != null) { this._fields.Add(item.Key, elm); } } this._security = sub.Security; }
internal MessageMarketSubscriptionData(Subscription sub, Dictionary <string, object> fields) : base(new Name("MarketDataEvents"), sub.CorrelationID, null) { this._fields = new Dictionary <string, Element>(); foreach (var item in fields) { Element elm = null; if (item.Value is double) { elm = new ElementMarketDouble(item.Key, (double)item.Value); } else if (item.Value is Datetime) { Datetime temp = (Datetime)item.Value; switch (temp.DateTimeType) { case Datetime.DateTimeTypeEnum.date: elm = new ElementMarketDate(item.Key, temp.ToSystemDateTime()); break; case Datetime.DateTimeTypeEnum.time: elm = new ElementMarketTime(item.Key, temp.ToSystemDateTime()); break; case Datetime.DateTimeTypeEnum.both: elm = new ElementMarketDatetime(item.Key, temp.ToSystemDateTime()); break; } } else if (item.Value is int) { elm = new ElementMarketInt(item.Key, (int)item.Value); } else if (item.Value is string) { elm = new ElementMarketString(item.Key, (string)item.Value); } else if (item.Value is bool) { elm = new ElementMarketBool(item.Key, (bool)item.Value); } if (elm != null) { this._fields.Add(item.Key.ToUpper(), elm); } } this._security = sub.Security; }
internal RequestIntradayBarElementTime(string elementName, Datetime date) : this(elementName, date.ToSystemDateTime()) { this._instance = date.ToSystemDateTime(); }
internal RequestHistoricElementDate(string elementName, Datetime date) : this(elementName, date.ToSystemDateTime()) { this._instance = date.ToSystemDateTime(); }
internal static string FormatDatetime(Datetime datetime) { return(datetime.ToSystemDateTime().ToString("yyyy-MM-ddTHH:mm:ss.fff")); }
internal static string FormatDate(Datetime date) { return(date.ToSystemDateTime().ToString("yyyy-MM-dd")); }
internal static string FormatDateZone(Datetime date) //default date { return(date.ToSystemDateTime().ToString("yyyy-MM-dd%K")); //mkt data has time zone information, but the other requests don't }
internal static string FormatDatetimeZone(Datetime datetime) //default datetime { return(datetime.ToSystemDateTime().ToString("yyyy-MM-dd HH:mm:ss.fff%K")); }
internal static string FormatTimeZone(Datetime time) //default time { return(time.ToSystemDateTime().ToString("HH:mm:ss.fff%K")); }
/// <summary> /// Processes data received from Blg /// </summary> /// <param name="eventObj">Blg Event</param> private void processResponseEvent(Event eventObj) { foreach (Message msg in eventObj) { if (msg.HasElement(RESPONSE_ERROR)) { printErrorInfo("REQUEST FAILED: ", msg.GetElement(RESPONSE_ERROR)); continue; } if (options.reqType == BlgRequests.reference) { Element security = msg.GetElement(SECURITY_DATA); for (int j = 0; j < security.NumValues; ++j) { string ticker = ""; Element temp; if (!CheckBBRunning()) { temp = ((Element)security.Elements.ElementAt(j)); } else { temp = ((Element)security[j]); } ticker = temp.GetElementAsString(SECURITY); Element fieldDataArray = temp.GetElement(FIELD_DATA); foreach (string s in options.fields) { string tempres; try { tempres = fieldDataArray.GetElementAsString(s); counter++; } catch (NotFoundException) { continue; } catch (Exception) { tempres = fieldDataArray.GetElementAsFloat64(s).ToString(); } res1.Add(new string[2] { s, ticker }, tempres); } } } else { Element security = msg.GetElement(SECURITY_DATA); string ticker = ""; System.Console.WriteLine("Processing securities:"); try { ticker = security.GetElementAsString(SECURITY); } catch (Exception) { security = (Element)security[0]; ticker = security.GetElementAsString(SECURITY).Remove(0, 6); } System.Console.WriteLine("\nTicker: " + ticker); if (security.HasElement(SECURITY_ERROR)) { printErrorInfo("\tSECURITY FAILED: ", security.GetElement(SECURITY_ERROR)); errors.Add(ticker, security.GetElement(SECURITY_ERROR).GetElementAsString(MESSAGE)); continue; } try { Element fieldexc = ((Element)security.GetElement(FIELD_EXCEPTIONS)[0]); printErrorInfo("\tFIELD EXCEPTION: ", fieldexc.GetElement(HISTORY_RESPONSE_ERROR)); errors.Add(ticker, fieldexc.GetElement(HISTORY_RESPONSE_ERROR).GetElementAsString(MESSAGE)); continue; } catch (Exception) { } Element fieldDataArray = security.GetElement(FIELD_DATA); DateTime date = new DateTime(); double value = 0; System.Console.WriteLine("FIELD\t\tVALUE"); System.Console.WriteLine("-----\t\t-----"); for (int j = 0; j < fieldDataArray.NumValues; ++j) { Element fieldData = fieldDataArray.GetValueAsElement(j); Datetime temp = fieldData.GetElementAsDatetime("date"); counter++; datecounter++; double valtemp = 0; foreach (string s in options.fields) { string tempres; counter++; try { tempres = fieldData.GetElementAsString(s); } catch (NotFoundException) { continue; } if (!Double.TryParse(tempres, out valtemp)) { break; } else { date = temp.ToSystemDateTime(); value = valtemp; if (date != null && value != 0) { res2.Add(new string[2] { s, ticker }, new HistoData(date, value)); } } } } System.Console.WriteLine(date.ToString() + "\t\t" + value.ToString()); } } }
internal HistoricRequestElementDate(string elementName, Datetime date) { this._instance = date.ToSystemDateTime(); this._elementName = elementName; }