예제 #1
0
 public static bool CheckTrackScript(string ScriptID)
 {
     try
     {
         SqlCommand     Cmd = new SqlCommand();
         DataTable      Dt  = new DataTable();
         DataSet        Ds  = new DataSet();
         SqlDataAdapter Da  = new SqlDataAdapter();
         SqlDataReader  dr;
         Cmd.Connection  = Conn;
         Cmd.CommandText = "select Count(*) from TblScriptTracking where ScriptID=" + ScriptID;
         Conn.Open();
         if (Cmd.ExecuteScalar().ToString() == "1")
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         ClsLog.WriteLog("ERROR: " + ex.Message);
         return(false);
     }
     finally
     {
         Conn.Close();
     }
 }
예제 #2
0
 public static DataTable GetSwingScriptData()
 {
     try
     {
         SqlCommand     Cmd = new SqlCommand();
         DataTable      Dt  = new DataTable();
         DataSet        Ds  = new DataSet();
         SqlDataAdapter Da  = new SqlDataAdapter();
         SqlDataReader  dr;
         Cmd.Connection  = Conn;
         Cmd.CommandText = "select RTRIM( B.ScriptName) ScriptName,C.LastClosePrice,A.* from TblSwingScripts" +
                           " A join TblScriptDetails B on A.ScriptID = B.ID Join TblScriptDMA_EMA C on A.ScriptID = C.ScriptID";
         Conn.Open();
         Da.SelectCommand = Cmd;
         Da.Fill(Ds);
         if (Ds.Tables.Count > 0)
         {
             Dt = Ds.Tables[0];
             return(Dt);
         }
         return(null);
     }
     catch (Exception ex)
     {
         ClsLog.WriteLog("ERROR: " + ex.Message);
         return(null);
     }
     finally
     {
         Conn.Close();
     }
 }
예제 #3
0
        void m_oWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            // The background process is complete. We need to inspect
            // our response to see if an error occurred, a cancel was
            // requested or if we completed successfully.
            if (e.Cancelled)
            {
                lblStatus.Text = "Task Cancelled.";
            }

            // Check to see if an error occurred in the background process.

            else if (e.Error != null)
            {
                lblStatus.Text = "Error while performing background operation.";
            }
            else
            {
                // Everything completed normally.
                progressBar1.Value = 0;
                progressBar2.Value = 0;
                labStckStatus.Text = "Download Complete..";
                lblStatus.Text     = "Download Complete..";
                ClsLog.WriteLog("Download Complete.");
                ClsDataBase.UpdateConfigTbl("LastDataDate", Dates[Dates.Count - 1].ToString("yyyy-MM-dd"));
                BtnJson.Enabled    = true;
                BtnGetData.Enabled = true;
                UpdatedData        = true;
            }
            UpdateDashBoard();
            Tm.Enabled             = false;
            LabTotalTime.Visible   = false;
            LabTimeElapsed.Visible = false;
            //Change the status of the buttons on the UI accordingly
        }
예제 #4
0
        public static string  GetLatestDateFromQuandl()
        {
            QuandlDownloadRequest request = new QuandlDownloadRequest();

            request.APIKey    = "Fp8XizZQKq3P1pqcHNxc";
            request.Datacode  = new Datacode("NSE", "ICICIBANK"); // PRAGUESE is the source, PX is the datacode
            request.Format    = FileFormats.JSON;
            request.Frequency = Frequencies.Daily;
            request.StartDate = DateTime.Today.AddDays(-5);
            request.Sort      = SortOrders.Descending;
            //request.Transformation = Transformations.Difference;
            QuandlConnection conn = new QuandlConnection();
            string           json = "";

            try
            {
                json = conn.Request(request); // request is your QuandlDownloadRequst
                RootObject obj = JsonConvert.DeserializeObject <RootObject>(json);
                return(obj.to_date);
            }
            catch (Exception ex)
            {
                ClsLog.WriteLog("ERROR: Not able to Downlaoding data for " + "ICICIBANK" + ". Exception: " + ex.Message);
                //ClsDataBase.MarkScriptInvalid("ICICIBANK");
                return(null);
            }
        }
