Пример #1
0
        public PriceDto ToDto()
        {
            var dto = new PriceDto
            {
                AssetId = this.AssetId
                , DeltaClosePrice = this.CloseDelta
                , Id = this.Id
                , PriceDate = this.Date
                , PriceGap = this.PriceGap
                , PeakByCloseEvaluation = this.PeakByClose
                , PeakByHighEvaluation = this.PeakByHigh
                , PriceDirection2D = this.Direction2D
                , PriceDirection3D = this.Direction3D
                , TroughByCloseEvaluation = this.TroughByClose
                , TroughByLowEvaluation = this.TroughByLow
                , TimeframeId = 1
                , PeakByClose = (PeakByCloseExtremum != null ? PeakByCloseExtremum.ToDto() : null)
                , PeakByHigh = (PeakByHighExtremum != null ? PeakByHighExtremum.ToDto() : null)
                , TroughByClose = (TroughByCloseExtremum != null ? TroughByCloseExtremum.ToDto() : null)
                , TroughByLow = (TroughByLowExtremum != null ? TroughByLowExtremum.ToDto() : null)
                , CloseRatio = this.CloseRatio
                , ExtremumRatio = this.ExtremumRatio
            };

            return dto;
        }
Пример #2
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();
            }
        }
Пример #3
0
        public static Price FromDto(PriceDto dto)
        {
            var price = new Price();
            price.Id = dto.Id;
            price.AssetId = dto.AssetId;
            price.Date = dto.PriceDate;
            price.CloseDelta = dto.DeltaClosePrice;
            price.Direction2D = dto.PriceDirection2D;
            price.Direction3D = dto.PriceDirection3D;
            price.PriceGap = dto.PriceGap;
            price.PeakByClose = dto.PeakByCloseEvaluation;
            price.PeakByHigh = dto.PeakByHighEvaluation;
            price.TroughByClose = dto.TroughByCloseEvaluation;
            price.TroughByLow = dto.TroughByLowEvaluation;
            price.CloseRatio = dto.CloseRatio;
            price.ExtremumRatio = dto.ExtremumRatio;

            return price;
        }
Пример #4
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();
            }
        }