Beispiel #1
0
        public void SyncAccountDataAsync_accounts_sameAccount()
        {
            IAccountDA         accountDA = new AccountDAMock();
            SyncPipeServerMock sps       = new SyncPipeServerMock();
            IInstrumDA         instrumDA = new InstrumDAMock();
            IReplicationBL     replBL    = new ReplicationBLMock();

            ImportLeech import = new ImportLeech(instrumDA, accountDA, null, null, replBL);

            import.SyncAccountDataAsync(sps).Wait();

            var r_accounts = sps.GetAccountList().Result;

            CompareAccounts(r_accounts, accountDA.GetAccounts(), replBL);

            // изменим account
            r_accounts[0].Code          = "***";
            r_accounts[0].Name          = "+++";
            r_accounts[0].IsShortEnable = !r_accounts[0].IsShortEnable;
            r_accounts[0].CommPerc     += 0.5m;

            import.SyncAccountDataAsync(sps).Wait();

            CompareAccounts(r_accounts, accountDA.GetAccounts(), replBL);

            // добавим еще account
            sps.AddAccount(Common.Data.AccountTypes.Test, "ccc", "nnn", 0, false);

            import.SyncAccountDataAsync(sps).Wait();

            CompareAccounts(sps.GetAccountList().Result, accountDA.GetAccounts(), replBL);

            // удаление account не тестируем
        }
Beispiel #2
0
        public void SyncAccountDataAsync_holdings_sameHoldings()
        {
            IInstrumDA         instrumDA = new InstrumDAMock();
            IAccountDA         accountDA = new AccountDAMock();
            SyncPipeServerMock sps       = new SyncPipeServerMock();
            IReplicationBL     replBL    = new ReplicationBLMock();
            ImportLeech        import    = new ImportLeech(instrumDA, accountDA, null, null, replBL);

            var r_accounts = sps.GetAccountList().Result;
            var r_instrums = sps.GetInstrumList().Result;

            // добавили две записи в разные accounts
            var r_h1 = sps.AddHolding(r_accounts[0].AccountID, r_instrums[0].InsID, 100);
            var r_h2 = sps.AddHolding(r_accounts[1].AccountID, r_instrums[1].InsID, 200);

            // синхронизировали
            import.SyncAccountDataAsync(sps).Wait();

            // узнаем локальные accountID
            var repl_acc = replBL.GetReplications(Common.Data.ReplObjects.Account);
            int l_acc0ID = repl_acc[r_accounts[0].AccountID];
            int l_acc1ID = repl_acc[r_accounts[1].AccountID];

            // сравниваем
            CompareHoldings(sps.GetHoldingList(r_accounts[0].AccountID).Result, accountDA.GetHoldings(l_acc0ID), replBL);
            CompareHoldings(sps.GetHoldingList(r_accounts[1].AccountID).Result, accountDA.GetHoldings(l_acc1ID), replBL);

            // поменяем записи
            r_h1.LotCount = 1000;
            r_h2.LotCount = 2000;

            // синхронизировали
            import.SyncAccountDataAsync(sps).Wait();

            // сравниваем
            CompareHoldings(sps.GetHoldingList(r_accounts[0].AccountID).Result, accountDA.GetHoldings(l_acc0ID), replBL);
            CompareHoldings(sps.GetHoldingList(r_accounts[1].AccountID).Result, accountDA.GetHoldings(l_acc1ID), replBL);

            // еще добавили запись
            var r_h3 = sps.AddHolding(r_accounts[1].AccountID, r_instrums[2].InsID, 300);

            // синхронизировали
            import.SyncAccountDataAsync(sps).Wait();

            // сравниваем
            CompareHoldings(sps.GetHoldingList(r_accounts[0].AccountID).Result, accountDA.GetHoldings(l_acc0ID), replBL);
            CompareHoldings(sps.GetHoldingList(r_accounts[1].AccountID).Result, accountDA.GetHoldings(l_acc1ID), replBL);

            // удалили записи
            sps.RemoveHolding(r_h1);
            sps.RemoveHolding(r_h2);

            // синхронизировали
            import.SyncAccountDataAsync(sps).Wait();

            // сравниваем
            CompareHoldings(sps.GetHoldingList(r_accounts[0].AccountID).Result, accountDA.GetHoldings(l_acc0ID), replBL);
            CompareHoldings(sps.GetHoldingList(r_accounts[1].AccountID).Result, accountDA.GetHoldings(l_acc1ID), replBL);
        }
