public override int GetHashCode() { unchecked { return((RequestTime.GetHashCode() * 397) ^ (Log != null ? Log.GetHashCode() : 0)); } }
public override string ToString() { var responseBodyLength = 0; if (ResponseBody != null) { responseBodyLength = ResponseBody.Length; } var requestTime = RequestTime.ToString("yyyy-MM-dd HH:mm:ss.fff"); var responseTime = ResponseTime.ToString("yyyy-MM-dd HH:mm:ss.fff"); var requestHeader = string.Empty; if (RequestHeader != null && RequestHeader.Count > 0) { requestHeader = string.Join(",", RequestHeader.Select(x => string.Format("{0}:{1}", x.Key, x.Value))); } var responseHeader = string.Empty; if (ResponseHeader != null && ResponseHeader.Count > 0) { responseHeader = string.Join(",", ResponseHeader.Select(x => string.Format("{0}:{1}", x.Key, x.Value))); } return(string.Format("[RequestType:{0}, RequestCode:{1}, RequestSequence:{2}, RequestTime:{3}, RequestHeader: [{4}], ResponseCode:{5}, ResponseTime:{6}, ResponseBodyLength:{7}, ResponseHeader: [{8}]]", RequestType, RequestCode, RequestSequence, requestTime, requestHeader, ResponseCode, responseTime, responseBodyLength, responseHeader)); }
public XmlNode ToXmlNode(XmlDocument xDoc) { XmlNode xInput = xDoc.CreateElement("Input"); // TODO: Add Description and Groupings xInput.AppendChild(xDoc.CreateElement("Value")).InnerText = _value; xInput.AppendChild(xDoc.CreateElement("RequestTime")).InnerText = RequestTime.ToString(); xInput.AppendChild(xDoc.CreateElement("ResponseTime")).InnerText = ResponseTime.ToString(); xInput.AppendChild(xDoc.CreateElement("Delay")).InnerText = Delay.Value.Ticks.ToString(); xInput.AppendChild(xDoc.CreateElement("Method")).InnerText = Method.ToString(); xInput.AppendChild(xDoc.CreateElement("Description")).AppendChild(xDoc.CreateCDataSection(Description)); if (OptionReference != null) { xInput.AppendChild(OptionReference.ToXmlNode(xDoc)); } var xInputTransforms = xInput.AppendChild(xDoc.CreateElement("Transforms")); if (Transforms?.Length > 0) { foreach (InputTransform inputTransform in Transforms) { xInputTransforms.AppendChild(inputTransform.ToXmlNode(xDoc)); } } return(xInput); }
public override int GetHashCode() { unchecked { int hashCode = StationYear.GetHashCode();//(StationYear != null ? StationYear.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Priority; hashCode = (hashCode * 397) ^ RequestTime.GetHashCode(); hashCode = (hashCode * 397) ^ LastRun.GetHashCode();//(LastRun != null ? LastRun.GetHashCode() : 0); return(hashCode); } }
/// <summary> /// Returns true if ResponseMetricsListData instances are equal /// </summary> /// <param name="other">Instance of ResponseMetricsListData to be compared</param> /// <returns>Boolean</returns> public bool Equals(ResponseMetricsListData other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( RequestTime == other.RequestTime || RequestTime != null && RequestTime.Equals(other.RequestTime) ) && ( Availability == other.Availability || Availability != null && Availability.Equals(other.Availability) ) && ( Invocations == other.Invocations || Invocations != null && Invocations.Equals(other.Invocations) ) && ( AverageResponse == other.AverageResponse || AverageResponse != null && AverageResponse.Equals(other.AverageResponse) ) && ( AverageTps == other.AverageTps || AverageTps != null && AverageTps.Equals(other.AverageTps) ) && ( PeakTps == other.PeakTps || PeakTps != null && PeakTps.Equals(other.PeakTps) ) && ( Errors == other.Errors || Errors != null && Errors.Equals(other.Errors) ) && ( Rejections == other.Rejections || Rejections != null && Rejections.Equals(other.Rejections) )); }
public override string ToString() { var result = new StringBuilder(); result.AppendLine("BuildRequestRecord"); result.AppendLine("ReceiveTunnel : " + ReceiveTunnel.ToString()); result.AppendLine("OurIdent : " + OurIdent.ToString()); result.AppendLine("NextTunnel : " + NextTunnel.ToString()); result.AppendLine("NextIdent : " + NextIdent.ToString()); result.AppendLine("Flag : 0x" + Flag.ToString("X2")); result.AppendLine("ToAnyone : " + ToAnyone.ToString()); result.AppendLine("FromAnyone : " + FromAnyone.ToString()); result.AppendLine("RequestTime : " + RequestTime.ToString()); result.AppendLine("SendMessageId : " + SendMessageId.ToString()); return(result.ToString()); }
public int CompareTo(StationYearRequest other) { int compareTo; if ((compareTo = Priority.CompareTo(other.Priority)) != 0) { return(compareTo); } if ((compareTo = RequestTime.CompareTo(other.RequestTime)) != 0) { return(compareTo); } if ((compareTo = StationYear.CompareTo(other.StationYear)) != 0) { return(compareTo); } return(0); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (RequestTime != null) { hashCode = hashCode * 59 + RequestTime.GetHashCode(); } if (Availability != null) { hashCode = hashCode * 59 + Availability.GetHashCode(); } if (Invocations != null) { hashCode = hashCode * 59 + Invocations.GetHashCode(); } if (AverageResponse != null) { hashCode = hashCode * 59 + AverageResponse.GetHashCode(); } if (AverageTps != null) { hashCode = hashCode * 59 + AverageTps.GetHashCode(); } if (PeakTps != null) { hashCode = hashCode * 59 + PeakTps.GetHashCode(); } if (Errors != null) { hashCode = hashCode * 59 + Errors.GetHashCode(); } if (Rejections != null) { hashCode = hashCode * 59 + Rejections.GetHashCode(); } return(hashCode); } }
public override int GetHashCode() { int hash = 1; if (security_ != null) { hash ^= Security.GetHashCode(); } if (RequestTime.Length != 0) { hash ^= RequestTime.GetHashCode(); } if (RequestTimeStamp != 0L) { hash ^= RequestTimeStamp.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
internal override bool Process(FTController ibController, bool allowNewRequest) { const int requestTimeoutPeriod = 20; // if no contract received yet if (TickerData.ContractStatus == ContractStatus.SendRequest || TickerData.ContractStatus == ContractStatus.WaitForResponse) { return(allowNewRequest); } // if no contract found if (TickerData.ContractStatus != ContractStatus.Ok) { TickerData.HeadTimestampStatus = HeadTimestampStatus.Failed; IsFinished = true; return(allowNewRequest); } lock (TickerData) // request handling { // if not waiting for response switch (TickerData.HeadTimestampStatus) { // if marked to get headtimestamp case HeadTimestampStatus.SendRequest: if (allowNewRequest) { LogAndMessage.Log(TickerData, MessageType.Trace, "Requesting earliest data point. " + ToString(false, LogAndMessage.VerboseLog)); TickerData.HeadTimestampStatus = HeadTimestampStatus.WaitForResponse; RequestTime = DateTime.Now; ibController.SendHeadTimestampRequest(Id, TickerData); } return(false); // if request is sent, but response has not arrived yet // see ibClient_HeadTimestamp event handler case HeadTimestampStatus.WaitForResponse: // if no answer in time if (RequestTime.AddSeconds(requestTimeoutPeriod) < DateTime.Now) { if (RequestTimeouts == 0) { LogAndMessage.LogAndQueue(TickerData, MessageType.Error, "Request of earliest data point timed out. Retrying. " + ToString(true, LogAndMessage.VerboseLog)); RequestTimeouts++; TickerData.HeadTimestampStatus = HeadTimestampStatus.SendRequest; Id = IBClientHelper.GetNextReqId(); goto case HeadTimestampStatus.SendRequest; } LogAndMessage.LogAndQueue(TickerData, MessageType.Error, "Request of earliest data point timed out. " + ToString(true, LogAndMessage.VerboseLog)); TickerData.HeadTimestampStatus = HeadTimestampStatus.Failed; goto case HeadTimestampStatus.Failed; } return(allowNewRequest); // if new, offline ticker case HeadTimestampStatus.Offline: // ticker's HeadTimestamp is updated case HeadTimestampStatus.Ok: // ticker's HeadTimestamp is NOT updated (we do not mark ticker as failed. it still may work!) case HeadTimestampStatus.Failed: IsFinished = true; return(allowNewRequest); // this is program error default: TickerData.HeadTimestampStatus = HeadTimestampStatus.Failed; IsFinished = true; return(allowNewRequest); } } }
public bool Equals(StationYearRequest other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Equals(StationYear, other.StationYear) && Priority == other.Priority && RequestTime.Equals(other.RequestTime) && Equals(LastRun, other.LastRun)); }
internal override bool Process(FTController ibController, bool allowNewRequest) { const int requestTimeoutPeriod = 10; lock (TickerData) // request handling { // if not waiting for response switch (TickerData.ContractStatus) { // if marked to get contract details case ContractStatus.SendRequest: if (allowNewRequest) { LogAndMessage.Log(TickerData, MessageType.Trace, "Getting contract. " + ToString(false, LogAndMessage.VerboseLog)); Contract contract = new Contract(); contract.Exchange = TickerData.SymbolParts.Exchange; contract.SecType = TickerData.SymbolParts.SecurityType; contract.Currency = TickerData.SymbolParts.Currency; contract.IncludeExpired = true; if (TickerData.SymbolParts.IsContinuous) { if (!string.IsNullOrEmpty(TickerData.SymbolParts.Underlying)) { contract.Symbol = TickerData.SymbolParts.Underlying; } else { contract.Symbol = TickerData.SymbolParts.Symbol; } } else { contract.LocalSymbol = TickerData.SymbolParts.Symbol; } TickerData.contractDetailsList.Clear(); TickerData.ContractStatus = ContractStatus.WaitForResponse; RequestTime = DateTime.Now; ibController.SendContractDetailsRequest(Id, contract); } return(false); // if request is sent, but response has not arrived yet // see ibclient_ContractDetails and ibclient_ContractDetailsEnd event handlers case ContractStatus.WaitForResponse: // if no answer in Time if (RequestTime.AddSeconds(requestTimeoutPeriod) < DateTime.Now) { LogAndMessage.LogAndQueue(TickerData, MessageType.Error, "Getting contract info timed out, symbol is offline. " + ToString(true, LogAndMessage.VerboseLog)); TickerData.ContractStatus = ContractStatus.Failed; goto case ContractStatus.Failed; } return(allowNewRequest); // if new, offline ticker case ContractStatus.Offline: goto case ContractStatus.Failed; // contract found case ContractStatus.Ok: goto case ContractStatus.Failed; // no contract found case ContractStatus.Failed: IsFinished = true; return(allowNewRequest); default: throw new ArgumentOutOfRangeException(); } } }
internal override bool Process(FTController ibController, bool allowNewRequest) { int requestTimeoutPeriod = 75; // if contract of the ticker is still being retrieved or headtimestamp of the ticker is needed (not Offline) AND not yet retrieved if (TickerData.ContractStatus <= ContractStatus.WaitForResponse || ((FTDataSource.Periodicity == Periodicity.EndOfDay || FTDataSource.AllowMixedEODIntra) && TickerData.HeadTimestampStatus <= HeadTimestampStatus.WaitForResponse)) { return(allowNewRequest); } if (TickerData.ContractStatus == ContractStatus.Failed || TickerData.ContractStatus == ContractStatus.Offline || TickerData.HeadTimestampStatus == HeadTimestampStatus.Failed || (TickerData.HeadTimestampStatus == HeadTimestampStatus.Offline && (FTDataSource.Periodicity == Periodicity.EndOfDay || FTDataSource.AllowMixedEODIntra))) { TickerData.QuoteDataStatus = QuotationStatus.Failed; IsFinished = true; return(allowNewRequest); } lock (TickerData) // request handling { // if reqHistoricalData is send to IB and we are waiting for answer if (WaitingForResponse) { // request is not yet timed out... if (RequestTime.AddSeconds(requestTimeoutPeriod) > DateTime.Now) { return(allowNewRequest); } // no response arrived in time, request is timed out... LogAndMessage.LogAndQueue(TickerData, MessageType.Info, "Historical data request has timed out. " + ToString(true, LogAndMessage.VerboseLog)); RequestTimeouts++; WaitingForResponse = false; // if there were too many reqHistoricalData timeouts if (RequestTimeouts > 2) { // drop this ticker... TickerData.QuoteDataStatus = QuotationStatus.Failed; IsFinished = true; return(allowNewRequest); } } // if no new request can be sent (request pacing) bool histThrottling = !allowNewRequest || TickerData.QuoteDataStatus > QuotationStatus.New && RequestTime.AddSeconds(6.5) > DateTime.Now; // process the ticker depending on its state switch (TickerData.QuoteDataStatus) { case QuotationStatus.Offline: LogAndMessage.Log(MessageType.Error, "Program error. Offline ticker cannot get historical update."); IsFinished = true; return(allowNewRequest); // All historical data requests are processed for the ticker // (the last CalcNextHistoricalDataRequest call sets this state) case QuotationStatus.DownloadedEod: #region Merging and backadjusting downloaded quotes of different contracts/expiry into a simgle QuotationList of the continuous contract if (TickerData.SymbolParts.IsContinuous) { QuotationList mergedQuotes = new QuotationList(FTDataSource.Periodicity); int newQuoteIndex; foreach (ContractDetails cd in TickerData.contractDetailsList) { // if there were no quotes receiced for this contract... if (!TickerData.ContinuousQuotesDictionary.ContainsKey(cd.Contract.LocalSymbol)) { continue; } newQuoteIndex = 0; if (mergedQuotes.Count > 0) { int mergedQuoteIndex = mergedQuotes.Count - 1; AmiDate mergedQuoteDateTime = mergedQuotes[mergedQuoteIndex].DateTime; // move forward to the first quote not overlqapping with prev contract while (newQuoteIndex < TickerData.ContinuousQuotesDictionary[cd.Contract.LocalSymbol].Count - 1 && TickerData.ContinuousQuotesDictionary[cd.Contract.LocalSymbol][newQuoteIndex].DateTime.Date < mergedQuoteDateTime.Date) { newQuoteIndex++; } // at this point newQuoteIndex points to a quote of the "same" date as mergedQuoteDateTime (if there are quotes for the same day, if not, then the next day) // if daily database then we look for a day where volume on older contract is greater (switch over day) if (FTDataSource.Periodicity == Periodicity.EndOfDay) { // find the quote that has a lower volume while (newQuoteIndex > 0 && mergedQuoteIndex > 0 && TickerData.ContinuousQuotesDictionary[cd.Contract.LocalSymbol][newQuoteIndex].DateTime.Date == mergedQuotes[mergedQuoteIndex].DateTime.Date && // quotes are of same date TickerData.ContinuousQuotesDictionary[cd.Contract.LocalSymbol][newQuoteIndex].Volume > mergedQuotes[mergedQuoteIndex].Volume) // new contract's volume is higher then old contract's volume { newQuoteIndex--; mergedQuoteIndex--; } // at this point newQuoteIndex and lastQuoteDateTime point to quote at which contract is replaced } if (TickerData.ContinuousQuotesDictionary[cd.Contract.LocalSymbol][newQuoteIndex].DateTime.Date != mergedQuotes[mergedQuoteIndex].DateTime.Date) { LogAndMessage.Log(MessageType.Info, TickerData.ToString(cd.Contract) + ": No overlapping quote found. Used dates to change contracts: " + mergedQuotes[mergedQuoteIndex].DateTime + " and " + TickerData.ContinuousQuotesDictionary[cd.Contract.LocalSymbol][newQuoteIndex].DateTime + "."); } else { LogAndMessage.Log(MessageType.Info, TickerData.ToString(cd.Contract) + ": Switching to new contract on " + mergedQuotes[mergedQuoteIndex].DateTime + "."); } // get "closing prices" of the contract on the same day float closeOfNewer = TickerData.ContinuousQuotesDictionary[cd.Contract.LocalSymbol][newQuoteIndex].Price; float closeOfOlder = mergedQuotes[mergedQuoteIndex].Price; double priceMult = closeOfNewer / closeOfOlder; // back-adjust prev contracts' prices QuotationList tempList = new QuotationList(FTDataSource.Periodicity); for (int i = 0; i < mergedQuoteIndex; i++) { Quotation quote = mergedQuotes[i]; quote.Open = (float)(quote.Open * priceMult); quote.High = (float)(quote.High * priceMult); quote.Low = (float)(quote.Low * priceMult); quote.Price = (float)(quote.Price * priceMult); tempList.Merge(quote); } mergedQuotes.Clear(); mergedQuotes = tempList; } // add quotes of newer contract for (; newQuoteIndex < TickerData.ContinuousQuotesDictionary[cd.Contract.LocalSymbol].Count; newQuoteIndex++) { mergedQuotes.Merge(TickerData.ContinuousQuotesDictionary[cd.Contract.LocalSymbol][newQuoteIndex]); } } TickerData.Quotes = mergedQuotes; } #endregion // this is not THROTTLED, but counted in general throttling queue ibController.SendSubscriptionRequest(0, TickerData, false); TickerData.QuoteDataStatus = QuotationStatus.Online; return(allowNewRequest); // this should never happen (ticker with online status should not be in the queue...) case QuotationStatus.Online: LogAndMessage.LogAndQueue(TickerData, MessageType.Info, "Backfill finished, symbol is ready. "); IsFinished = true; return(allowNewRequest); // if any error happend case QuotationStatus.Failed: // if intraday download received no data response if (errorCode == 162 && FTDataSource.Periodicity < Periodicity.EndOfDay && FTDataSource.Periodicity > Periodicity.FifteenSeconds) { errorCode = 0; // move forward 4 periods to speed up download/find first valid period with available data CalcNextBackfillRequest(); CalcNextBackfillRequest(); CalcNextBackfillRequest(); LogAndMessage.Log(TickerData, MessageType.Trace, "No data returned, fast forward download period."); // start next download TickerData.QuoteDataStatus = QuotationStatus.DownloadingIntra; return(allowNewRequest); } else { LogAndMessage.LogAndQueue(TickerData, MessageType.Info, "Backfill failed, symbol is offline."); IsFinished = true; return(allowNewRequest); } // start historical data refresh case QuotationStatus.New: if (histThrottling) { return(false); } // calc download properties downloadPeriodicity = FTDataSource.Periodicity; downloadStep = IBClientHelper.GetDownloadStep(FTDataSource.Periodicity); downloadInterval = IBClientHelper.GetDownloadInterval(FTDataSource.Periodicity); downloadStart = IBClientHelper.GetAdjustedStartDate(TickerData.RefreshStartDate, FTDataSource.Periodicity, GetEarliestDownloadDate(), true); downloadEnd = downloadStart.AddMinutes(downloadInterval); downloadContract = GetCurrentContract(downloadStart); // remove quotes already stored TickerData.Quotes.Clear(); // set next state if (FTDataSource.Periodicity == Periodicity.EndOfDay) { TickerData.QuoteDataStatus = QuotationStatus.DownloadingEod; } else { TickerData.QuoteDataStatus = QuotationStatus.DownloadingIntra; } // not to wait to send next request RequestTime = DateTime.MinValue; // download historical data SendBackfillRequest(ibController); return(false); case QuotationStatus.DownloadingEod: case QuotationStatus.DownloadingIntra: if (histThrottling) { return(false); } // if previous request timed out if (RequestTimeouts != 0) { SendBackfillRequest(ibController); } // download historical data else if (CalcNextBackfillRequest()) { SendBackfillRequest(ibController); } return(false); // last CalcNextHistoricalDataRequest call for intraday bars should have set this state case QuotationStatus.DownloadedIntra: // if we need EOD data as well if (FTDataSource.AllowMixedEODIntra) { if (histThrottling) { return(false); } // calc download properties for EOD downloadPeriodicity = Periodicity.EndOfDay; downloadStep = IBClientHelper.GetDownloadStep(Periodicity.EndOfDay); downloadInterval = IBClientHelper.GetDownloadInterval(Periodicity.EndOfDay); downloadStart = IBClientHelper.GetAdjustedStartDate(TickerData.RefreshStartDate, Periodicity.EndOfDay, GetEarliestDownloadDate(), true); downloadEnd = downloadStart.AddMinutes(downloadInterval); downloadContract = GetCurrentContract(downloadStart); SendBackfillRequest(ibController); TickerData.QuoteDataStatus = QuotationStatus.DownloadingEod; } else { TickerData.QuoteDataStatus = QuotationStatus.DownloadedEod; } return(false); default: LogAndMessage.LogAndQueue(TickerData, MessageType.Info, "Program error in backfill logic."); IsFinished = true; return(true); } } }