예제 #1
0
        /*public String StockDbName(String stock_index)
         * {
         *  return "s" + stock_index;
         * }*/

        public void StockData_Save(ArrayList data)
        {
            foreach (Object obj in data)
            {
                StockTradeInfo stock_info    = (StockTradeInfo)obj;
                String         stock_db_name = stock_info.stock_index;

                if (stock_db_name.StartsWith("237") == false)   //debug
                {
                    continue;
                }

                string sql_ins = "INSERT INTO " + StockPage.StockDbName(stock_db_name) + "( trans_date, trans_volume, trans_count, trans_value, open, high, low ," +
                                 "close, diff, close_buy_price, close_buy_volume, close_sell_price, close_sell_volume) VALUE(" +
                                 "'" + Util.convertDate2mysql(stock_info.trans_date) + "'" + "," + stock_info.trans_volume.ToString() + "," + stock_info.trans_count.ToString() + "," + stock_info.trans_value.ToString() + "," +
                                 Util.double2dec(stock_info.open, 6, 2) + "," + Util.double2dec(stock_info.high, 6, 2) + "," + Util.double2dec(stock_info.low, 5, 2) + "," + Util.double2dec(stock_info.close, 5, 2) + "," +
                                 Util.double2dec(stock_info.diff, 5, 2) + "," + Util.double2dec(stock_info.close_buy_price, 5, 2) + "," + stock_info.close_buy_volume.ToString() + "," +
                                 Util.double2dec(stock_info.close_sell_price, 5, 2) + "," + stock_info.close_sell_volume.ToString() + ");";
                MySqlCommand cmd_insert = new MySqlCommand(sql_ins, conn);
                try
                {
                    cmd_insert.ExecuteNonQuery();
                }
                catch (MySql.Data.MySqlClient.MySqlException ex)
                {
                    //MessageBox.Show("Error " + ex.Number + " has occurred: " + ex.Message,
                    //    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #2
0
        public override ArrayList ParseHtml(MySqlConnection conn, string source, DateTime date)
        {
            ArrayList stocks = new ArrayList();

            if (!IsValidJson(source))
            {
                return(stocks);
            }

            JObject obj = JObject.Parse(source);

            if (obj == null || obj["data9"] == null)
            {
                //no stock data
                return(stocks);
            }

            foreach (JArray stk in obj["data9"])
            {
                //String stock_str = stk.ToString();
                //stock_str = stock_str.Substring(1, stock_str.Length - 2);   //remove []
                JToken[] token_ary   = stk.ToArray();
                String[] stk_strings = new string[token_ary.Length];
                for (int i = 0; i < token_ary.Length; i++)
                {
                    stk_strings[i] = token_ary[i].ToString();
                }

                StockTradeInfo stock_info = new StockTradeInfo(stk_strings, date);
                stocks.Add(stock_info);
            }
            return(stocks);
        }
예제 #3
0
        public void StockData_Save(ArrayList data)
        {
            BsonDocument stock = new BsonDocument();

            stock.Add("stock_index", 2379);

            foreach (Object obj in data)
            {
                BsonDocument   perday     = new BsonDocument();
                StockTradeInfo stock_info = (StockTradeInfo)obj;

                var share_price = twstock_db.GetCollection <BsonDocument>(stock_info.stock_index);
                perday.Add("trans_volume", stock_info.trans_volume);
                perday.Add("trans_count", stock_info.trans_count);
                perday.Add("trans_value", stock_info.trans_value);
                perday.Add("open", stock_info.open);
                perday.Add("high", stock_info.high);
                perday.Add("low", stock_info.low);
                perday.Add("close", stock_info.close);
                perday.Add("diff", stock_info.diff);
                perday.Add("close_buy_price", stock_info.close_buy_price);
                perday.Add("close_sell_price", stock_info.close_sell_price);
                perday.Add("pe_ratio", stock_info.pe_ratio);
                perday.Add("close_buy_volume", stock_info.close_buy_volume);
                perday.Add("close_sell_volume", stock_info.close_sell_volume);

                share_price.InsertOne(perday);
            }
        }