Beispiel #3
0
        public void Series_fulltest()
        {
            IAccountDA accDA = new AccountDAMock();
            SeriesData sd    = new SeriesData(accDA);
            int        accID = 10;

            // создали серию
            int sid = sd.OpenSeries("key1");

            // записали туда числа
            DateTime d = new DateTime(2019, 1, 1);

            sd.AddSeriesValue(sid, d, 100);

            // сохранили
            sd.SetAccount(accID);
            sd.SaveData();

            // загрузили
            SeriesData sd1 = new SeriesData(accDA);

            sd1.LoadData(accID);

            // создали новую серию
            int sid1 = sd1.OpenSeries("key1"); // старая
            int sid2 = sd1.OpenSeries("key2"); // новая

            // записали числа в старую серию
            sd1.AddSeriesValue(sid1, d, 200);

            // записали числа в новую серию
            sd1.AddSeriesValue(sid2, d, 300);

            // сохранили
            sd1.SaveData();

            // загрузили
            SeriesData sd3 = new SeriesData(accDA);

            sd3.LoadData(accID);

            // проверяем
            var series = accDA.GetSeries(accID).ToList();

            Assert.Equal(2, series.Count);
            var s1_ = series.FirstOrDefault(s => s.Key == "key1");
            var s2_ = series.FirstOrDefault(s => s.Key == "key2");

            Assert.Equal(accID, s1_.AccountID);
            Assert.Equal(accID, s2_.AccountID);

            var sv1_ = accDA.GetValues(s1_.SeriesID).ToList();

            Assert.Equal(2, sv1_.Count);
            var sv2_ = accDA.GetValues(s2_.SeriesID).ToList();

            Assert.Single(sv2_);
        }
Beispiel #4
0
        public void SubscribeValueRow_fulltest()
        {
            IAccountDA accDA = new AccountDAMock();
            SeriesData sd    = new SeriesData(accDA);
            int        accID = 10;

            // создали серию и подписали на нее поток
            int    sid  = sd.OpenSeries("key1");
            BarRow bars = new BarRow(Timeframes.Day, 1);

            sd.SubscribeValueRow(sid, bars.Close, bars.Dates);

            // в поток добавляем 10 значений
            DateTime d = new DateTime(2019, 1, 1, 10, 0, 0);

            for (int i = 0; i < 10; i++)
            {
                bars.AddTick(d, 100, 1);
                d = d.AddDays(1);
            }
            bars.CloseLastBar();

            sd.SetAccount(accID);
            sd.SaveData(); // после сохранения sid уже не актуален, надо использовать series[0].SeriesID

            var series = accDA.GetSeries(accID).ToList();

            Assert.Single(series); // серия одна

            var vals = accDA.GetValues(series[0].SeriesID).ToList();

            Assert.True(vals.Count == 10); // в серии 10 значений

            // теперь отпишемся от потока
            sd.SubscribeValueRow(series[0].SeriesID, null, null);

            // в поток добавляем еще 10 значений
            for (int i = 0; i < 10; i++)
            {
                bars.AddTick(d, 200, 1);
                d = d.AddDays(1);
            }
            bars.CloseLastBar();

            // снова запишем данные
            sd.SaveData();

            var vals1 = accDA.GetValues(series[0].SeriesID).ToList();

            Assert.True(vals1.Count == 10); // в серии по прежнему 10 значений
        }
