Пример #1
0
        public void TestRemoveFFD()
        {
            var tempConnection = DataBaseLink.Fabricate.CreateConnection(_connection, ConnectionType.Npgsql);

            DataBaseLink.DbLink dbLink = new DbLink(tempConnection);
            //инструмент
            fin_instrument fin_instrument = new fin_instrument("roman", 13, "bushuev");

            if (FinInstrument.FindId(dbLink, fin_instrument.ident) == null)
            {
                FinInstrument.Insert(dbLink, fin_instrument);
            }

            var result = FinInstrument.FindId(dbLink, fin_instrument.ident);
            //fisd_id
            ffd ffd = new ffd()
            {
                ds_id  = 17,
                fi_id  = result.fi_id,
                fif_id = 11,
            };

            if (FFD.Find(dbLink, ffd.fi_id, ffd.ds_id, ffd.fif_id) == null)
            {
                FFD.Insert(dbLink, ffd);
                var ffdResult = FFD.Find(dbLink, result.fi_id, ffd.ds_id, ffd.fif_id);
                FFD.Remove(dbLink, ffdResult);
            }
            else
            {
                var ffdResult = FFD.Find(dbLink, result.fi_id, ffd.ds_id, ffd.fif_id);
                FFD.Remove(dbLink, ffdResult);
            }
        }
        //insert
        public static void Insert(DbLink dbLink, fin_instrument finInstrument)
        {
            string query =
                @"insert into fin_instrument(fi_id,ident,ft_id,title)
                    values(nextval('mir_sequence'), @ident, @ft_id, @title);";

            dbLink.GetConnection().Execute(query, finInstrument);
        }
        public void TestRemoveFisdItem()
        {
            var    tempConnection = DataBaseLink.Fabricate.CreateConnection(_connection, ConnectionType.Npgsql);
            DbLink dbLink         = new DbLink(tempConnection);

            //создать финансовый инструмент
            fin_instrument fin_instrument = new fin_instrument("roman", 13, "bushuev");

            if (FinInstrument.FindId(dbLink, fin_instrument.ident) == null)
            {
                FinInstrument.Insert(dbLink, fin_instrument);
            }

            var resultFI = FinInstrument.FindId(dbLink, fin_instrument.ident);

            //ffd
            ffd ffd = new ffd()
            {
                ds_id  = 17,
                fi_id  = resultFI.fi_id,
                fif_id = 8,
            };

            if (FFD.Find(dbLink, resultFI.fi_id, ffd.ds_id, ffd.fif_id) == null)
            {
                FFD.Insert(dbLink, ffd);
            }
            var ffdResult = FFD.Find(dbLink, resultFI.fi_id, ffd.ds_id, ffd.fif_id);

            //dict_item
            dict_item dict_item = new dict_item()
            {
                fif_id = 8,
                key_v  = "RUB",
            };

            var resultDictItem = DictItem.FindId(dbLink, dict_item.key_v, dict_item.fif_id);

            //fisd_item
            fisd_item fisd_item = new fisd_item()
            {
                dat_from = new DateTime(2017, 08, 05),
                fisd_id  = ffdResult.fisd_id,
                val      = resultDictItem.key_v
            };

            if (FisdItem.FindId(dbLink, fisd_item.fisd_id, fisd_item.dat_from) == null)
            {
                FisdItem.Insert(dbLink, fisd_item);
                var one = FisdItem.FindId(dbLink, fisd_item.fisd_id, fisd_item.dat_from);
                FisdItem.Remove(dbLink, one.fisd_id, one.dat_from);
            }
            else
            {
                var one = FisdItem.FindId(dbLink, fisd_item.fisd_id, fisd_item.dat_from);
                FisdItem.Remove(dbLink, one.fisd_id, one.dat_from);
            }
        }
Пример #4
0
        public void TestInsertFinInstrument()
        {
            var tempConnection = DataBaseLink.Fabricate.CreateConnection(_connection, ConnectionType.Npgsql);

            DataBaseLink.DbLink dbLink         = new DbLink(tempConnection);
            fin_instrument      fin_instrument = new fin_instrument("roman", 13, "bushuev");

            if (FinInstrument.FindId(dbLink, fin_instrument.ident) == null)
            {
                FinInstrument.Insert(dbLink, fin_instrument);
            }
        }
