void ThreadMethod() { var status = true; string message = null; try { using (var storage = new DataFeedStorage(m_storageLocation, StorageProvider.Ntfs, null, false)) { using (var writer = new StreamWriter(m_outputFile)) { if (m_period != null) { this.ExportBars(writer, storage); } else { this.ExportTicks(writer, storage); } } } } catch (Exception ex) { status = false; message = ex.ToString(); } var func = this.Finish; if (func != null) { var e = new FinishEventArgs(status, message); func(this, e); } }
/// <summary> /// The constructor takes snapshot from manager. /// </summary> /// <param name="snapshot">a snapshot instance</param> /// <param name="storage"></param> /// <param name="symbol"></param> /// <param name="periodicity"></param> /// <param name="priceType"></param> /// <exception cref="System.ArgumentNullException">if snapshot is null</exception> public Snapshot(Snapshot snapshot, DataFeedStorage storage, string symbol, BarPeriod periodicity, PriceType priceType) { if (snapshot == null) throw new ArgumentNullException(nameof(snapshot)); if (storage == null) throw new ArgumentNullException(nameof(storage)); this.IsFeedLoggedOn = snapshot.IsFeedLoggedOn; this.IsTradeLoggedOn = snapshot.IsTradeLoggedOn; this.AccountInfo = snapshot.AccountInfo; this.FeedSessionInfo = snapshot.FeedSessionInfo; this.TradeSessionInfo = snapshot.TradeSessionInfo; this.TradeRecords = snapshot.TradeRecords; this.Positions = snapshot.Positions; this.Quotes = snapshot.Quotes; this.Symbols = snapshot.Symbols; this.storage = storage; this.symbol = symbol; this.periodicity = periodicity; this.priceType = priceType; this.synchronizer = snapshot.synchronizer; }
public SmartStorage(DataFeedStorage storage, IHistorySource source = null) { if (storage == null) throw new ArgumentNullException(nameof(storage)); this.storage = storage; this.source = source; }
public SmartStorage(DataFeedStorage storage, IHistorySource source = null) { if (storage == null) { throw new ArgumentNullException(nameof(storage)); } this.storage = storage; this.source = source; }
public StorageDataSourceProvider() { this.dataFeed = CreateDataFeed(); this.storage = new DataFeedStorage(Settings.Default.DataSources_FDK_StorageLocation, StorageProvider.Ntfs, this.dataFeed, flushOnDispose: true); this.dataFeed.Start(); var symbols = this.GetSymbols(); var sources = symbols.Select(o => { return new [] { new SymbolBarsDataSource(this.dataFeed, this.storage, o, PriceType.Bid), new SymbolBarsDataSource(this.dataFeed, this.storage, o, PriceType.Ask) }; }); this.DataSources = sources.SelectMany(o => o) .ToArray(); }
HistoryManagerAdapter GetOrCreateHistoryManagerAdapter(string symbol) { HistoryManagerAdapter result; lock (this.synchronizer) { if (!this.symbol2cache.TryGetValue(symbol, out result)) { var symbols = new HashSet <ISymbolProperties> { new SymbolProperties(symbol) }; var storageVersion = this.storageVersion; if (this.historyFeed != null) { storageVersion = this.historyFeed.Server.GetQuotesHistoryVersion(); } var provider = HistoryManager.Create( storageVersion, this.store, symbols, DataFeedStorage.GetSupportedPeriodicityToStoreLevel(this.storageVersion), this.saveTickLevel2History, Cache.ClientInstance(Guid.NewGuid().ToString()), true, this.flushOnDispose, NullMonitoringService, NullMonitoringItem); result = new HistoryManagerAdapter(provider); this.symbol2cache[symbol] = result; } } return(result); }
/// <summary> /// /// </summary> /// <param name="symbol"></param> /// <param name="from"></param> /// <param name="to"></param> public void RebuildBarsFromBars(string symbol, string from, string to) { var start = DateTime.MinValue.AddYears(1); var finish = DateTime.MaxValue.AddYears(-1); try { var periodicities = new[] { Periodicity.Parse(from), Periodicity.Parse(to), }; var writer = BulkHistoryWriter.Create(this.store, DataFeedStorage.GetSupportedPeriodicityToStoreLevel(this.storageVersion), NullMonitoringService); writer.RebuildBarsFromBars(symbol, FxPriceType.Bid, start, finish, periodicities); writer.RebuildBarsFromBars(symbol, FxPriceType.Ask, start, finish, periodicities); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
void ExportTicks(StreamWriter writer, DataFeedStorage storage) { writer.WriteLine("Time,Ask,Bid,AskVolume,BidVolume"); var quotes = new QuotesSingleSequence(storage.Offline, m_symbol, m_from, m_to, 1); var previousBidPrice = double.NaN; var previousAskPrice = double.NaN; foreach (var element in quotes) { if (!continueMonitoring) { break; } var bid = element.Bids[0]; var ask = element.Asks[0]; if (this.m_removeDuplicateEntries) { if (previousBidPrice == bid.Price && previousAskPrice == ask.Price) { continue; } previousBidPrice = bid.Price; previousAskPrice = ask.Price; } var dateTime = element.CreatingTime.ToString("yyyy.MM.dd HH:mm:ss.fff"); var bidPrice = bid.Price.ToString(CultureInfo.InvariantCulture); var askPrice = ask.Price.ToString(CultureInfo.InvariantCulture); var bidVolume = (bid.Volume / m_contractSize).ToString(CultureInfo.InvariantCulture); var askVolume = (ask.Volume / m_contractSize).ToString(CultureInfo.InvariantCulture); writer.WriteLine("{0},{1},{2},{3},{4}", dateTime, askPrice, bidPrice, askVolume, bidVolume); this.RaiseProgress(element.CreatingTime); } }
static void Main(string[] args) { if (args.Length == 4) { var location = args[0]; var symbol = args[1]; var source = args[2]; var target = args[3]; using (var storage = new DataFeedStorage(location, StorageProvider.Ntfs, null, true)) { storage.RebuildBarsFromBars(symbol, source, target); } } else { Console.WriteLine("Usage:"); Console.WriteLine("\tFeedRebuilder <location> <symbol> <source periodicity> <target periodicity>"); Console.WriteLine("List of supported periodicities:"); Console.WriteLine("\tS1 S10 M1 M5 M15 M30 H1 H4 D1 W1 MN1"); Console.WriteLine("Example:"); Console.WriteLine("\tFeedRebuilder C:\\Storage EURUSD M15 M30"); } }
public void SetupPathsAndConnect(string rootPath) { if (Initialized) { throw new InvalidOperationException("Fdk seems to be initialized for second time"); } Initialized = true; // create and specify log directory string root; if (string.IsNullOrEmpty(rootPath)) { var assembly = Assembly.GetEntryAssembly(); root = assembly == null ? Directory.GetCurrentDirectory() : assembly.Location; root = Path.GetDirectoryName(root); if (root == null) throw new InvalidDataException("FDK assembly's directory seems to be invalid"); } else { root = rootPath; } var logsPath = Path.Combine(root, "Logs\\Fix"); Directory.CreateDirectory(logsPath); Builder.FixLogDirectory = logsPath; Feed = new DataFeed(Builder.ToString()) { SynchOperationTimeout = 18000 }; var storagePath = Path.Combine(root, "Storage"); Directory.CreateDirectory(storagePath); Storage = new DataFeedStorage(storagePath, StorageProvider.Ntfs, Feed, true); }
public Dictionary <Periodicity, TimeInterval> GetSupportedBarPeriodicities(string symbol) { return(DataFeedStorage.GetSupportedPeriodicityToStoreLevel(this.dataFeed.Server.GetQuotesHistoryVersion())); }
void ExportBars(StreamWriter writer, DataFeedStorage storage) { writer.WriteLine("Time,Open,High,Low,Close,Volume"); var bars = new Bars(storage.Offline, m_symbol, PriceType.Bid, m_period, m_from, m_to); foreach (var element in bars) { if (!continueMonitoring) { break; } var dateTime = element.From.ToString("yyyy.MM.dd HH:mm:ss.fff"); var stOpen = element.Open.ToString(CultureInfo.InvariantCulture); var stHigh = element.High.ToString(CultureInfo.InvariantCulture); var stLow = element.Low.ToString(CultureInfo.InvariantCulture); var stClose = element.Close.ToString(CultureInfo.InvariantCulture); var stVolume = element.Volume.ToString(CultureInfo.InvariantCulture); writer.WriteLine("{0},{1},{2},{3},{4},{5}", dateTime, stOpen, stHigh, stLow, stClose, stVolume); this.RaiseProgress(element.From); } }
public void Dispose() { if (this.Feed != null) { this.Feed.Stop(); this.Feed.Dispose(); this.Feed = null; } if (this.Storage != null) { this.Storage.Dispose(); this.Storage = null; } }