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); } }
/// <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); } } }
/// <summary> /// Загрузить все данные по торговому счету /// </summary> /// <param name="accountID">Торговый счет</param> public void LoadData(int accountID) { _account = _accountDA.GetAccountByID(accountID); if (_account == null) { throw new ApplicationException("Счет не найден."); } _cash = _accountDA.GetCash(accountID); if (_cash == null) { _cash = new Cash(); _cash.AccountID = accountID; } _holdings = _accountDA.GetHoldings(accountID).ToList(); _orders = _accountDA.GetOrders(accountID).ToList(); _stopOrders = _accountDA.GetStopOrders(accountID).ToList(); _trades = _accountDA.GetTrades(accountID).ToList(); }
/// <summary> /// Получить список владения бумагами для торгового счета /// </summary> /// <param name="accountID">Торговый счет</param> /// <returns>Список владения бумагами</returns> public IEnumerable <CommonData.Holding> GetHoldings(int accountID) { return(_accountDA.GetHoldings(accountID)); }