コード例 #1
0
ファイル: ImportLeech.cs プロジェクト: vlshl/pulxer
        /// <summary>
        /// Синхронизация счетов
        /// </summary>
        private async Task SyncAccounts(ISyncPipeServer sps)
        {
            var remAccounts = await sps.GetAccountList();

            if (remAccounts == null)
            {
                return;
            }

            var accounts = _accountDA.GetAccounts();

            foreach (var racc in remAccounts)
            {
                if (_account_rid_lid.ContainsKey(racc.AccountID))
                {
                    int lid     = _account_rid_lid[racc.AccountID];
                    var account = accounts.FirstOrDefault(r => r.AccountID == lid);
                    if (account != null) // локальный найден
                    {
                        bool isUpdate = false;
                        if (account.AccountType != racc.AccountType)
                        {
                            account.AccountType = racc.AccountType; isUpdate = true;
                        }
                        if (account.Code != racc.Code)
                        {
                            account.Code = racc.Code; isUpdate = true;
                        }
                        if (account.Name != racc.Name)
                        {
                            account.Name = racc.Name; isUpdate = true;
                        }
                        if (account.CommPerc != racc.CommPerc)
                        {
                            account.CommPerc = racc.CommPerc; isUpdate = true;
                        }
                        if (account.IsShortEnable != racc.IsShortEnable)
                        {
                            account.IsShortEnable = racc.IsShortEnable; isUpdate = true;
                        }

                        if (isUpdate)
                        {
                            _accountDA.UpdateAccount(account);
                        }
                    }
                    else // соответствие есть, но локальный не найден, значит соответствие уже не действительно
                    {
                        var acc = _accountDA.CreateAccount(racc.Code, racc.Name, racc.CommPerc, racc.IsShortEnable, racc.AccountType);
                        _account_rid_lid[racc.AccountID] = acc.AccountID; // прописываем новый ключ
                    }
                }
                else // соответствие не найдено
                {
                    var acc = _accountDA.CreateAccount(racc.Code, racc.Name, racc.CommPerc, racc.IsShortEnable, racc.AccountType);
                    _account_rid_lid.Add(racc.AccountID, acc.AccountID);
                }
            }
        }
コード例 #2
0
ファイル: PositionTest.cs プロジェクト: vlshl/pulxer
        public PositionTest()
        {
            DbContextOptionsBuilder <DaContext> builder = new DbContextOptionsBuilder <DaContext>();

            builder.UseNpgsql("Username=postgres;Password=123;Host=localhost;Port=5432;Database=pulxer_test");
            _options = builder.Options;

            _insDA      = new InstrumDA(_options);
            _accountDA  = new AccountDA(_options);
            _positionDA = new PositionDA(_options);

            // создание
            var gazp = _insDA.GetInstrum(0, "GAZP");

            if (gazp == null)
            {
                _gazpID = _insDA.InsertInstrum("GAZP", "Газпром", "Газпром", 10, 2, 1);
            }
            else
            {
                _gazpID = gazp.InsID;
            }

            var lkoh = _insDA.GetInstrum(0, "LKOH");

            if (lkoh == null)
            {
                _lkohID = _insDA.InsertInstrum("LKOH", "Лукойл", "Лукойл", 1, 0, 0);
            }
            else
            {
                _lkohID = lkoh.InsID;
            }

            _accountID = _accountDA.CreateAccount("", "", 0, false, Common.Data.AccountTypes.Test).AccountID;
        }
