private bool SafeDownload(string path) { bool result = false; try { Log("Downloading quotes..."); using (DataFeedImpl impl = DataFeedImpl.Create()) { DataFeed feed = impl.Instance; using (DataFeedStorage storage = new DataFeedStorage(path, StorageProvider.Ntfs, 1, feed, false)) { HistoryInfo info = storage.Online.GetQuotesInfo(m_symbol, 0); string availbaleFrom = info.AvailableFrom.ToString(cDateTimeFormat); string availableTo = info.AvailableTo.ToString(cDateTimeFormat); Log("Quotes history available from = {0} to = {1}", availbaleFrom, availableTo); DateTime startTime = m_timestamp.AddSeconds(-m_duration); Log("Start time = {0}", startTime.ToString(cDateTimeFormat)); DateTime endTime = m_timestamp; Log("End time = {0}", endTime.ToString(cDateTimeFormat)); this.Quotes = storage.Online.GetQuotes(m_symbol, startTime, endTime, 0); } } Log("{0} quotes have been loaded", this.Quotes.Length); result = this.Quotes.Length > 0; } catch (Exception ex) { Log(ex.Message); } return(result); }
/// <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 SymbolBarsDataSource(DataFeed dataFeed, DataFeedStorage storage, string symbol, PriceType priceType) { this.dataFeed = dataFeed; this.storage = storage; this.symbol = symbol; this.priceType = priceType; this.Name = symbol + (priceType == PriceType.Ask ? " (ASK)" : " (BID)"); }
void ThreadMethod() { try { var from = this.from; var to = this.to; this.AdjustTimes(ref from, ref to); Directory.CreateDirectory(this.location); var retries = 0; using (var storage = new DataFeedStorage(this.location, this.storageType, this.dataFeed, true)) { for (var current = from; this.continueMonitoring && (current < to);) { if (retries == 0) { this.Log("Synchronizing = {0}", current); } else { this.Log("Synchronizing = {0}; retries = {1}", current, retries); } var next = this.Download(storage, current); if (current == next) { if (retries == this.retries) { break; } retries++; } else { retries = 0; current = next; this.Log("Synchronized"); } } this.Log("Flushing quotes storage"); } this.Log("Quotes storage has been flushed"); } catch (Exception ex) { this.Log(ex.Message); } this.RaiseFinish(); this.thread = null; }
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; } }
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 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(); }
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); } }
protected override void OnUpdate(SingleAdviser <int> adviser) { lock (obj) { foreach (string currSymbol in listSymbols) { Level2 level2 = adviser.GetLevel2(currSymbol); if (!level2.Exist || level2.HasBeenChanged) { continue; } LastTask = LastTask.ContinueWith(ant => { DataFeedStorage dfs = dictKeyToStorage[GetKey(adviser.Tag, currSymbol)]; dfs.Import(level2.ToQuote().ToEnumerable(), false, true, true); } ); //listCodeToBankSaver[adviser.Tag].AddQuote(level2); } } }
DateTime Download(DataFeedStorage storage, DateTime time) { try { var result = time + Interval; if (this.period == null) { var marketDepth = includeLevel2 ? 0 : 1; storage.Synchronize(this.symbol, time, result, marketDepth); } else { storage.Synchronize(this.symbol, this.priceType, this.period, time, result); } return(result); } catch (Exception ex) { this.Log("Exception = {0}", ex.Message); Thread.Sleep(1000); return(time); } }
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"); } }
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); } }