Пример #5
0
        public void TestInsertQuote()
        {
            //вставим несколько значений за разные даты
            var tempConnection = DataBaseLink.Fabricate.CreateConnection(_connection, ConnectionType.Npgsql);

            DataBaseLink.DbLink dbLink = new DbLink(tempConnection);
            //создать финансовый инструмент
            fin_instrument fin_instrument = new fin_instrument("roman", 13, "bushuev");

            if (FinInstrument.FindId(dbLink, fin_instrument.ident) == null)
            {
                FinInstrument.Insert(dbLink, fin_instrument);
            }

            var result = FinInstrument.FindId(dbLink, fin_instrument.ident);

            ffd ffd = new ffd()
            {
                ds_id  = 17,
                fi_id  = result.fi_id,
                fif_id = 3
            };

            if (FFD.Find(dbLink, result.fi_id, ffd.ds_id, ffd.fif_id) == null)
            {
                FFD.Insert(dbLink, ffd);
            }
            var ffdResult = FFD.Find(dbLink, result.fi_id, ffd.ds_id, ffd.fif_id);

            fisd_dq fisd_dq = new fisd_dq()
            {
                dat     = DateTime.Today.AddDays(-1),
                fisd_id = ffdResult.fisd_id,
                val     = 10.0m
            };

            if (FisdDq.FindId(dbLink, fisd_dq.fisd_id, fisd_dq.dat) == null)
            {
                FisdDq.Insert(dbLink, fisd_dq);
            }

            fisd_dq = new fisd_dq()
            {
                dat     = DateTime.Today,
                fisd_id = ffdResult.fisd_id,
                val     = 11.0m
            };

            if (FisdDq.FindId(dbLink, fisd_dq.fisd_id, fisd_dq.dat) == null)
            {
                FisdDq.Insert(dbLink, fisd_dq);
            }
        }
        public void TestRemoveFisdNum()
        {
            var tempConnection = DataBaseLink.Fabricate.CreateConnection(_connection, ConnectionType.Npgsql);

            DataBaseLink.DbLink dbLink         = new DbLink(tempConnection);
            fin_instrument      fin_instrument = new fin_instrument("roman", 13, "bushuev");

            if (FinInstrument.FindId(dbLink, fin_instrument.ident) == null)
            {
                FinInstrument.Insert(dbLink, fin_instrument);
            }

            var result = FinInstrument.FindId(dbLink, fin_instrument.ident);

            //fisd_id
            ffd ffd = new ffd()
            {
                ds_id  = 17,
                fi_id  = result.fi_id,
                fif_id = 11,
            };

            if (FFD.Find(dbLink, result.fi_id, ffd.ds_id, ffd.fif_id) == null)
            {
                FFD.Insert(dbLink, ffd);
            }
            var ffdResult = FFD.Find(dbLink, result.fi_id, ffd.ds_id, ffd.fif_id);

            fisd_num fisd_num = new fisd_num()
            {
                fisd_id  = ffdResult.fisd_id,
                dat_from = new DateTime(2018, 03, 24),
                val      = 320.0m
            };


            if (FisdNum.FindId(dbLink, ffdResult.fisd_id, fisd_num.dat_from) == null)
            {
                FisdNum.Insert(dbLink, fisd_num);
                var one = FisdNum.FindId(dbLink, fisd_num.fisd_id, fisd_num.dat_from);
                FisdNum.Remove(dbLink, fisd_num.fisd_id, fisd_num.dat_from);
            }
            else
            {
                FisdNum.Insert(dbLink, fisd_num);
                var one = FisdNum.FindId(dbLink, fisd_num.fisd_id, fisd_num.dat_from);
                FisdNum.Remove(dbLink, fisd_num.fisd_id, one.dat_from);
            }
        }
        public void TestRemoveFisdDate()
        {
            var tempConnection = DataBaseLink.Fabricate.CreateConnection(_connection, ConnectionType.Npgsql);

            DataBaseLink.DbLink dbLink = new DbLink(tempConnection);
            //создать финансовый инструмент
            fin_instrument fin_instrument = new fin_instrument("roman", 13, "bushuev");

            if (FinInstrument.FindId(dbLink, fin_instrument.ident) == null)
            {
                FinInstrument.Insert(dbLink, fin_instrument);
            }

            var result = FinInstrument.FindId(dbLink, fin_instrument.ident);

            //fisd_id
            ffd ffd = new ffd()
            {
                ds_id  = 17,
                fi_id  = result.fi_id,
                fif_id = 11,
            };

            if (FFD.Find(dbLink, result.fi_id, ffd.ds_id, ffd.fif_id) == null)
            {
                FFD.Insert(dbLink, ffd);
            }
            var ffdResult = FFD.Find(dbLink, result.fi_id, ffd.ds_id, ffd.fif_id);

            //создать fisd_date
            fisd_date fisdDate = new fisd_date()
            {
                fisd_id  = ffdResult.fisd_id,
                dat_from = new DateTime(2018, 03, 25),
                val      = new DateTime(2018, 03, 25)
            };

            if (FisdDate.FindId(dbLink, fisdDate.fisd_id, fisdDate.dat_from) == null)
            {
                FisdDate.Insert(dbLink, fisdDate);
                var one = FisdDate.FindId(dbLink, fisdDate.fisd_id, fisdDate.dat_from);
                FisdDate.Remove(dbLink, fisdDate.fisd_id, one.dat_from);
            }
            else
            {
                var one = FisdDate.FindId(dbLink, fisdDate.fisd_id, fisdDate.dat_from);
                FisdDate.Remove(dbLink, fisdDate.fisd_id, one.dat_from);
            }
        }
