public static 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 " + 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); } } }
private void show_kd(Canvas kd_canvas, StockTradeInfo[] hist) { double left_line_x = 50; double buttom_space_y = 30; double x_step = (kd_canvas.ActualWidth - left_line_x) / hist.Length; double kd_height = kd_canvas.ActualHeight - buttom_space_y; Range_Mapper mapper = new Range_Mapper(); mapper.UpdateRange(hist); mapper.targer_size = kd_height; for (int i = 0; i < hist.Length; i++) { StockTradeInfo si = hist[i]; double x_center = left_line_x + (49 - i) * x_step + x_step / 2; SolidColorBrush color = si.close > si.open ? Brushes.Red : Brushes.Green; Line high_low = new Line(); high_low.Stroke = color; high_low.X1 = x_center; high_low.X2 = x_center; high_low.Y1 = flip_y(kd_height, mapper.map(si.low)); high_low.Y2 = flip_y(kd_height, mapper.map(si.high)); kd_canvas.Children.Add(high_low); Rectangle open_close = new Rectangle(); Canvas.SetLeft(open_close, x_center - x_step / 2); Canvas.SetTop(open_close, flip_y(kd_height, mapper.map(Math.Max(si.open, si.close)))); open_close.Width = x_step; open_close.Height = Math.Abs(mapper.map(si.open) - mapper.map(si.close)); open_close.Stroke = color; kd_canvas.Children.Add(open_close); } }
public override ArrayList ParseHtml(string source, DateTime date) { Logger.Log("Parsing Stock Page:" + date.ToString()); ArrayList stocks = new ArrayList(); if (!IsValidJson(source)) { return(stocks); } JObject obj = JObject.Parse(source); if (obj == null || obj["data9"] == null) { 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); }
float evaluate_transation(StockData stock_data, ArrayList history) { float value = 1; float share = 0; Trade_Cmd cmd; foreach (object obj in history) { cmd = (Trade_Cmd)obj; if (cmd.is_buy) { StockTradeInfo trade_info = stock_data.getByDate(cmd.date); float buy_price = trade_info.open; share = value / buy_price; value = 0; cmd.price = buy_price; } else { StockTradeInfo trade_info = stock_data.getByDate(cmd.date); float sell_price = trade_info.open; value = share * sell_price; share = 0; cmd.price = sell_price; cmd.perf = value; } } if (share > 0) { StockTradeInfo trade_info = stock_data.getLatest(); float sell_price = trade_info.open; value = share * sell_price; } return(value); }