Example #1
0
        public void SetHolding(int accountID, int insID, int lots)
        {
            if (lots == 0)
            {
                return;
            }

            var holds = _da.GetHoldings(accountID);
            var hold  = holds.FirstOrDefault(h => h.InsID == insID);

            if (hold == null && lots != 0)
            {
                Holding h = new Holding();
                h.AccountID = accountID;
                h.InsID     = insID;
                h.LotCount  = lots;
                _da.InsertHolding(h);
            }
            else if (hold != null && lots == 0)
            {
                _da.DeleteHolding(hold.HoldingID);
            }
            else if (hold != null && lots != 0 && hold.LotCount != lots)
            {
                hold.LotCount = lots;
                _da.UpdateHolding(hold);
            }
        }
Example #2
0
        /// <summary>
        /// Синхронизация позиций по бумагам
        /// </summary>
        /// <param name="localAccountID">Локальный AccountID</param>
        /// <param name="remoteAccountID">Удаленный AccountID</param>
        private async Task SyncHoldings(ISyncPipeServer sps, int localAccountID, int remoteAccountID)
        {
            var remHoldings = await sps.GetHoldingList(remoteAccountID);

            if (remHoldings == null)
            {
                return;
            }

            var holdings = _accountDA.GetHoldings(localAccountID);

            foreach (var r_hold in remHoldings)
            {
                if (!_instrum_rid_lid.ContainsKey(r_hold.InsID))
                {
                    continue;
                }

                int l_insID = _instrum_rid_lid[r_hold.InsID];
                var l_hold  = holdings.FirstOrDefault(r => r.InsID == l_insID);
                if (l_hold == null)
                {
                    _accountDA.CreateHolding(localAccountID, l_insID, r_hold.LotCount);
                }
                else if (l_hold.LotCount != r_hold.LotCount)
                {
                    l_hold.LotCount = r_hold.LotCount;
                    _accountDA.UpdateHolding(l_hold);
                }
            }

            foreach (var l_hold in holdings)
            {
                if (!_instrum_rid_lid.ContainsValue(l_hold.InsID))
                {
                    continue;
                }

                var r_insID = _instrum_rid_lid.FirstOrDefault(r => r.Value == l_hold.InsID).Key;
                if (remHoldings.FirstOrDefault(r => r.InsID == r_insID) == null) // в локальной базе есть запись с инструментом, а в удаленной базе нет такого инструмента, значит удаляем
                {
                    _accountDA.DeleteHolding(l_hold.HoldingID);
                }
            }
        }