public StorageEntityFactory(ISecurityStorage securityStorage) { if (securityStorage == null) throw new ArgumentNullException("securityStorage"); _securityStorage = securityStorage; _securities = _securityStorage.LookupAll().ToDictionary(s => s.Id, s => s, StringComparer.InvariantCultureIgnoreCase); }
/// <summary> /// Initializes a new instance of the <see cref="StorageEntityFactory"/>. /// </summary> /// <param name="entityRegistry">The storage of trade objects.</param> /// <param name="storageRegistry">The storage of market data.</param> public StorageEntityFactory(IEntityRegistry entityRegistry, IStorageRegistry storageRegistry) { if (entityRegistry == null) throw new ArgumentNullException("entityRegistry"); if (storageRegistry == null) throw new ArgumentNullException("storageRegistry"); _entityRegistry = entityRegistry; _storageRegistry = storageRegistry; _securityStorage = storageRegistry.GetSecurityStorage(); _securities = _securityStorage.LookupAll() .ToDictionary(s => s.Id, s => s, StringComparer.InvariantCultureIgnoreCase); }
/// <summary> /// Initializes a new instance of the <see cref="StorageEntityFactory"/>. /// </summary> /// <param name="entityRegistry">The storage of trade objects.</param> /// <param name="storageRegistry">The storage of market data.</param> public StorageEntityFactory(IEntityRegistry entityRegistry, IStorageRegistry storageRegistry) { if (entityRegistry == null) { throw new ArgumentNullException("entityRegistry"); } if (storageRegistry == null) { throw new ArgumentNullException("storageRegistry"); } _entityRegistry = entityRegistry; _storageRegistry = storageRegistry; _securityStorage = storageRegistry.GetSecurityStorage(); _securities = _securityStorage.LookupAll() .ToDictionary(s => s.Id, s => s, StringComparer.InvariantCultureIgnoreCase); }
public void Load() { foreach (var board in _exchangeInfoProvider.Boards) { RaiseNewOutMessage(board.ToMessage()); } foreach (var security in _securityStorage.LookupAll()) { RaiseNewOutMessage(security.ToMessage()); } foreach (var portfolio in _positionStorage.Portfolios) { RaiseNewOutMessage(portfolio.ToMessage()); RaiseNewOutMessage(portfolio.ToChangeMessage()); } foreach (var position in _positionStorage.Positions) { RaiseNewOutMessage(position.ToChangeMessage()); } }
/// <summary> /// Synchronize securities with storage. /// </summary> /// <param name="drives">Storage drives.</param> /// <param name="securityStorage">Securities meta info storage.</param> /// <param name="exchangeInfoProvider">Exchanges and trading boards provider.</param> /// <param name="newSecurity">The handler through which a new instrument will be passed.</param> /// <param name="updateProgress">The handler through which a progress change will be passed.</param> /// <param name="logsReceiver">Logs receiver.</param> /// <param name="isCancelled">The handler which returns an attribute of search cancel.</param> public static void SynchronizeSecurities(this IEnumerable <IMarketDataDrive> drives, ISecurityStorage securityStorage, IExchangeInfoProvider exchangeInfoProvider, Action <Security> newSecurity, Action <int, int> updateProgress, Func <bool> isCancelled, ILogReceiver logsReceiver) { if (drives == null) { throw new ArgumentNullException(nameof(drives)); } if (securityStorage == null) { throw new ArgumentNullException(nameof(securityStorage)); } if (exchangeInfoProvider == null) { throw new ArgumentNullException(nameof(exchangeInfoProvider)); } if (newSecurity == null) { throw new ArgumentNullException(nameof(newSecurity)); } if (updateProgress == null) { throw new ArgumentNullException(nameof(updateProgress)); } if (isCancelled == null) { throw new ArgumentNullException(nameof(isCancelled)); } if (logsReceiver == null) { throw new ArgumentNullException(nameof(logsReceiver)); } var securityPaths = new List <string>(); var progress = 0; foreach (var dir in drives.Select(drive => drive.Path).Distinct()) { foreach (var letterDir in InteropHelper.GetDirectories(dir)) { if (isCancelled()) { break; } var name = Path.GetFileName(letterDir); if (name == null || name.Length != 1) { continue; } securityPaths.AddRange(InteropHelper.GetDirectories(letterDir)); } if (isCancelled()) { break; } } if (isCancelled()) { return; } // кол-во проходов по директории для создания инструмента var iterCount = securityPaths.Count; updateProgress(0, iterCount); var securities = securityStorage.LookupAll().ToDictionary(s => s.Id, s => s, StringComparer.InvariantCultureIgnoreCase); foreach (var securityPath in securityPaths) { if (isCancelled()) { break; } var securityId = Path.GetFileName(securityPath).FolderNameToSecurityId(); var isNew = false; var security = securities.TryGetValue(securityId); if (security == null) { var firstDataFile = Directory.EnumerateDirectories(securityPath) .SelectMany(d => Directory.EnumerateFiles(d, "*.bin") .Concat(Directory.EnumerateFiles(d, "*.csv")) .OrderBy(f => Path.GetExtension(f).CompareIgnoreCase(".bin") ? 0 : 1)) .FirstOrDefault(); if (firstDataFile != null) { var id = securityId.ToSecurityId(); decimal priceStep; if (Path.GetExtension(firstDataFile).CompareIgnoreCase(".bin")) { try { priceStep = File.ReadAllBytes(firstDataFile).Range(6, 16).To <decimal>(); } catch (Exception ex) { throw new InvalidOperationException(LocalizedStrings.Str2929Params.Put(firstDataFile), ex); } } else { priceStep = 0.01m; } security = new Security { Id = securityId, PriceStep = priceStep, Name = id.SecurityCode, Code = id.SecurityCode, Board = exchangeInfoProvider.GetOrCreateBoard(id.BoardCode), }; securities.Add(securityId, security); securityStorage.Save(security, false); newSecurity(security); isNew = true; } } updateProgress(progress++, iterCount); if (isNew) { logsReceiver.AddInfoLog(LocalizedStrings.Str2930Params, security); } } }
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) { Year.ItemsSource = Competition.AllYears; Year.SelectedItem = Competition.AllYears.Last(); var ns = typeof(IIndicator).Namespace; var rendererTypes = typeof(Chart).Assembly .GetTypes() .Where(t => !t.IsAbstract && typeof(BaseChartIndicatorPainter).IsAssignableFrom(t)) .ToDictionary(t => t.Name); var indicators = typeof(IIndicator).Assembly .GetTypes() .Where(t => t.Namespace == ns && !t.IsAbstract && typeof(IIndicator).IsAssignableFrom(t)) .Select(t => new IndicatorType(t, rendererTypes.TryGetValue(t.Name + "Painter"))); Chart.IndicatorTypes.AddRange(indicators); const string finamSecurities = "finam.csv"; if (File.Exists(finamSecurities)) { var idGen = new SecurityIdGenerator(); var securities = File.ReadAllLines(finamSecurities).Select(line => { var cells = line.SplitByComma(); var idParts = idGen.Split(cells[0]); return(new Security { Id = cells[0], Code = idParts.Item1, Board = ExchangeBoard.GetOrCreateBoard(idParts.Item2), ExtensionInfo = new Dictionary <object, object> { { FinamHistorySource.MarketIdField, cells[1].To <long>() }, { FinamHistorySource.SecurityIdField, cells[2].To <long>() }, } }); }); foreach (var security in securities) { _securities.Add(security); _securityStorage.Save(security); } } else { _finamHistorySource.Refresh(_securityStorage, new Security(), s => { }, () => false); var securities = _securityStorage.LookupAll().ToArray(); foreach (var security in securities) { _securities.Add(security); } File.WriteAllLines(finamSecurities, securities.Where(s => !s.Id.Contains(',')).Select(s => "{0},{1},{2}" .Put(s.Id, s.ExtensionInfo[FinamHistorySource.MarketIdField], s.ExtensionInfo[FinamHistorySource.SecurityIdField]))); } Trader.Text = "Bull"; Security.Text = "SIZ4@FORTS"; From.Value = new DateTime(2014, 09, 16); }
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) { Year.ItemsSource = Competition.AllYears; Year.SelectedItem = Competition.AllYears.Last(); Directory.CreateDirectory(_settingsDir); var ns = typeof(IIndicator).Namespace; var rendererTypes = typeof(Chart).Assembly .GetTypes() .Where(t => !t.IsAbstract && typeof(BaseChartIndicatorPainter).IsAssignableFrom(t)) .ToDictionary(t => t.Name); var indicators = typeof(IIndicator).Assembly .GetTypes() .Where(t => t.Namespace == ns && !t.IsAbstract && typeof(IIndicator).IsAssignableFrom(t)) .Select(t => new IndicatorType(t, rendererTypes.TryGetValue(t.Name + "Painter"))); Chart.IndicatorTypes.AddRange(indicators); var finamSecurities = Path.Combine(_settingsDir, "finam2.csv"); BusyIndicator.BusyContent = "Обновление инструментов..."; BusyIndicator.IsBusy = true; Task.Factory.StartNew(() => { File.Delete("finam.csv"); if (File.Exists(finamSecurities)) { CultureInfo.InvariantCulture.DoInCulture(() => { var idGen = new SecurityIdGenerator(); var securities = File.ReadAllLines(finamSecurities).Select(line => { var cells = line.SplitByComma(); var idParts = idGen.Split(cells[0]); return(new Security { Id = cells[0], Code = idParts.Item1, Board = ExchangeBoard.GetOrCreateBoard(idParts.Item2), ExtensionInfo = new Dictionary <object, object> { { FinamHistorySource.MarketIdField, cells[1].To <long>() }, { FinamHistorySource.SecurityIdField, cells[2].To <long>() }, }, PriceStep = cells[3].To <decimal?>(), Decimals = cells[4].To <int?>(), Currency = cells[5].To <CurrencyTypes?>(), }); }); foreach (var security in securities) { _securityProvider.Securities.Add(security); _securityStorage.Save(security); } }); } else { _finamHistorySource.Refresh(_securityStorage, new Security(), s => { }, () => false); var securities = _securityStorage.LookupAll().ToArray(); foreach (var security in securities) { _securityProvider.Securities.Add(security); } File.WriteAllLines(finamSecurities, securities.Where(s => !s.Id.Contains(',')).Select(s => "{0},{1},{2},{3},{4},{5}" .Put(s.Id, s.ExtensionInfo[FinamHistorySource.MarketIdField], s.ExtensionInfo[FinamHistorySource.SecurityIdField], s.PriceStep, s.Decimals, s.Currency))); } }) .ContinueWith(res => { BusyIndicator.IsBusy = false; if (res.Exception != null) { new MessageBoxBuilder() .Error() .Owner(this) .Text(res.Exception.ToString()) .Show(); } if (File.Exists(_settingsFile)) { var settings = CultureInfo.InvariantCulture.DoInCulture(() => new XmlSerializer <SettingsStorage>().Deserialize(_settingsFile).Load <Settings>()); Year.SelectedItem = settings.Year; Trader.Text = settings.Trader; From.Value = settings.From; To.Value = settings.To; Security1.Text = settings.Security1; Security2.Text = settings.Security2; Security3.Text = settings.Security3; Security4.Text = settings.Security4; TimeFrame.SelectedItem = settings.TimeFrame; Apart.IsChecked = settings.Apart; } else { Trader.Text = "Vasya"; Security1.Text = "RIZ5@FORTS"; //Trader.Text = "iZotov"; //Security1.Text = "SPZ5@FORTS"; //Security2.Text = "SIZ5@FORTS"; //From.Value = new DateTime(2014, 09, 16); Apart.IsChecked = true; } }, TaskScheduler.FromCurrentSynchronizationContext()); }