Exemplo n.º 1
0
        public List<StockData> DownloadHistoricalData(string ticker)
        {
            List<StockData> retval = new List<StockData>();

            Type tFloat = typeof(float);
            Type tLong = typeof(long);
            Type tString = typeof(string);
            Type tDateTime = typeof(DateTime);

            StockData hData;
            string addr;
            string results;
            JObject dataobject;
            JValue count;
            JArray jsonArray;
            DateTime auxDate = startDate;

            while (auxDate.Year <= DateTime.Now.Year) {
                addr = DOWNLOAD_HISTORICAL_DATA_1 + ticker + DOWNLOAD_HISTORICAL_DATA_2 + auxDate.ToString("yyyy-MM-dd") + DOWNLOAD_HISTORICAL_DATA_3 + auxDate.AddYears(1).ToString("yyyy-MM-dd") + DOWNLOAD_HISTORICAL_DATA_4;
                auxDate = auxDate.AddYears(1);
                results = GetData(addr);

                dataobject = JObject.Parse(results);
                count = (JValue)dataobject["query"]["count"];
                if (Int32.Parse(count.Value.ToString()) > 0)
                {
                    jsonArray = (JArray)dataobject["query"]["results"]["quote"];

                    foreach (var historicData in jsonArray)
                    {
                        hData = new StockData();
                        hData.StockName = ticker.ToString().Trim('\'');
                        hData.Date = DateTime.Parse(historicData["Date"].ToString());
                        hData.Open = (float)JsonConvert.DeserializeObject(historicData["Open"].ToString(), tFloat);
                        hData.High = (float)JsonConvert.DeserializeObject(historicData["High"].ToString(), tFloat);
                        hData.Low = (float)JsonConvert.DeserializeObject(historicData["Low"].ToString(), tFloat);
                        hData.Close = (float)JsonConvert.DeserializeObject(historicData["Close"].ToString(), tFloat);
                        hData.Volume = (long)JsonConvert.DeserializeObject(historicData["Volume"].ToString(), tLong);
                        try
                        {
                            hData.AdjClose = (float)JsonConvert.DeserializeObject(historicData["AdjClose"].ToString(), tFloat);
                        }
                        catch (NullReferenceException ex)
                        {
                            hData.AdjClose = null;
                        }

                        retval.Add(hData);
                    }
                }
                else
                {
                    //throw new Exception("No information available in the selected Dates");
                }
            }
            return retval;
        }
Exemplo n.º 2
0
        public void sqlConnectionViaApp()
        {
            StockData sD = new StockData();
            SQLExpressDDBB sqlEDDBB = new SQLExpressDDBB();

            sD.StockName = "Test";
            sD.Date = System.DateTime.Now;
            sD.Open = 0;
            sD.Close= 0;
            sD.High= 0;
            sD.Low= 0;
            sD.Volume= 0;
            sD.AdjClose = 0;
            for (int i = 0; i<1000; i++) sqlEDDBB.InsertData(sD);
        }
Exemplo n.º 3
0
        public bool InsertData(StockData sData)
        {
            bool rValue = true;
            string cText;

            SqlConnection cnn;
            cnn = new SqlConnection(connectionString);

            System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(connectionString);
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
            cmd.CommandType = System.Data.CommandType.Text;
            cText = "INSERT INTO [dbo].[HistoricalStockValuesTable]"
                                  + "(StockName"
                                  + ",Date"
                                  + ",OpenValue"
                                  + ",CloseValue"
                                  + ",HighValue"
                                  + ",LowValue"
                                  + ",Volume"
                                  + ",Adj_Close)"
                            + "VALUES"
                                  + "('" + sData.StockName + "'"
                                  + ",'" + String.Format("{0:yyyy-MM-dd}", sData.Date) + "'"
                                  + ",'" + sData.Open.ToString().Replace(",",".") + "'"
                                  + ",'" + sData.Close.ToString().Replace(",", ".") + "'"
                                  + ",'" + sData.High.ToString().Replace(",", ".") + "'"
                                  + ",'" + sData.Low.ToString().Replace(",", ".") + "'"
                                  + ",'" + sData.Volume + "'";
            if (sData.AdjClose != null) cText = cText + ",'" + sData.AdjClose.ToString().Replace(",", ".") + "')";
            else cText = cText + ",'')";

            cmd.CommandText = cText;
            cmd.Connection = sqlConnection;

            try
            {
                sqlConnection.Open();
                cmd.ExecuteNonQuery();
                sqlConnection.Close();
            }
            catch (Exception ex)
            {
                rValue = false;
            }

            return rValue;
        }
Exemplo n.º 4
0
 public void AddItem(StockData stockData)
 {
     _view.AddItemToGrid(GetLVIFromSD(stockData));
 }
Exemplo n.º 5
0
        private ListViewItem GetLVIFromSD(StockData sD)
        {
            ListViewItem lvItem;

            lvItem = new ListViewItem(sD.StockName);
            lvItem.SubItems.Add(sD.Date.ToString());
            lvItem.SubItems.Add(sD.Open.ToString());
            lvItem.SubItems.Add(sD.High.ToString());
            lvItem.SubItems.Add(sD.Low.ToString());
            lvItem.SubItems.Add(sD.Close.ToString());
            lvItem.SubItems.Add(sD.Volume.ToString());
            lvItem.SubItems.Add(sD.AdjClose.ToString());

            return lvItem;
        }
Exemplo n.º 6
0
 public int GetId(StockData sData)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 7
0
 public bool UpdateData(int Id, StockData sData)
 {
     throw new NotImplementedException();
 }