Beispiel #5
0
        public void SyncAccountDataAsync_instrums_sameInstrums()
        {
            IAccountDA         accountDA = new AccountDAMock();
            IInstrumDA         instrumDA = new InstrumDAMock();
            SyncPipeServerMock sps       = new SyncPipeServerMock();
            IReplicationBL     replBL    = new ReplicationBLMock();

            ImportLeech import = new ImportLeech(instrumDA, accountDA, null, null, replBL);

            import.SyncAccountDataAsync(sps).Wait();

            var r_instrums = sps.GetInstrumList().Result;

            CompareInstrums(r_instrums, instrumDA.GetInstrums(), replBL);

            // изменим instrum
            r_instrums[0].ShortName = "***";
            r_instrums[0].Name      = "+++";
            r_instrums[0].LotSize   = 10;
            r_instrums[0].Decimals  = 3;

            import.SyncAccountDataAsync(sps).Wait();

            CompareInstrums(r_instrums, instrumDA.GetInstrums(), replBL);

            // новый инструмент
            var newIns = sps.AddInstrum("ttt", "sn");

            import.SyncAccountDataAsync(sps).Wait();

            CompareInstrums(sps.GetInstrumList().Result, instrumDA.GetInstrums(), replBL);

            // удалим инструмент
            sps.RemoveInstrum(newIns.InsID);

            import.SyncAccountDataAsync(sps).Wait();

            // при удалении инструмента в удаленной базе,
            // в локальной базе мы его не удаляем,
            // а удаляем лишь репликацию
            bool isReplFound = replBL.GetReplications(Common.Data.ReplObjects.Instrum).ContainsKey(newIns.InsID);

            Assert.False(isReplFound);

            // в удаленной базе должно быть на 1 меньше
            Assert.Equal(sps.GetInstrumList().Result.Count(), instrumDA.GetInstrums().Count() - 1);
        }
Beispiel #6
0
        public void SyncAccountDataAsync_cash_sameCash()
        {
            IInstrumDA         instrumDA = new InstrumDAMock();
            IAccountDA         accountDA = new AccountDAMock();
            SyncPipeServerMock sps       = new SyncPipeServerMock();
            IReplicationBL     replBL    = new ReplicationBLMock();
            ImportLeech        import    = new ImportLeech(instrumDA, accountDA, null, null, replBL);

            var r_accounts = sps.GetAccountList().Result;
            var r_instrums = sps.GetInstrumList().Result;

            // добавили две записи в разные accounts
            var r_h1 = sps.AddCash(r_accounts[0].AccountID, 100);
            var r_h2 = sps.AddCash(r_accounts[1].AccountID, 200);

            // синхронизировали
            import.SyncAccountDataAsync(sps).Wait();

            // узнаем локальные accountID
            var repl_acc = replBL.GetReplications(Common.Data.ReplObjects.Account);
            int l_acc0ID = repl_acc[r_accounts[0].AccountID];
            int l_acc1ID = repl_acc[r_accounts[1].AccountID];

            // сравниваем
            var rCash = sps.GetCash(r_accounts[0].AccountID).Result;
            var lCash = accountDA.GetCash(l_acc0ID);

            CompareCash(rCash, lCash);

            // изменили данные
            rCash.Initial  += 10.0m;
            rCash.Current  += 20.0m;
            rCash.Buy      += 30.0m;
            rCash.BuyComm  += 40.0m;
            rCash.Sell     += 50.0m;
            rCash.SellComm += 60.0m;

            // синхронизировали
            import.SyncAccountDataAsync(sps).Wait();

            // сравниваем
            var rCash1 = sps.GetCash(r_accounts[0].AccountID).Result;
            var lCash1 = accountDA.GetCash(l_acc0ID);

            CompareCash(rCash1, lCash1);
        }