コード例 #3
0
ファイル: TradeEngineData.cs プロジェクト: vlshl/pulxer
        /// <summary>
        /// Сохранить все данные по торговому счету
        /// </summary>
        public void SaveData()
        {
            if (_account.AccountID <= 0)
            {
                _account        = _accountDA.CreateAccount(_account.Code, _account.Name, _account.CommPerc, _account.IsShortEnable, _account.AccountType);
                _cash.AccountID = _account.AccountID;
                foreach (Holding holding in _holdings)
                {
                    holding.AccountID = _account.AccountID;
                }
                foreach (Order order in _orders)
                {
                    order.AccountID = _account.AccountID;
                }
                foreach (StopOrder stopOrder in _stopOrders)
                {
                    stopOrder.AccountID = _account.AccountID;
                }
                foreach (Trade trade in _trades)
                {
                    trade.AccountID = _account.AccountID;
                }
            }
            else
            {
                _accountDA.UpdateAccount(_account);
            }

            if (_cash.CashID <= 0)
            {
                _cash = _accountDA.CreateCash(_cash.AccountID, _cash.Initial, _cash.Current, _cash.Sell, _cash.Buy, _cash.SellComm, _cash.BuyComm);
            }
            else
            {
                _accountDA.UpdateCash(_cash);
            }

            foreach (var holding in _holdings)
            {
                if (holding.HoldingID <= 0)
                {
                    _accountDA.CreateHolding(holding.AccountID, holding.InsID, holding.LotCount);
                }
                else
                {
                    _accountDA.UpdateHolding(holding); // holdings всегда обновляем, так проще
                }
            }

            var createStopOrders = _stopOrders.Where(r => r.StopOrderID <= 0).ToList();

            _stopOrders.RemoveAll(r => r.StopOrderID <= 0);
            foreach (var so in _stopOrders)
            {
                if (_modifiedStopOrders.Contains(so))
                {
                    _accountDA.UpdateStopOrder(so);
                }
            }
            _modifiedStopOrders.Clear();
            foreach (var so in createStopOrders)
            {
                var newSo = _accountDA.CreateStopOrder(so.AccountID, so.Time, so.InsID, so.BuySell, so.StopType, so.EndTime,
                                                       so.AlertPrice, so.Price, so.LotCount, so.Status, so.CompleteTime, so.StopOrderNo);
                _stopOrders.Add(newSo);
                var orders = _orders.Where(r => r.StopOrderID == so.StopOrderID).ToList();
                foreach (var ord in orders)
                {
                    ord.StopOrderID = newSo.StopOrderID;
                    if (ord.OrderID > 0)
                    {
                        MarkAsModified(ord);
                    }
                }
            }

            var createOrders = _orders.Where(r => r.OrderID <= 0).ToList();

            _orders.RemoveAll(r => r.OrderID <= 0);
            foreach (var order in _orders)
            {
                if (_modifiedOrders.Contains(order))
                {
                    _accountDA.UpdateOrder(order);
                }
            }
            _modifiedOrders.Clear();
            foreach (var ord in createOrders)
            {
                var newOrd = _accountDA.CreateOrder(ord.AccountID, ord.Time, ord.InsID, ord.BuySell, ord.LotCount, ord.Price,
                                                    ord.Status, ord.StopOrderID, ord.OrderNo);
                _orders.Add(newOrd);
                var trades = _trades.Where(r => r.OrderID == ord.OrderID).ToList();
                foreach (var trd in trades)
                {
                    trd.OrderID = newOrd.OrderID;
                }
            }

            var newTrades = _trades.Where(r => r.TradeID <= 0).ToList();

            _trades.RemoveAll(r => r.TradeID <= 0);
            foreach (var nt in newTrades)
            {
                var t = _accountDA.CreateTrade(nt.AccountID, nt.OrderID, nt.Time, nt.InsID, nt.BuySell, nt.LotCount, nt.Price,
                                               nt.Comm, nt.TradeNo);
                _trades.Add(t);
            }
        }
コード例 #4
0
 /// <summary>
 /// Создать новый торговый счет
 /// </summary>
 /// <param name="code">Код счета</param>
 /// <param name="name">Наименование счета</param>
 /// <param name="commPerc">Процент комиссии по операциям</param>
 /// <param name="isShortEnable">Разрешены ли короткие позиции</param>
 /// <returns></returns>
 public Account CreateTestAccount(string code, string name, decimal commPerc, bool isShortEnable)
 {
     return(_accountDA.CreateAccount(code, name, commPerc, isShortEnable, AccountTypes.Test));
 }