Esempio n. 1
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);
                }
            }
        }
Esempio n. 2
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);
            }
        }