예제 #5
0
 public static string[] GetSwingScriptById(string ScriptId)
 {
     try
     {
         SqlCommand Cmd = new SqlCommand();
         Cmd.Connection  = Conn;
         Cmd.CommandText = "select concat(UpperLimit,'|',LowerLimit,'|',Comments) from TblSwingScripts where ScriptID='" + ScriptId + "'";
         Conn.Open();
         var Data = Cmd.ExecuteScalar();
         if (Data != null)
         {
             return(Data.ToString().Split('|'));
         }
         else
         {
             return(null);
         }
     }
     catch (Exception ex)
     {
         ClsLog.WriteLog("ERROR: " + ex.Message);
         return(null);
     }
     finally
     {
         Conn.Close();
     }
 }
예제 #6
0
        public static DataTable GetTrackScriptData(String ScriptId, string StartDate)
        {
            try
            {
                SqlCommand     Cmd = new SqlCommand();
                DataTable      Dt  = new DataTable();
                DataSet        Ds  = new DataSet();
                SqlDataAdapter Da  = new SqlDataAdapter();
                SqlDataReader  dr;
                Cmd.Connection = Conn;
                //Cmd.CommandText = "Select B.ScriptName,A.* from TblScriptTracking A Join TblScriptDetails B " +
                // "on A.ScriptID = B.ID";
                Conn.Open();

                Da.SelectCommand = Cmd;
                Da.Fill(Ds);
                if (Ds.Tables.Count > 0)
                {
                    Dt = Ds.Tables[0];
                    return(Dt);
                }
                return(null);
            }
            catch (Exception ex)
            {
                ClsLog.WriteLog("ERROR: " + ex.Message);
                return(null);
            }
            finally
            {
                Conn.Close();
            }
        }
예제 #7
0
 private void BtnGetData_Click(object sender, EventArgs e)
 {
     ChangeOPbarValue = true;
     ChangeSPbarValue = false;
     OneDayData       = true;
     ClsLog.WriteLog("Initiating Daily Stock Data Download.. ");
     BtnGetData.Enabled = false;
     m_oWorker.RunWorkerAsync();
     Tm.Enabled             = true;
     LabUpdateEOD.ForeColor = Color.Green;
     LabUpdateEOD.Text      = "Please Wait...Data is being download.";
     label1.ForeColor       = Color.Green;
     LabTotalTime.Visible   = true;
     LabTimeElapsed.Visible = true;
     // ClsDataBase.InsertScriptCode();
 }
예제 #8
0
        public void m_oWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            // This function fires on the UI thread so it's safe to edit

            // the UI control directly, no funny business with Control.Invoke :)

            // Update the progressBar with the integer supplied to us from the

            // ReportProgress() function.
            try
            {
                if (e.ProgressPercentage == 0)
                {
                    if (ChangeOPbarValue)
                    {
                        progressBar1.Maximum = OverallPbarMax;
                    }
                    if (ChangeSPbarValue)
                    {
                        ChangeSPbarValue     = false;
                        progressBar2.Maximum = ScriptPbarMax;
                    }
                    progressBar1.Value = OverallProgress;
                    progressBar2.Value = ScriptProgress;
                    lblStatus.Text     = "Downloading Data for NSE scripts......" + ScriptOStatus;
                    labStckStatus.Text = "Downloading Data for " + ScriptSStatus;
                }
                else if (e.ProgressPercentage == 1)
                {
                    progressBar1.Value = 0;
                    progressBar2.Value = 0;
                    lblStatus.Text     = "Data Download Complete. Running EMA DMA Update SP. Please wait..";
                    labStckStatus.Text = "Please wait..";
                }
                else if (e.ProgressPercentage == 2)
                {
                    progressBar1.Value = 0;
                    LabDates.Text      = DataDate;
                }
            }
            catch (Exception ex)
            {
                ClsLog.WriteLog("ERROR: " + ex.Message);
            }
        }
