Exemplo n.º 1
0
        public void AddAnalysisInfo(AnalysisDto analysis)
        {
            string sqlInsert = "INSERT INTO fx." + AnalysisInfoTable +
                "(AnalysisName, Symbol, FirstAnalysedItemDate, LastAnalysedItemDate, AnalysedUnits, " +
                    "AnalysisStart, AnalysisEnd, AnalysisTotalTime) " +
                "VALUES ('" + analysis.Type + "'" +
                    ", '" + analysis.Symbol + "'" +
                    ", '" + analysis.FirstItemDate + "'" +
                    ", '" + analysis.LastItemDate + "'" +
                    ", " + analysis.AnalyzedItems +
                    ", '" + analysis.AnalysisStart + "'" +
                    ", '" + analysis.AnalysisEnd + "'" +
                    ", " + analysis.AnalysisTotalTime.ToDbString() + ");";

            using (var context = new EFDbContext())
            {
                context.Database.ExecuteSqlCommand(sqlInsert);
                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        private void AddExtremum(ExtremumDto extremum)
        {
            if (extremum == null) return;

            string sqlInsert = string.Format(extremum.InsertSql(), ExtremaEvaluationTable);

            using (var context = new EFDbContext())
            {
                context.Database.ExecuteSqlCommand(sqlInsert);
                context.SaveChanges();
            }
        }
Exemplo n.º 3
0
        public void UpdateQuotation(QuotationDto quotation, string symbol)
        {
            string tableName = QuotationsTablePrefix + symbol;
            string sql = "UPDATE fx." + tableName +
                " SET " +
                    "  OpenPrice = " + quotation.OpenPrice.ToDbString() +
                    ", HighPrice = " + quotation.HighPrice.ToDbString() +
                    ", LowPrice = " + quotation.LowPrice.ToDbString() +
                    ", ClosePrice = " + quotation.ClosePrice.ToDbString() +
                    ", Volume = " + quotation.Volume.ToDbString() +
                " WHERE QuotationId = " + quotation.Id;

            using (var context = new EFDbContext())
            {
                context.Database.ExecuteSqlCommand(sql);
                context.SaveChanges();
            }
        }
Exemplo n.º 4
0
        public void UpdatePrice(PriceDto price, string symbol)
        {
            string tableName = PricesTablePrefix + symbol;
            string sql = "UPDATE fx." + tableName +
                " SET " +
                    "  AssetId = " + price.AssetId +
                    ", PriceDate = '" + price.PriceDate + "'" +
                    ", DeltaClosePrice = " + price.DeltaClosePrice.ToDbString() +
                    ", PriceDirection2D = " + price.PriceDirection2D +
                    ", PriceDirection3D = " + price.PriceDirection3D +
                    ", PeakByCloseEvaluation = " + price.PeakByCloseEvaluation.ToDbString() +
                    ", PeakByHighEvaluation = " + price.PeakByHighEvaluation.ToDbString() +
                    ", TroughByCloseEvaluation = " + price.TroughByCloseEvaluation.ToDbString() +
                    ", TroughByLowEvaluation = " + price.TroughByLowEvaluation.ToDbString() +
                    ", PriceGap = " + price.PriceGap.ToDbString() +
                " WHERE PriceId = " + price.Id;

            //Update info about extrema.
            UpdateExtremum(price.PeakByClose);
            UpdateExtremum(price.PeakByHigh);
            UpdateExtremum(price.TroughByClose);
            UpdateExtremum(price.TroughByLow);

            using (var context = new EFDbContext())
            {
                context.Database.ExecuteSqlCommand(sql);
                context.SaveChanges();
            }
        }
Exemplo n.º 5
0
        public void UpdateMacd(MacdDto macd, string symbol)
        {
            string tableName = MacdTablePrefix + symbol;

            string sqlUpdate = "UPDATE fx." + tableName +
                " SET " +
                    "MA13 = " + macd.Ma13.ToDbString() +
                    ", EMA13 = " + macd.Ema13.ToDbString() +
                    ", MA26 = " + macd.Ma26.ToDbString() +
                    ", EMA26 = " + macd.Ema26.ToDbString() +
                    ", MACDLine = " + macd.MacdLine.ToDbString() +
                    ", SignalLine = " + macd.SignalLine.ToDbString() +
                    ", Histogram = " + macd.Histogram.ToDbString() +
                    ", HistogramAvg = " + macd.HistogramAvg.ToDbString() +
                    ", HistogramExtremum = " + macd.HistogramExtremum.ToDbString() +
                    ", DeltaHistogram = " + macd.DeltaHistogram.ToDbString() +
                    ", DeltaHistogramPositive = " + macd.DeltaHistogramPositive +
                    ", DeltaHistogramNegative = " + macd.DeltaHistogramNegative +
                    ", DeltaHistogramZero = " + macd.DeltaHistogramZero +
                    ", HistogramDirection2D = " + macd.HistogramDirection2D +
                    ", HistogramDirection3D = " + macd.HistogramDirection3D +
                    ", HistogramDirectionChanged = " + macd.HistogramDirectionChanged +
                    ", HistogramToOX = " + macd.HistogramToOx +
                    ", HistogramRow = " + macd.HistogramRow +
                    ", OxCrossing = " + macd.OxCrossing.ToDbString() +
                    ", MacdPeak = " + macd.MacdPeak +
                    ", LastMACDPeak = " + macd.LastMacdPeak.ToDbString() +
                    ", MACDPeakSlope = " + macd.MacdPeakSlope.ToDbString() +
                    ", MACDTrough = " + macd.MacdTrough +
                    ", LastMACDTrough = " + macd.LastMacdTrough.ToDbString() +
                    ", MACDTroughSlope = " + macd.MacdTroughSlope.ToDbString() +
                 " WHERE PriceDate = '" + macd.PriceDate + "';";

            using (var context = new EFDbContext())
            {
                context.Database.ExecuteSqlCommand(sqlUpdate);
                context.SaveChanges();
            }
        }
Exemplo n.º 6
0
        public void UpdateExtremum(ExtremumDto extremum)
        {
            if (extremum == null) return;

            string sql = string.Format(extremum.Cancelled ? extremum.RemoveSql() : extremum.UpdateSql(), ExtremaEvaluationTable);

            using (var context = new EFDbContext())
            {
                context.Database.ExecuteSqlCommand(sql);
                context.SaveChanges();
            }
        }
Exemplo n.º 7
0
        public void AddMacd(MacdDto macd, string symbol)
        {
            string tableName = MacdTablePrefix + symbol;

            string sqlRemove = "DELETE FROM fx." + tableName +
                        " WHERE PriceDate = '" + macd.PriceDate + "';";
            string sqlInsert = "INSERT INTO fx." + tableName +
                "(AssetId, PriceDate, MA13, EMA13, MA26, EMA26, MACDLine, SignalLine, Histogram, HistogramAvg, " +
                "HistogramExtremum, DeltaHistogram, DeltaHistogramPositive, DeltaHistogramNegative, DeltaHistogramZero, " +
                "HistogramDirection2D, HistogramDirection3D, HistogramDirectionChanged, HistogramToOX, " +
                "HistogramRow, OxCrossing, MacdPeak, LastMACDPeak, MACDPeakSlope, MACDTrough, LastMACDTrough, MACDTroughSlope) " +
                "VALUES (" +
                    macd.AssetId +
                 ", '" + macd.PriceDate + "'" +
                 ", " + macd.Ma13.ToDbString() +
                 ", " + macd.Ema13.ToDbString() +
                 ", " + macd.Ma26.ToDbString() +
                 ", " + macd.Ema26.ToDbString() +
                 ", " + macd.MacdLine.ToDbString() +
                 ", " + macd.SignalLine.ToDbString() +
                 ", " + macd.Histogram.ToDbString() +
                 ", " + macd.HistogramAvg.ToDbString() +
                 ", " + macd.HistogramExtremum.ToDbString() +
                 ", " + macd.DeltaHistogram.ToDbString() +
                 ", " + macd.DeltaHistogramPositive +
                 ", " + macd.DeltaHistogramNegative +
                 ", " + macd.DeltaHistogramZero +
                 ", " + macd.HistogramDirection2D +
                 ", " + macd.HistogramDirection3D +
                 ", " + macd.HistogramDirectionChanged +
                 ", " + macd.HistogramToOx +
                 ", " + macd.HistogramRow +
                 ", " + macd.OxCrossing.ToDbString() +
                 ", " + macd.MacdPeak +
                 ", " + macd.LastMacdPeak.ToDbString() +
                 ", " + macd.MacdPeakSlope.ToDbString() +
                 ", " + macd.MacdTrough +
                 ", " + macd.LastMacdTrough.ToDbString() +
                 ", " + macd.MacdTroughSlope.ToDbString() +");";

            using (var context = new EFDbContext())
            {
                context.Database.ExecuteSqlCommand(sqlRemove);
                context.Database.ExecuteSqlCommand(sqlInsert);
                context.SaveChanges();
            }
        }
Exemplo n.º 8
0
        private void RemoveExtrema(string symbol, DateTime date)
        {
            string sqlDelete = string.Format("DELETE FROM fx.{0} " +
                                " WHERE " +
                                    " Symbol = '" + symbol + "' AND " +
                                    " PriceDate = '" + date + "';", ExtremaEvaluationTable);

            using (var context = new EFDbContext())
            {
                context.Database.ExecuteSqlCommand(sqlDelete);
                context.SaveChanges();
            }
        }
Exemplo n.º 9
0
        public void AddPrice(PriceDto price, string symbol)
        {
            string tableName = PricesTablePrefix + symbol;

            string sqlRemove = "DELETE FROM fx." + tableName +
                        " WHERE PriceDate = '" + price.PriceDate + "';";
            string sqlInsert = "INSERT INTO fx." + tableName +
                "(AssetId, PriceDate, DeltaClosePrice, PriceDirection3D, PriceDirection2D, " +
                    "PeakByCloseEvaluation, PeakByHighEvaluation, TroughByCloseEvaluation, " +
                    "TroughByLowEvaluation, PriceGap) " +
                "VALUES (" +
                       price.AssetId +
                    ", '" + price.PriceDate + "'" +
                    ", " + price.DeltaClosePrice.ToDbString() +
                    ", " + price.PriceDirection3D +
                    ", " + price.PriceDirection2D +
                    ", " + price.PeakByCloseEvaluation.ToDbString() +
                    ", " + price.PeakByHighEvaluation.ToDbString() +
                    ", " + price.TroughByCloseEvaluation.ToDbString() +
                    ", " + price.TroughByLowEvaluation.ToDbString() +
                    ", " + price.PriceGap.ToDbString() + ");";

            //Add info about extrema.
            RemoveExtrema(symbol, price.PriceDate);
            AddExtremum(price.PeakByClose);
            AddExtremum(price.PeakByHigh);
            AddExtremum(price.TroughByClose);
            AddExtremum(price.TroughByLow);

            using (var context = new EFDbContext())
            {
                context.Database.ExecuteSqlCommand(sqlRemove);
                context.SaveChanges();
                context.Database.ExecuteSqlCommand(sqlInsert);
                context.SaveChanges();
            }
        }