예제 #1
0
 private void OnHistoryReady(BarInfo value)
 {
     if (HistoryReady != null)
     {
         HistoryReady(this, value);
     }
 }
예제 #2
0
        private void webSvc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            BarInfo bars = (BarInfo)e.UserState;

            ((WebClient)sender).DownloadStringCompleted -= webSvc_DownloadStringCompleted;
            if (e.Error == null)
            {
                if (e.Result != null)
                {
                    string        requestStr   = e.Result;
                    List <string> responseRows = new List <string>();
                    responseRows.AddRange(requestStr.Split('\n'));

                    int outnum = 0;
                    if (responseRows.Count - 2 > bars.Token.MaxAmount)
                    {
                        outnum = responseRows.Count - bars.Token.MaxAmount - 1;
                    }

                    for (int i = 1; i < responseRows.Count - outnum; i++)
                    {
                        string[] rowElements = responseRows[i].Split(',');

                        if (rowElements.Length >= 7)
                        {
                            System.DateTime tStamp = ParseDate(rowElements[0]);
                            double          open   = double.Parse(rowElements[1]);
                            double          high   = double.Parse(rowElements[2]);
                            double          low    = double.Parse(rowElements[3]);
                            double          close  = double.Parse(rowElements[4]);
                            double          volume = double.Parse(rowElements[5]);
                            //double adjustedClose = double.Parse(rowElements[6]);

                            bars.Add(new Bar
                            {
                                Close     = close,
                                High      = high,
                                Low       = low,
                                Open      = open,
                                TimeStamp = tStamp,
                                Volume    = volume
                            });
                        }
                    }

                    OnHistoryReady(bars);
                }
            }
        }
예제 #3
0
        public void GetHistory(HistoryRequest value)
        {
            easternZone = TimeZoneInfo.FindSystemTimeZoneById(easternZoneId);

            BarInfo token = new BarInfo
            {
                Token = value
            };
            WebClient webSvc = new WebClient();

            webSvc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webSvc_DownloadStringCompleted);
            Uri addressValue = GetHistiryRequestUri(value);

            webSvc.DownloadStringAsync(addressValue, token);
        }
예제 #4
0
        void CSIFeed_GetHistoryComplete(object sender, CSIData.BarInfo value)
        {
            if (started && value != null)
            {
                BarInfo binfo = new BarInfo
                {
                    Token = new HistoryRequest
                    {
                        ID          = value.Token.ID,
                        MaxAmount   = value.Token.MaxAmount,
                        period      = value.Token.period,
                        periodicity = Periodicity.Day,
                        Symbol      = value.Token.Symbol
                    },
                };
                foreach (var itm in value)
                {
                    binfo.Add(new Bar
                    {
                        Close     = itm.Close,
                        High      = itm.High,
                        Low       = itm.Low,
                        Open      = itm.Open,
                        TimeStamp = itm.TimeStamp,
                        Volume    = itm.Volume
                    });
                }

                binfo = DataFeed.BarConverter.ConvertToWeekly(binfo);

                var data = TechnicalCalculations.AroonOscillator(binfo, 16);

                if (data.Count >= 2)
                {
                    if (data[data.Count - 1].Value != data[data.Count - 2].Value)
                    {
                        var    user    = Users[binfo.Token.ID];
                        string content = GetMailContent(user.FirstName + " " + user.LastName, user.DefaultTiker, data[data.Count - 1].Value);
                        var    ret     = EmailSender.SendEmail(user.Email, Config.MailSubject, content, Config);
                        if (ret.InternalError)
                        {
                            LogFile.WriteToLog("Send mail error: " + ret.InternalErrorMessage);
                        }
                        else
                        {
                            LogFile.WriteToLog("Send mail: to " + user.Email + "| subject: " + Config.MailSubject + "| content: " + content);
                        }
                    }
                }
                if (started)
                {
                    string nID       = null;
                    bool   cangetkey = false;
                    foreach (var key in Users.Keys)
                    {
                        if (cangetkey)
                        {
                            nID = key;
                            break;
                        }
                        if (key.Equals(binfo.Token.ID))
                        {
                            cangetkey = true;
                        }
                    }
                    if (nID != null)
                    {
                        ProcessCalcualtions(nID);
                    }
                    else
                    {
                        inprogress = false;
                    }
                }
                else
                {
                    inprogress = false;
                    DisableUI(started);
                }
            }
            else
            {
                inprogress = false;
                DisableUI(started);
            }
        }
        public static List <DataResult> AroonOscillator(BarInfo value, int period)
#endif
        {
#if SILVERLIGHT
            var data = value.Data.OrderBy(t => t.TimeStamp);
#else
            var data = value.OrderBy(t => t.TimeStamp);
#endif
            List <DataResult> ret = new List <DataResult>();

#if SILVERLIGHT
            List <WCFBar> counter = new List <WCFBar>();
#else
            List <Bar> counter = new List <Bar>();
#endif

            int    currentIndex     = 0;
            double Aroon_up         = 0;
            double Aroon_down       = 0;
            double Aroon_oscillator = 0;
            int    nCount           = 0;

            foreach (var itm in data)
            {
                counter.Add(itm);

                if (currentIndex >= period)
                {
                    int    idxMax = -1;
                    int    idxMin = -1;
                    double max    = double.MinValue;
                    double min    = double.MaxValue;

                    int cnt = period;
                    for (int idx = period; idx >= 0; idx--)
                    {
                        if (counter[currentIndex - period + idx].High - double.Epsilon >= max)
                        {
                            max    = counter[currentIndex - period + idx].High;
                            idxMax = currentIndex - period + idx;
                        }

                        if (counter[currentIndex - period + idx].Low + double.Epsilon <= min)
                        {
                            min    = counter[currentIndex - period + idx].Low;
                            idxMin = currentIndex - period + idx;
                        }
                        cnt--;
                    }

                    Aroon_up   = ((double)(period - (currentIndex - idxMax)) / period) * 100;
                    Aroon_down = ((double)(period - (currentIndex - idxMin)) / period) * 100;

                    //System.Diagnostics.Debug.WriteLine(string.Format("{0}. {1} = {2} , {3}", currentIndex, itm.TimeStamp.ToShortDateString(), Aroon_up.ToString("#0.00"), Aroon_down.ToString("#0.00")));

                    Aroon_oscillator = Aroon_up - Aroon_down;
                }
                currentIndex++;

                ret.Add(new DataResult
                {
                    Position  = nCount,
                    TimeStamp = itm.TimeStamp,
                    Value     = Aroon_oscillator
                });
                nCount++;
            }
            return(ret);
        }