Пример #1
0
        public static void AddOhlcQuoteInDb(OHLCQuote minuteBar)
        {
            using (var con = OpenConnection())
            {
                using (var command = con.CreateCommand())
                {
                    command.CommandText =
                        "INSERT INTO minutebars (open, high, low, close, symbol, TimeFrame, bartime, volume) VALUES (?o,?h,?l,?c,?s,?tf, ?t,?v)";
                    command.Parameters.AddWithValue("?o", minuteBar.Open);
                    command.Parameters.AddWithValue("?h", minuteBar.High);
                    command.Parameters.AddWithValue("?l", minuteBar.Low);
                    command.Parameters.AddWithValue("?c", minuteBar.Close);
                    command.Parameters.AddWithValue("?s", minuteBar.Symbol.Substring(0, 2));
                    command.Parameters.AddWithValue("?v", minuteBar.Volume);
                    command.Parameters.AddWithValue("?tf", minuteBar.Interval);
                    command.Parameters.AddWithValue("?t", minuteBar.Timestamp);


                    var result = command.ExecuteNonQuery();
                    if (result > 0)
                    {
                        Console.WriteLine("New bar O:" + minuteBar.Open + " H:" +
                                          minuteBar.High + " L:" +
                                          minuteBar.Low +
                                          " C:" + minuteBar.Close +
                                          " Symbol:" + minuteBar.Symbol + " Timeframe:" + minuteBar.Interval
                                          );
                    }
                    else
                    {
                        Console.WriteLine("Adding new bar into db was unsuccessful!");
                    }
                }
            }
        }
 void NewOHLCQuote(OHLCQuote quote)
 {
     if (this.InvokeRequired)
     {
         this.BeginInvoke(new NewOHLCQuoteHandler(NewOHLCQuote), new object[] { quote });
     }
     else
     {
         listOHLC.Items.Add(OHLCQuoteToString(quote));
     }
 }
Пример #3
0
 private void NewOhlcQuote(OHLCQuote q)
 {
     Data.MinuteBars.Add(new MinuteBar
     {
         Close    = (decimal)(q.Close * Data.PriceMultiplier),
         High     = (decimal)(q.High * Data.PriceMultiplier),
         Interval = (int)q.Interval,
         Low      = (decimal)(q.Low * Data.PriceMultiplier),
         Open     = (decimal)(q.Open * Data.PriceMultiplier),
         Symbol   = q.Symbol,
         Volume   = q.Volume,
         Time     = q.Timestamp
     });
     Program.Tf.StartNew(() => Db.AddOhlcQuoteInDb(q));
     //Console.WriteLine("New bar: "+q.Timestamp.ToString("hh:mm:ss.ffff") +" vs. "+ DateTime.Now.AddHours(-7).ToString("hh:mm:ss.ffff"));
 }
Пример #4
0
        public static string OhlcQuoteToString(OHLCQuote q)
        {
            var res = "";

            try
            {
                res =
                    $"{q.Symbol} @ {q.Timestamp:yyyy-MM-dd HH:mm}: Day={q.Day},Open={q.FormatValue(q.Open, NumericFormat.Default)},High={q.FormatValue(q.High, NumericFormat.Default)},Low={q.FormatValue(q.Low, NumericFormat.Default)},Close={q.FormatValue(q.Close, NumericFormat.Default)},Volume={q.Volume}";
            }
            catch (Exception ex)
            {
                res = "Error converting data from OHLC quote to string: " + ex.Message;
            }

            return(res);
        }
        private string OHLCQuoteToString(OHLCQuote q)
        {
            string res = "";

            try
            {
                res = string.Format("{0} @ {1}: Day={2},Open={3},High={4},Low={5},Close={6},Volume={7}",
                                    q.Symbol, q.Timestamp.ToString("yyyy-MM-dd HH:mm"),
                                    q.Day,
                                    q.FormatValue(q.Open, NumericFormat.Default),
                                    q.FormatValue(q.High, NumericFormat.Default),
                                    q.FormatValue(q.Low, NumericFormat.Default),
                                    q.FormatValue(q.Close, NumericFormat.Default),
                                    q.Volume);
            }
            catch (Exception ex)
            {
                res = "Error converting data from OHLC quote to string: " + ex.Message;
            }

            return(res);
        }