예제 #9
0
 public ClsDashBoard()
 {
     InitializeComponent();
     m_oWorker             = new BackgroundWorker();
     m_oWorker_LiveRefresh = new BackgroundWorker();
     // Create a background worker thread that ReportsProgress &
     // SupportsCancellation
     // Hook up the appropriate events.
     m_oWorker.DoWork          += new DoWorkEventHandler(m_oWorker_DoWork);
     m_oWorker.ProgressChanged += new ProgressChangedEventHandler
                                      (m_oWorker_ProgressChanged);
     m_oWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler
                                         (m_oWorker_RunWorkerCompleted);
     m_oWorker.WorkerReportsProgress      = true;
     m_oWorker.WorkerSupportsCancellation = true;
     //Live data refresh Backround Worker block
     m_oWorker_LiveRefresh.DoWork                    += M_oWorker_LiveRefresh_DoWork;
     m_oWorker_LiveRefresh.ProgressChanged           += M_oWorker_LiveRefresh_ProgressChanged;
     m_oWorker_LiveRefresh.RunWorkerCompleted        += M_oWorker_LiveRefresh_RunWorkerCompleted;
     m_oWorker_LiveRefresh.WorkerReportsProgress      = true;
     m_oWorker_LiveRefresh.WorkerSupportsCancellation = true;
     DgvAllDma.AutoGenerateColumns                    = false;
     DgvAllEma.AutoGenerateColumns                    = false;
     DgvDCross.AutoGenerateColumns                    = false;
     DgvGCross.AutoGenerateColumns                    = false;
     Dgv50_200.AutoGenerateColumns                    = false;
     DgvLiveData.AutoGenerateColumns                  = false;
     DgvSwing.AutoGenerateColumns                     = false;
     UpdatedData = false;
     CB50DMA.Items.Add("50");
     CB50DMA.Items.Add("200");
     CB50DMA.Items.Add("50+200");
     CB50DMA.SelectedIndex = 0;
     CmbRefreshTime.Items.Add(".5");
     CmbRefreshTime.Items.Add("1");
     CmbRefreshTime.Items.Add("3");
     CmbRefreshTime.Items.Add("5");
     CmbRefreshTime.SelectedIndex = 1;
     ClsLog.WriteLog("**********************************App Start*************************** Date: " + DateTime.Today.ToLongDateString());
     Tm.Tick                += Tm_Tick;
     Tm.Interval             = 1000;
     Tm_RefreshLive.Tick    += Tm_RefreshLive_Tick;
     Tm_RefreshLive.Interval = 1000 * 60;
 }
예제 #10
0
        private void CopyDataGridView(DataGridView dgv_org)
        {
            try
            {
                if (DgvDetails.Columns.Count == 0)
                {
                    foreach (DataGridViewColumn dgvc in dgv_org.Columns)
                    {
                        DgvDetails.Columns.Add(dgvc.Clone() as DataGridViewColumn);
                    }
                }
                DataGridViewButtonColumn NewCol = new DataGridViewButtonColumn();

                DgvDetails.Columns.Add(NewCol);
                NewCol.Text       = "Add to Track list";
                NewCol.Name       = "BtnColAdd";
                NewCol.HeaderText = "Add To List";
                NewCol.Width      = 150;
                NewCol.UseColumnTextForButtonValue = true;
                DataGridViewRow row = new DataGridViewRow();

                for (int i = 0; i < dgv_org.Rows.Count; i++)
                {
                    row = (DataGridViewRow)dgv_org.Rows[i].Clone();
                    int intColIndex = 0;
                    foreach (DataGridViewCell cell in dgv_org.Rows[i].Cells)
                    {
                        row.Cells[intColIndex].Value = cell.Value;
                        intColIndex++;
                    }
                    DgvDetails.Rows.Add(row);
                    if (ClsDataBase.CheckTrackScript(row.Cells[StrScriptIdCol].Value.ToString()))
                    {
                        row.DefaultCellStyle.BackColor = Color.Green;
                    }
                }
                DgvDetails.AllowUserToAddRows = false;
                DgvDetails.Refresh();
            }
            catch (Exception ex)
            {
                ClsLog.WriteLog("Copy DataGridViw" + ex.Message);
            }
        }
예제 #11
0
 public static void MarkScriptInvalid(string ScriptCode)
 {
     try
     {
         SqlCommand Cmd = new SqlCommand();
         Cmd.Connection  = Conn;
         Cmd.CommandText = "Update TblScriptDetails set Active=0 where ScriptCode='" + ScriptCode + "'";
         Conn.Open();
         Cmd.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         ClsLog.WriteLog(ex.Message);
     }
     finally
     {
         Conn.Close();
     }
 }
예제 #12
0
 public static string GetConfigValue(string ConfigName)
 {
     try
     {
         SqlCommand Cmd = new SqlCommand();
         Cmd.Connection  = Conn;
         Cmd.CommandText = "Select ConfigValue from tblConfig where ConfigName='" + ConfigName + "'";
         Conn.Open();
         return(Cmd.ExecuteScalar().ToString());
     }
     catch (Exception ex)
     {
         ClsLog.WriteLog(ex.Message);
         return("False");
     }
     finally
     {
         Conn.Close();
     }
 }
