コード例 #1
0
            /// <summary>
            /// Transform received data into BaseData object
            /// </summary>
            /// <param name="e">Received data</param>
            /// <param name="requestData">Request information</param>
            /// <returns>BaseData object</returns>
            private BaseData GetData(LookupEventArgs e, HistoryRequest requestData)
            {
                var isEquity = requestData.SecurityType == SecurityType.Equity;
                var scale    = isEquity ? 1000m : 1m;

                try
                {
                    switch (e.Type)
                    {
                    case LookupType.REQ_HST_TCK:
                        var t    = (LookupTickEventArgs)e;
                        var time = isEquity ? t.DateTimeStamp : t.DateTimeStamp.ConvertTo(TimeZones.NewYork, TimeZones.EasternStandard);
                        return(new Tick(time, requestData.Symbol, (decimal)t.Last * scale, (decimal)t.Bid * scale, (decimal)t.Ask * scale));

                    case LookupType.REQ_HST_INT:
                        var i = (LookupIntervalEventArgs)e;
                        if (i.DateTimeStamp == DateTime.MinValue)
                        {
                            return(null);
                        }
                        var istartTime = i.DateTimeStamp - requestData.Resolution.ToTimeSpan();
                        if (!isEquity)
                        {
                            istartTime = istartTime.ConvertTo(TimeZones.NewYork, TimeZones.EasternStandard);
                        }
                        return(new TradeBar(istartTime, requestData.Symbol, (decimal)i.Open * scale, (decimal)i.High * scale, (decimal)i.Low * scale, (decimal)i.Close * scale, i.PeriodVolume));

                    case LookupType.REQ_HST_DWM:
                        var d = (LookupDayWeekMonthEventArgs)e;
                        if (d.DateTimeStamp == DateTime.MinValue)
                        {
                            return(null);
                        }
                        var dstartTime = d.DateTimeStamp - requestData.Resolution.ToTimeSpan();
                        if (!isEquity)
                        {
                            dstartTime = dstartTime.ConvertTo(TimeZones.NewYork, TimeZones.EasternStandard);
                        }
                        return(new TradeBar(dstartTime, requestData.Symbol, (decimal)d.Open * scale, (decimal)d.High * scale, (decimal)d.Low * scale, (decimal)d.Close * scale, d.PeriodVolume));

                    // we don't need to handle these other types
                    case LookupType.REQ_SYM_SYM:
                    case LookupType.REQ_SYM_SIC:
                    case LookupType.REQ_SYM_NAC:
                    case LookupType.REQ_TAB_MKT:
                    case LookupType.REQ_TAB_SEC:
                    case LookupType.REQ_TAB_MKC:
                    case LookupType.REQ_TAB_SIC:
                    case LookupType.REQ_TAB_NAC:
                    default:
                        return(null);
                    }
                }
                catch (Exception err)
                {
                    Log.Error("Encountered error while processing request: " + e.Id);
                    Log.Error(err);
                    return(null);
                }
            }
コード例 #2
0
            /// <summary>
            /// Method called when a new Lookup event is fired
            /// </summary>
            /// <param name="e">Received data</param>
            protected override void OnLookupEvent(LookupEventArgs e)
            {
                try
                {
                    switch (e.Sequence)
                    {
                    case LookupSequence.MessageStart:
                        _currentRequest.AddOrUpdate(e.Id, new List <BaseData>());
                        break;

                    case LookupSequence.MessageDetail:
                        List <BaseData> current;
                        if (_currentRequest.TryGetValue(e.Id, out current))
                        {
                            HandleMessageDetail(e, current);
                        }
                        break;

                    case LookupSequence.MessageEnd:
                        _inProgress = false;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                catch (Exception err)
                {
                    Log.Error(err);
                }
            }
コード例 #3
0
 protected virtual void OnLookupEvent(LookupEventArgs e)
 {
     if (LookupEvent != null)
     {
         LookupEvent(this, e);
     }
 }
コード例 #4
0
            /// <summary>
            /// Put received data into current list of BaseData object
            /// </summary>
            /// <param name="e">Received data</param>
            /// <param name="current">Current list of BaseData object</param>
            private void HandleMessageDetail(LookupEventArgs e, List <BaseData> current)
            {
                var requestData = _requestDataByRequestId[e.Id];
                var data        = GetData(e, requestData);

                if (data != null && data.Time != DateTime.MinValue)
                {
                    current.Add(data);
                }
            }