Пример #8
0
        public void TestRemoveFinInstrument()
        {
            var tempConnection = DataBaseLink.Fabricate.CreateConnection(_connection, ConnectionType.Npgsql);

            DataBaseLink.DbLink dbLink         = new DbLink(tempConnection);
            fin_instrument      fin_instrument = new fin_instrument("roman", 13, "bushuev");

            if (FinInstrument.FindId(dbLink, fin_instrument.ident) == null)
            {
                FinInstrument.Insert(dbLink, fin_instrument);
                var t = FinInstrument.FindId(dbLink, fin_instrument.ident);
                Console.WriteLine(t.fi_id);
                FinInstrument.Remove(dbLink, t.fi_id);
            }
            else
            {
                var t = FinInstrument.FindId(dbLink, fin_instrument.ident);
                Console.WriteLine(t.fi_id);
                FinInstrument.Remove(dbLink, t.fi_id);
            }
        }
        private void Save(Dictionary <PortfolioPosition, TimeSeries> storage)
        {
            foreach (var x in storage)
            {
                var transaction = _dbLink.GetConnection().BeginTransaction(IsolationLevel.ReadCommitted);
                try
                {
                    // найдем тип финансового инструмента
                    var    finIdent     = x.Key.Ident;
                    var    finType      = x.Key.FinType;
                    string finTypeIdent = _mapping.GetAI(finType);

                    #region финансовый инструмент
                    fin_instrument finInstrument = new fin_instrument()
                    {
                        ident = finIdent,
                        title = finIdent,
                        ft_id = int.Parse(finTypeIdent)
                    };

                    if (FinInstrument.FindId(_dbLink, finInstrument.ident) == null)
                    {
                        FinInstrument.Insert(_dbLink, finInstrument);
                    }

                    finInstrument = FinInstrument.FindId(_dbLink, finInstrument.ident);
                    #endregion

                    #region Data_source
                    data_source dataSource = new data_source()
                    {
                        ident = _providerParams[SCALAR].ToString(),
                    };

                    dataSource = DataSource.FindId(_dbLink, dataSource.ident);
                    #endregion

                    #region fisd_id
                    ffd ffd = new ffd()
                    {
                        ds_id  = dataSource.ds_id,
                        fi_id  = finInstrument.fi_id,
                        fif_id = int.Parse(_mapping.GetAI(x.Value.Attribute))
                    };

                    if (FFD.Find(_dbLink, ffd.fi_id, ffd.ds_id, ffd.fif_id) == null)
                    {
                        FFD.Insert(_dbLink, ffd);
                    }
                    ffd = FFD.Find(_dbLink, ffd.fi_id, ffd.ds_id, ffd.fif_id);
                    #endregion

                    #region TimeSeries
                    foreach (var z in x.Value.Series)
                    {
                        fisd_dq fisd_dq = new fisd_dq()
                        {
                            dat     = z.Key,
                            val     = z.Value,
                            fisd_id = ffd.fisd_id
                        };

                        if (FisdDq.FindId(_dbLink, fisd_dq.fisd_id, fisd_dq.dat) == null)
                        {
                            FisdDq.Insert(_dbLink, fisd_dq);
                        }
                        else
                        {
                            FisdDq.Update(_dbLink, fisd_dq);
                        }
                    }
                    #endregion

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                }
            }
        }
        private void Save(Dictionary <KeyValuePair <PortfolioPosition, Enum>, ScalarNum> storage)
        {
            foreach (var x in storage)
            {
                var transaction = _dbLink.GetConnection().BeginTransaction(IsolationLevel.ReadCommitted);
                try
                {
                    // найдем тип финансового инструмента
                    var    finIdent     = x.Key.Key.Ident;
                    var    finType      = x.Key.Key.FinType;
                    string finTypeIdent = _mapping.GetAI(finType);

                    #region финансовый инструмент
                    fin_instrument finInstrument = new fin_instrument()
                    {
                        ident = finIdent,
                        title = finIdent,
                        ft_id = int.Parse(finTypeIdent)
                    };

                    if (FinInstrument.FindId(_dbLink, finInstrument.ident) == null)
                    {
                        FinInstrument.Insert(_dbLink, finInstrument);
                    }

                    finInstrument = FinInstrument.FindId(_dbLink, finInstrument.ident);

                    #endregion

                    #region Data_source
                    data_source dataSource = new data_source()
                    {
                        ident = _providerParams[SCALAR].ToString(),
                    };

                    dataSource = DataSource.FindId(_dbLink, dataSource.ident);
                    #endregion

                    #region fisd_id
                    ffd ffd = new ffd()
                    {
                        ds_id  = dataSource.ds_id,
                        fi_id  = finInstrument.fi_id,
                        fif_id = int.Parse(_mapping.GetAI(x.Key.Value))
                    };

                    if (FFD.Find(_dbLink, ffd.fi_id, ffd.ds_id, ffd.fif_id) == null)
                    {
                        FFD.Insert(_dbLink, ffd);
                    }
                    ffd = FFD.Find(_dbLink, ffd.fi_id, ffd.ds_id, ffd.fif_id);
                    #endregion

                    fisd_num fisdNum = new fisd_num()
                    {
                        dat_from = x.Value.Dictionary.First().Key,
                        fisd_id  = ffd.fisd_id,
                        val      = x.Value.Dictionary.First().Value
                    };

                    FisdNum.Insert(_dbLink, fisdNum);
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                }
            }
        }
        private void Save(Dictionary <PortfolioPosition, CashFlow> dictionary)
        {
            foreach (var x in dictionary)
            {
                var transaction = _dbLink.GetConnection().BeginTransaction(IsolationLevel.ReadCommitted);
                try
                {
                    var    finIdent     = x.Key.Ident;
                    var    finType      = x.Key.FinType;
                    string finTypeIdent = _mapping.GetAI(finType);

                    #region финансовый инструмент
                    fin_instrument finInstrument = new fin_instrument()
                    {
                        ident = finIdent,
                        title = finIdent,
                        ft_id = int.Parse(finTypeIdent)
                    };

                    if (FinInstrument.FindId(_dbLink, finInstrument.ident) == null)
                    {
                        FinInstrument.Insert(_dbLink, finInstrument);
                    }

                    finInstrument = FinInstrument.FindId(_dbLink, finInstrument.ident);
                    #endregion

                    #region Data_source
                    data_source dataSource = new data_source()
                    {
                        ident = _providerParams[SCALAR].ToString(),
                    };

                    dataSource = DataSource.FindId(_dbLink, dataSource.ident);
                    #endregion

                    #region fcs
                    fcs ffd = new fcs()
                    {
                        ds_id = dataSource.ds_id,
                        fi_id = finInstrument.fi_id,
                        ct_id = int.Parse(_mapping.GetAI(x.Value.Attribute))
                    };

                    if (FCS.Find(_dbLink, ffd.fi_id, ffd.ds_id, ffd.ct_id) == null)
                    {
                        FCS.Insert(_dbLink, ffd);
                    }
                    ffd = FCS.Find(_dbLink, ffd.fi_id, ffd.ds_id, ffd.ct_id);
                    #endregion

                    #region Денежный поток
                    foreach (var z in x.Value.Values)
                    {
                        cashflow cf = new cashflow()
                        {
                            cf_id     = ffd.cf_id,
                            dat       = z.Key,
                            val       = z.Value,
                            valid_dat = (DateTime)_providerParams[REPORTDATE]
                        };

                        if (Cashflow.FindId(_dbLink, cf.cf_id, cf.dat, cf.valid_dat) == null)
                        {
                            //первое значение, следовательно 01.01.1900 год
                            cf.valid_dat = new DateTime(1900, 01, 01);
                            Cashflow.Insert(_dbLink, cf);
                        }
                        else
                        {
                            Cashflow.Insert(_dbLink, cf);
                        }
                    }
                    #endregion


                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                }
            }
        }