예제 #13
0
        public static string[] GetScriptForLiveData()
        {
            int i = 0;
            int j = 0;

            string[] UriList = new string[4];
            try
            {
                Collection <ClsScriptsMaster> ScriptCodes = ClsDataBase.GetScriptsCode(true);
                System.Text.StringBuilder     StrScpt     = new System.Text.StringBuilder();
                StrScpt.Append("https://www.google.com/finance/info?q=");
                foreach (var Script in ScriptCodes)
                {
                    StrScpt.Append("NSE:" + Script.ScriptsCode + ",");
                    i++;
                    if (i == 100)
                    {
                        StrScpt.Remove(StrScpt.Length - 1, 1);
                        StrScpt.Replace("&", "%26");
                        UriList[j] = StrScpt.ToString();
                        StrScpt.Clear();
                        StrScpt.Append("https://www.google.com/finance/info?q=");
                        j++;
                        i = 0;
                    }
                }
                if (i != 0)
                {
                    StrScpt.Remove(StrScpt.Length - 1, 1);
                    StrScpt.Replace("&", "%26");
                    UriList[j] = StrScpt.ToString();
                }

                return(UriList);
            }
            catch (Exception ex)
            {
                ClsLog.WriteLog("ERROR:GetScriptForLiveData " + ex.Message);
                return(null);
            }
        }
예제 #14
0
        public static DataTable GetSwingThit(bool BuyCall)
        {
            try
            {
                SqlCommand     Cmd = new SqlCommand();
                DataTable      Dt  = new DataTable();
                DataSet        Ds  = new DataSet();
                SqlDataAdapter Da  = new SqlDataAdapter();
                SqlDataReader  dr;
                Cmd.Connection = Conn;
                if (BuyCall)
                {
                    Cmd.CommandText = "select C.ScriptName,D.LastClosePrice  from (select B.ScriptName,A.ScriptID from TblSwingScripts A join TblScriptDetails B on A.ScriptID=B.ID where A.TargetHit=1)C" +
                                      " Join TblScriptDMA_EMA D on C.ScriptID = D.ScriptID";
                }
                else
                {
                    Cmd.CommandText = "select C.ScriptName,D.LastClosePrice  from (select B.ScriptName,A.ScriptID from TblSwingScripts A join TblScriptDetails B on A.ScriptID=B.ID where A.TargetHit=2)C" +
                                      " Join TblScriptDMA_EMA D on C.ScriptID = D.ScriptID";
                }
                Conn.Open();

                Da.SelectCommand = Cmd;
                Da.Fill(Ds);
                if (Ds.Tables.Count > 0)
                {
                    Dt = Ds.Tables[0];
                    return(Dt);
                }
                return(null);
            }
            catch (Exception ex)
            {
                ClsLog.WriteLog("ERROR: " + ex.Message);
                return(null);
            }
            finally
            {
                Conn.Close();
            }
        }
예제 #15
0
 public static bool UpdateConfigTbl(string ConfigName, string ConfigValue)
 {
     try
     {
         SqlCommand Cmd = new SqlCommand();
         Cmd.Connection  = Conn;
         Cmd.CommandText = "Update tblConfig set COnfigValue='" + ConfigValue + "' where ConfigName='" + ConfigName + "'";
         Conn.Open();
         Cmd.ExecuteNonQuery();
         return(true);
     }
     catch (Exception ex)
     {
         ClsLog.WriteLog(ex.Message);
         return(false);
     }
     finally
     {
         Conn.Close();
     }
 }
예제 #16
0
        public static bool UpdateEmaDma()
        {
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "SP_UpdateEMA_DMA";
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Connection = Conn;
                Conn.Open();
                cmd.CommandTimeout = 0;
                cmd.ExecuteNonQuery();
                return(true);
            }
            catch (Exception ex)
            {
                ClsLog.WriteLog("ERROR: Module UpdateEmaDma : " + ex.Message);
                return(false);
            }
            finally
            {
                Conn.Close();
            }
        }
