Beispiel #1
0
        private void axYQ_OnGetMktAll(object sender, _DYuantaQuoteEvents_OnGetMktAllEvent e)
        {
            // 獲取所有行情資料
            DataRow DR = this.dtable.Rows.Find(e.symbol);
            string matchtime = e.matchTime != "" ? (string.Format("{0}:{1}:{2}.{3}", e.matchTime.Substring(0, 2), e.matchTime.Substring(2, 2), e.matchTime.Substring(4, 2), e.matchTime.Substring(6, 3))) : "";

            //Console.WriteLine(e.matchTime);
            if (DR != null)
            {
                DR["參考價"] = e.refPri;
                DR["開盤價"] = e.openPri;
                DR["最高價"] = e.highPri;
                DR["最低價"] = e.lowPri;
                DR["漲停價"] = e.upPri;
                DR["跌停價"] = e.dnPri;
                DR["成交時間"] = e.matchTime != "" ? matchtime : "";
                DR["成交價位"] = e.matchPri;
                DR["成交數量"] = e.matchQty;
                DR["總成交量"] = e.tolMatchQty;
                DR["買五"] = e.bestBuyPri + e.bestBuyQty;
                DR["賣五"] = e.bestSellPri + e.bestSellQty;

                DR.EndEdit();
                DR.AcceptChanges();

            }
            else
            {
                DR = this.dtable.NewRow();
                DR["商品代碼"] = e.symbol;
                DR["參考價"] = e.refPri;
                DR["開盤價"] = e.openPri;
                DR["最高價"] = e.highPri;
                DR["最低價"] = e.lowPri;
                DR["漲停價"] = e.upPri;
                DR["跌停價"] = e.dnPri;
                DR["成交時間"] = e.matchTime != "" ? matchtime : ""; DR["成交價位"] = e.matchPri;
                DR["成交數量"] = e.matchQty;
                DR["總成交量"] = e.tolMatchQty;
                DR["買五"] = e.bestBuyPri + e.bestBuyQty;
                DR["賣五"] = e.bestSellPri + e.bestSellQty;
                this.dtable.Rows.Add(DR);
            }

            // 更新資料
            if (!CheckData(e))
            {
                UpdateData(e);
                _times++;
                lbRuntimes.Text = "Runtimes: " + _times;
            }

            ListShow(String.Format("{0} 買五:{1}-{2}", e.symbol, e.bestBuyPri, e.bestBuyQty));
            ListShow(String.Format("{0} 賣五:{1}-{2}", e.symbol, e.bestSellPri, e.bestSellQty));
        }
Beispiel #2
0
        public void UpdateData(_DYuantaQuoteEvents_OnGetMktAllEvent e)
        {
            if (e != null)
            {
                string sql = "INSERT into Data (symbol, refPri, openPri, highPri, lowPri, upPri, dnPri, matchTime, matchPri, matchQty, tolMatchQty, bestBuyPri, bestBuyQty, bestSellPri, bestSellQty, currentTime) " +
                    "VALUES (@symbol, @refPri, @openPri, @highPri, @lowPri, @upPri, @dnPri, @matchTime, @matchPri, @matchQty, @tolMatchQty, @bestBuyPri, @bestBuyQty, @bestSellPri, @bestSellQty, @currentTime)";
                SqlConnection conn = new SqlConnection(db.ini);
                SqlCommand cmd = new SqlCommand(sql);
                cmd.Connection = conn;

                cmd.Parameters.Add("@symbol", SqlDbType.NVarChar).Value = e.symbol;
                cmd.Parameters.Add("@refPri", SqlDbType.NVarChar).Value = e.refPri;
                cmd.Parameters.Add("@openPri", SqlDbType.NVarChar).Value = e.openPri;

                cmd.Parameters.Add("@highPri", SqlDbType.NVarChar).Value = e.highPri;
                cmd.Parameters.Add("@lowPri", SqlDbType.NVarChar).Value = e.lowPri;
                cmd.Parameters.Add("@upPri", SqlDbType.NVarChar).Value = e.upPri;
                cmd.Parameters.Add("@dnPri", SqlDbType.NVarChar).Value = e.dnPri;

                cmd.Parameters.Add("@matchTime", SqlDbType.NVarChar).Value = e.matchTime;
                cmd.Parameters.Add("@matchPri", SqlDbType.NVarChar).Value = e.matchPri;
                cmd.Parameters.Add("@matchQty", SqlDbType.NVarChar).Value = e.matchQty;
                cmd.Parameters.Add("@tolMatchQty", SqlDbType.NVarChar).Value = e.tolMatchQty;

                cmd.Parameters.Add("@bestBuyPri", SqlDbType.NVarChar).Value = e.bestBuyPri;
                cmd.Parameters.Add("@bestBuyQty", SqlDbType.NVarChar).Value = e.bestBuyQty;

                cmd.Parameters.Add("@bestSellPri", SqlDbType.NVarChar).Value = e.bestSellPri;
                cmd.Parameters.Add("@bestSellQty", SqlDbType.NVarChar).Value = e.bestSellQty;

                cmd.Parameters.Add("@currentTime", SqlDbType.DateTime).Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                try
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
                catch (SqlException ex)
                {
                    Console.WriteLine(ex);
                }
                finally
                {
                    conn.Close();
                    Console.WriteLine("Updating Finish");
                }
            }
        }
Beispiel #3
0
        public bool CheckData(_DYuantaQuoteEvents_OnGetMktAllEvent e)
        {
            // 檢查取得的資料是否與資料庫最後新增的那筆不同

            string sql = "select top 1 matchTime from Data order by id desc";
            SqlConnection conn = new SqlConnection(db.ini);
            SqlCommand cmd = new SqlCommand(sql);
            cmd.Connection = conn;

            DataList n_data = new DataList();
            DataList e_data = new DataList();

            try
            {
                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    n_data.matchTime = dr[0].ToString();
                }

                //  e matchTime
                e_data.matchTime = e.matchTime;
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                conn.Close();
            }

            // Compare 如果目前資料庫最後一筆matchTime 與 API取得的相同,就不寫入資料庫了
            Console.WriteLine("{0} = DataBase", n_data.matchTime);
            Console.WriteLine("{0} = API", e_data.matchTime);
            Console.WriteLine("{0} = Compare Result", n_data.matchTime == e_data.matchTime);
            return n_data.matchTime == e_data.matchTime;
        }