Beispiel #7
0
        public void SyncAccountDataAsync_data_sameData()
        {
            IInstrumDA         instrumDA = new InstrumDAMock();
            IAccountDA         accountDA = new AccountDAMock();
            SyncPipeServerMock sps       = new SyncPipeServerMock();
            IReplicationBL     replBL    = new ReplicationBLMock();

            var r_accounts = sps.GetAccountList().Result;
            var r_instrums = sps.GetInstrumList().Result;

            var so1  = sps.AddStopOrder(r_accounts[0].AccountID, r_instrums[0].InsID, Platform.BuySell.Buy, Platform.StopOrderType.StopLoss, 1000, 1);
            var ord1 = sps.AddOrder(so1);
            var trd1 = sps.AddTrade(ord1);
            var ord2 = sps.AddOrder(r_accounts[1].AccountID, r_instrums[1].InsID, Platform.BuySell.Sell, 1000, 1);
            var trd2 = sps.AddTrade(ord2);

            // действительно добавили записи
            Assert.True(sps.GetStopOrders(r_accounts[0].AccountID, 0).Result.Count() == 1);
            Assert.True(sps.GetOrders(r_accounts[0].AccountID, 0).Result.Count() == 1);
            Assert.True(sps.GetTrades(r_accounts[0].AccountID, 0).Result.Count() == 1);
            Assert.True(sps.GetStopOrders(r_accounts[1].AccountID, 0).Result.Count() == 0);
            Assert.True(sps.GetOrders(r_accounts[1].AccountID, 0).Result.Count() == 1);
            Assert.True(sps.GetTrades(r_accounts[1].AccountID, 0).Result.Count() == 1);

            ImportLeech import = new ImportLeech(instrumDA, accountDA, null, null, replBL);

            import.SyncAccountDataAsync(sps).Wait();

            // узнаем локальные accountID
            var repl_acc = replBL.GetReplications(Common.Data.ReplObjects.Account);
            int l_acc0ID = repl_acc[r_accounts[0].AccountID];
            int l_acc1ID = repl_acc[r_accounts[1].AccountID];

            CompareStopOrders(sps.GetStopOrders(r_accounts[0].AccountID, 0).Result, accountDA.GetStopOrders(l_acc0ID), replBL);
            CompareStopOrders(sps.GetStopOrders(r_accounts[1].AccountID, 0).Result, accountDA.GetStopOrders(l_acc1ID), replBL);
            CompareOrders(sps.GetOrders(r_accounts[0].AccountID, 0).Result, accountDA.GetOrders(l_acc0ID), replBL);
            CompareOrders(sps.GetOrders(r_accounts[1].AccountID, 0).Result, accountDA.GetOrders(l_acc1ID), replBL);
            CompareTrades(sps.GetTrades(r_accounts[0].AccountID, 0).Result, accountDA.GetTrades(l_acc0ID), replBL);
            CompareTrades(sps.GetTrades(r_accounts[1].AccountID, 0).Result, accountDA.GetTrades(l_acc1ID), replBL);

            // еще добавили данных
            var so3  = sps.AddStopOrder(r_accounts[0].AccountID, r_instrums[0].InsID, Platform.BuySell.Sell, Platform.StopOrderType.TakeProfit, 2000, 2);
            var ord3 = sps.AddOrder(so3);
            var trd3 = sps.AddTrade(ord3);
            var ord4 = sps.AddOrder(r_accounts[1].AccountID, r_instrums[1].InsID, Platform.BuySell.Buy, 3000, 3);
            var trd4 = sps.AddTrade(ord4);

            // снова синхронизировали
            import.SyncAccountDataAsync(sps).Wait();

            // и снова сравнили
            CompareStopOrders(sps.GetStopOrders(r_accounts[0].AccountID, 0).Result, accountDA.GetStopOrders(l_acc0ID), replBL);
            CompareStopOrders(sps.GetStopOrders(r_accounts[1].AccountID, 0).Result, accountDA.GetStopOrders(l_acc1ID), replBL);
            CompareOrders(sps.GetOrders(r_accounts[0].AccountID, 0).Result, accountDA.GetOrders(l_acc0ID), replBL);
            CompareOrders(sps.GetOrders(r_accounts[1].AccountID, 0).Result, accountDA.GetOrders(l_acc1ID), replBL);
            CompareTrades(sps.GetTrades(r_accounts[0].AccountID, 0).Result, accountDA.GetTrades(l_acc0ID), replBL);
            CompareTrades(sps.GetTrades(r_accounts[1].AccountID, 0).Result, accountDA.GetTrades(l_acc1ID), replBL);

            // изменили записи
            so3.Status  = StopOrderStatus.Reject;
            ord3.Status = OrderStatus.Reject;

            // снова синхронизировали
            import.SyncAccountDataAsync(sps).Wait();

            // и снова сравнили
            CompareStopOrders(sps.GetStopOrders(r_accounts[0].AccountID, 0).Result, accountDA.GetStopOrders(l_acc0ID), replBL);
            CompareStopOrders(sps.GetStopOrders(r_accounts[1].AccountID, 0).Result, accountDA.GetStopOrders(l_acc1ID), replBL);
            CompareOrders(sps.GetOrders(r_accounts[0].AccountID, 0).Result, accountDA.GetOrders(l_acc0ID), replBL);
            CompareOrders(sps.GetOrders(r_accounts[1].AccountID, 0).Result, accountDA.GetOrders(l_acc1ID), replBL);
            CompareTrades(sps.GetTrades(r_accounts[0].AccountID, 0).Result, accountDA.GetTrades(l_acc0ID), replBL);
            CompareTrades(sps.GetTrades(r_accounts[1].AccountID, 0).Result, accountDA.GetTrades(l_acc1ID), replBL);
        }