예제 #17
0
 public static DataTable GetBreakOutData(int Mode)
 {
     try
     {
         SqlCommand     Cmd = new SqlCommand();
         DataTable      Dt  = new DataTable();
         DataSet        Ds  = new DataSet();
         SqlDataAdapter Da  = new SqlDataAdapter();
         SqlDataReader  dr;
         Cmd.Connection  = Conn;
         Cmd.CommandText = "PR_Get_DMA_P_Breakout_Scripts";
         Cmd.CommandType = CommandType.StoredProcedure;
         SqlParameter param = new SqlParameter("@Mode", Mode);
         param.Direction = ParameterDirection.Input;
         param.DbType    = DbType.Int32;
         Cmd.Parameters.Add(param);
         Conn.Open();
         Da.SelectCommand = Cmd;
         Da.Fill(Ds);
         if (Ds.Tables.Count > 0)
         {
             Dt = Ds.Tables[0];
             return(Dt);
         }
         return(null);
     }
     catch (Exception ex)
     {
         ClsLog.WriteLog("ERROR: " + ex.Message);
         return(null);
     }
     finally
     {
         Conn.Close();
     }
 }
예제 #18
0
 public static string GetSriptLastClosePrice(string ScriptCode)
 {
     try
     {
         SqlCommand Cmd = new SqlCommand();
         Cmd.Connection  = Conn;
         Cmd.CommandText = "select concat(Rtrim(TableName),'|',ID) from TblScriptDetails where ScriptCode='" + ScriptCode + "'";
         Conn.Open();
         var TableName = Cmd.ExecuteScalar().ToString().Split('|');
         Conn.Close();
         Cmd.CommandText = "select top 1 ClosePrice from " + TableName[0] + " where ScriptId=" + TableName[1] + " order by TradeDate desc";
         Conn.Open();
         return(Cmd.ExecuteScalar().ToString());
     }
     catch (Exception ex)
     {
         ClsLog.WriteLog("ERROR: " + ex.Message);
         return(null);
     }
     finally
     {
         Conn.Close();
     }
 }
예제 #19
0
 public static void DownloadEodDataNSEBhav(ref BackgroundWorker BGW, List <DateTime> Dates)
 {
     try
     {
         Collection <ClsScriptsMaster> ScriptCodes = ClsDataBase.GetScriptsCode(false);
         Collection <ClsPriceDataSet>  ColEodData  = new Collection <ClsPriceDataSet>();
         ArrayList TempData        = new ArrayList();
         string    BhavFileName    = null;
         string    BhavFilePath    = null;
         string    NseZipFile      = null;
         string    BhavCsvFileName = null;
         DateTime  Tradedate       = DateTime.Today;
         DataSet   ds;
         DataRow[] Dr;
         int       i = 0;
         ClsDashBoard.OverallPbarMax = ScriptCodes.Count;
         WebClient WC;
         foreach (DateTime item in Dates)
         {
             ClsLog.WriteLog("Dowloading NSE Bhav file..");
             ClsDashBoard.ScriptOStatus = "Dowloading NSE Bhav file for the date";
             BGW.ReportProgress(0);
             ClsDashBoard.DataDate = item.ToString("dd-MM-yyyy");
             BGW.ReportProgress(2);
             i               = 0;
             BhavFileName    = "cm" + item.ToString("dd") + item.ToString("MMM").ToUpper() + item.Year.ToString() + "bhav.csv.zip";
             BhavCsvFileName = "cm" + item.ToString("dd") + item.ToString("MMM").ToUpper() + item.Year.ToString() + "bhav.csv";
             BhavFilePath    = "https://www.nseindia.com/content/historical/EQUITIES/" + item.Year.ToString() + "/" + item.ToString("MMM").ToUpper() + "/";
             BhavFilePath    = BhavFilePath + BhavFileName;
             NseZipFile      = "AllNSEData_" + item.ToString("ddMMMyyyy") + ".zip";
             WC              = new WebClient();
             if (File.Exists(BhavFilePath))
             {
                 File.Delete(BhavFilePath);
             }
             WC.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
             WC.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.83 Safari/537.1");
             WC.DownloadFile(BhavFilePath, NseZipFile);
             ZipFile.ExtractToDirectory(Application.StartupPath + "\\" + NseZipFile, Application.UserAppDataPath);
             var connString = string.Format(@"Provider=Microsoft.Jet.OleDb.4.0; Data Source={0};Extended Properties=""Text;HDR=YES;FMT=Delimited""",
                                            Application.UserAppDataPath);
             using (var conn = new OleDbConnection(connString))
             {
                 conn.Open();
                 var query = "SELECT * FROM [" + BhavCsvFileName + "]";
                 using (var adapter = new OleDbDataAdapter(query, conn))
                 {
                     ds = new DataSet("CSV File");
                     adapter.Fill(ds);
                 }
             }
             foreach (var Scode in ScriptCodes)
             {
                 ClsLog.WriteLog("Starting Data Download for script: " + Scode.ScriptsName + "(" + Scode.ScriptsCode + ")");
                 ClsDashBoard.ScriptOStatus = "Total Scripts: " + ScriptCodes.Count.ToString() + " Downloading " +
                                              i.ToString() + " Of " + ScriptCodes.Count.ToString() +
                                              " Script Name: " + Scode.ScriptsCode;
                 ClsDashBoard.OverallProgress = i;
                 i = i + 1;
                 BGW.ReportProgress(0);
                 Dr = ds.Tables[0].Select("SYMBOL='" + Scode.ScriptsCode + "' and SERIES='" + Scode.Series + "'");
                 if (Dr.Length != 0)
                 {
                     Tradedate = Convert.ToDateTime(Dr[0]["TIMESTAMP"]);
                     ColEodData.Add(new ClsPriceDataSet()
                     {
                         ScriptId   = Scode.ScriptId,
                         Date       = Convert.ToDateTime(Dr[0]["TIMESTAMP"]),
                         OpenPrice  = Dr[0]["OPEN"] != null ? Convert.ToDouble(Dr[0]["OPEN"].ToString()) : 0.0,
                         HighPrice  = Dr[0]["HIGH"] != null ? Convert.ToDouble(Dr[0]["HIGH"].ToString()) : 0.0,
                         LowPrice   = Dr[0]["LOW"] != null ? Convert.ToDouble(Dr[0]["LOW"].ToString()) : 0.0,
                         LastPrice  = Dr[0]["LAST"] != null ? Convert.ToDouble(Dr[0]["LAST"].ToString()) : 0.0,
                         ClosePrice = Dr[0]["CLOSE"] != null ? Convert.ToDouble(Dr[0]["CLOSE"].ToString()) : 0.0,
                         TotalVal   = Dr[0]["TOTTRDQTY"] != null ? Convert.ToDouble(Dr[0]["TOTTRDQTY"].ToString()) : 0.0,
                         TurnOver   = Dr[0]["TOTTRDVAL"] != null ? Convert.ToDouble(Dr[0]["TOTTRDVAL"].ToString()) : 0.0
                     });
                 }
                 else
                 {
                     ColEodData.Add(new ClsPriceDataSet()
                     {
                         ScriptId   = Scode.ScriptId,
                         Date       = Tradedate,
                         OpenPrice  = 0.0,
                         HighPrice  = 0.0,
                         LowPrice   = 0.0,
                         LastPrice  = 0.0,
                         ClosePrice = 0.0,
                         TotalVal   = 0.0,
                         TurnOver   = 0.0
                     });
                 }
                 ClsDataBase.UpdateEodData(ColEodData, Scode.TableName);
                 ClsLog.WriteLog("Data Download for script: " + Scode.ScriptsName + "(" + Scode.ScriptsCode + ") Completed.");
                 ColEodData.Clear();
             }
             File.Move(Application.UserAppDataPath + @"\" + BhavCsvFileName, @"E:\TradeAppBackup\" + BhavCsvFileName);
         }
         ClsLog.WriteLog("Running EMA DMA SP...");
         ClsDashBoard.ScriptOStatus = "Data Download Complete. Running EMA DMA Update SP.";
         ClsDashBoard.ScriptSStatus = "Data Download Complete. Running EMA DMA Update SP.";
         BGW.ReportProgress(0);
         ClsDataBase.UpdateEmaDma();
         ClsLog.WriteLog("Running EMA DMA SP...Completed");
     }
     catch (Exception ex)
     {
         ClsLog.WriteLog(ex.Message);
     }
 }
예제 #20
0
        public static void DownlaodBulkEodData(ref BackgroundWorker BGW, List <DateTime> Dates)
        {
            try
            {
                Collection <ClsScriptsMaster> ScriptCodes = ClsDataBase.GetScriptsCode(false);
                Collection <ClsPriceDataSet>  ColEodData  = new Collection <ClsPriceDataSet>();
                ArrayList    TempData     = new ArrayList();
                string       json         = "";
                ClsDashBoard ObjDashBoard = new ClsDashBoard();
                ClsDashBoard.OverallPbarMax = ScriptCodes.Count;
                //ClsDashBoard.ChangeOPbarValue = false;
                //ClsDashBoard.OverallPbarMax = ScriptCodes.Count;
                int i = 1; int j = 1;
                foreach (var Scode in ScriptCodes)
                {
                    ClsLog.WriteLog("Starting Data Download for script: " + Scode.ScriptsName + "(" + Scode.ScriptsCode + ")");

                    QuandlDownloadRequest request = new QuandlDownloadRequest();
                    request.APIKey    = "Fp8XizZQKq3P1pqcHNxc";
                    request.Datacode  = new Datacode("NSE", Scode.ScriptsCode); // PRAGUESE is the source, PX is the datacode
                    request.Format    = FileFormats.JSON;
                    request.Frequency = Frequencies.Daily;
                    request.StartDate = Dates[0];
                    if (Dates.Count > 1)
                    {
                        request.EndDate = Dates[Dates.Count - 1];
                    }
                    //request.Truncation = 150;
                    request.Sort = SortOrders.Descending;
                    //request.Transformation = Transformations.Difference;
                    QuandlConnection conn = new QuandlConnection();
                    try
                    {
                        json = conn.Request(request); // request is your QuandlDownloadRequst
                    }
                    catch (Exception ex)
                    {
                        ClsLog.WriteLog("ERROR: Not able to Downlaoding data for " + Scode.ScriptsCode + ". Exception: " + ex.Message);
                        ClsDataBase.MarkScriptInvalid(Scode.ScriptsCode);
                        continue;
                    }

                    RootObject obj = JsonConvert.DeserializeObject <RootObject>(json);
                    ClsDashBoard.ScriptOStatus    = "Total Scripts: " + ScriptCodes.Count.ToString() + " Downloading " + i.ToString() + " Of " + ScriptCodes.Count.ToString();
                    ClsDashBoard.OverallProgress  = i;
                    ClsDashBoard.ScriptPbarMax    = 0;
                    ClsDashBoard.ChangeSPbarValue = true;
                    BGW.ReportProgress(0);
                    ClsDashBoard.ScriptSStatus = Scode.ScriptsCode + " Total Records:" + obj.data.Count.ToString();
                    ClsLog.WriteLog(Scode.ScriptsCode + " Total Records:" + obj.data.Count.ToString());
                    ClsDashBoard.ScriptPbarMax    = obj.data.Count;
                    ClsDashBoard.ChangeSPbarValue = true;
                    BGW.ReportProgress(0);
                    i = i + 1;
                    j = 0;

                    //ClsDashBoard.ScriptPbarMax = obj.data.Count;
                    if (obj.data.Count != 0)
                    {
                        foreach (var item in obj.data)
                        {
                            ColEodData.Add(new ClsPriceDataSet()
                            {
                                ScriptId   = Scode.ScriptId,
                                Date       = Convert.ToDateTime(item[0].ToString()),
                                OpenPrice  = item[1] != null ? Convert.ToDouble(item[1].ToString()) : 0.0,
                                HighPrice  = item[2] != null ? Convert.ToDouble(item[2].ToString()) : 0.0,
                                LowPrice   = item[3] != null ? Convert.ToDouble(item[3].ToString()) : 0.0,
                                LastPrice  = item[4] != null ? Convert.ToDouble(item[4].ToString()) : 0.0,
                                ClosePrice = item[5] != null ? Convert.ToDouble(item[5].ToString()) : 0.0,
                                TotalVal   = item[6] != null ? Convert.ToDouble(item[6].ToString()) : 0.0,
                                TurnOver   = item[7] != null ? Convert.ToDouble(item[7].ToString()) : 0.0
                            });
                            ClsDashBoard.ScriptProgress = j;
                            BGW.ReportProgress(0);
                            j = j + 1;
                        }
                    }
                    else
                    {
                        ColEodData.Add(new ClsPriceDataSet()
                        {
                            ScriptId   = Scode.ScriptId,
                            Date       = request.StartDate,
                            OpenPrice  = 0.0,
                            HighPrice  = 0.0,
                            LowPrice   = 0.0,
                            LastPrice  = 0.0,
                            ClosePrice = 0.0,
                            TotalVal   = 0.0,
                            TurnOver   = 0.0
                        });
                        ClsDashBoard.ScriptProgress = j;
                        BGW.ReportProgress(0);
                        j = j + 1;
                    }
                    ClsDataBase.UpdateEodData(ColEodData, Scode.TableName);
                    ColEodData.Clear();
                    ClsLog.WriteLog("Data Download for script: " + Scode.ScriptsName + "(" + Scode.ScriptsCode + ") Completed.");
                }
                ClsLog.WriteLog("Running EMA DMA SP...");
                ClsDashBoard.ScriptOStatus = "Data Download Complete. Running EMA DMA Update SP.";
                ClsDashBoard.ScriptSStatus = "Data Download Complete. Running EMA DMA Update SP.";
                BGW.ReportProgress(0);
                ClsDataBase.UpdateEmaDma();
                ClsLog.WriteLog("Running EMA DMA SP...Completed");
            }
            catch (Exception ex)
            {
                ClsLog.WriteLog(ex.Message);
            }
        }
예제 #21
0
        private void UpdateDashBoard()
        {
            DataTable dt;
            int       i = 0;

            try
            {
                Dates = ClsDataBase.GetDatesForDataDownload(ClsDataBase.GetConfigValue("LastDataDate"), null);
            }
            catch (Exception ex)
            {
                ClsLog.WriteLog("ERROR: Load Function, DashBoard module: " + ex.Message);
            }
            if (Dates.Count == 0)
            {
                UpdatedData        = true;
                label1.ForeColor   = Color.Green;
                label1.Text        = "Data is up to date!!";
                LabDates.Visible   = false;
                BtnGetData.Enabled = false;
                BtnJson.Enabled    = false;
                groupBox3.Enabled  = true;
                groupBox4.Enabled  = true;
                groupBox5.Enabled  = true;
                groupBox6.Enabled  = true;
                groupBox8.Enabled  = true;
                Grv.Enabled        = true;
            }
            else
            {
                UpdatedData        = false;
                label1.ForeColor   = Color.Red;
                label1.Text        = "Data to be downloaded for the dates(" + Dates.Count.ToString() + ") :";
                BtnGetData.Enabled = true;
                BtnJson.Enabled    = true;
                groupBox3.Enabled  = false;
                groupBox4.Enabled  = false;
                groupBox5.Enabled  = false;
                groupBox6.Enabled  = false;
                groupBox8.Enabled  = false;
                Grv.Enabled        = false;
            }

            foreach (var Date in Dates)
            {
                if (i <= 3)
                {
                    LabDates.Text = LabDates.Text + Date.Date.Day.ToString() + "-" + Date.Date.Month.ToString() + ", ";
                    i++;
                }
                else

                {
                    LabDates.Text = LabDates.Text.Remove(LabDates.Text.Length - 2);
                    LabDates.Text = LabDates.Text + " + " + (Dates.Count - i).ToString() + " More";
                    break;
                }
            }
            if (UpdatedData)
            {
                dt = ClsDataBase.GetBreakOutData(1);
                if (dt != null)
                {
                    DgvAllDma.DataSource = dt;
                }
                PanUpdateEOD.Visible = false;
                dt = ClsDataBase.GetBreakOutData(2);
                if (dt != null)
                {
                    Dgv50_200.DataSource = dt;
                }
                dt = ClsDataBase.GetBreakOutData(5);
                if (dt != null)
                {
                    DgvGCross.DataSource = dt;
                }
                dt = ClsDataBase.GetSwingScriptData();
                if (dt != null)
                {
                    DgvSwing.DataSource = dt;
                }
                dt = ClsDataBase.GetSwingThit(true);
                foreach (DataRow item in dt.Rows)
                {
                    RTxtSwing.AppendText("It's Time to BUY:" + item[0].ToString() + " CP:" + item[1].ToString());
                    RTxtSwing.AppendText(Environment.NewLine);
                }
                RTxtSwing.Select(0, RTxtSwing.Text.Length);
                RTxtSwing.SelectionColor = Color.Green;
                dt = ClsDataBase.GetSwingThit(false);
                var txtLenth = RTxtSwing.Text.Length;
                foreach (DataRow item in dt.Rows)
                {
                    RTxtSwing.AppendText("It's Time to SELL:" + item[0].ToString() + " CP:" + item[1].ToString());
                    RTxtSwing.AppendText(Environment.NewLine);
                }
                RTxtSwing.Select(txtLenth, RTxtSwing.Text.Length - txtLenth);
                RTxtSwing.SelectionColor = Color.Red;
            }
            else
            {
                PanUpdateEOD.Visible = true;
            }
            LabDataDetails.Text = "Latest Data Date: " + ClsDataBase.GetConfigValue("LastDataDate");
        }