public static bool TradingOpen(DateTime time, string assetName) { var startTime = Config.ParseDateTimeLocal(_settings["TRADING_START_TIME"]); var endTime = Config.Settings.ContainsKey("TRADING_CLOSING_TIME") ? Config.ParseDateTimeLocal(_settings["TRADING_CLOSING_TIME"]) : Config.ParseDateTimeLocal(_settings["TRADING_STOP_TIME"]); if (time.DayOfWeek == DayOfWeek.Monday) { var today9am = new DateTime(endTime.Year, endTime.Month, endTime.Day, 9, 0, 0); if (startTime < today9am) { startTime = today9am; } } if (assetName == "DAX" || assetName == "DOW" || assetName == "CAC" || assetName == "FTSE") { var today6pm = new DateTime(endTime.Year, endTime.Month, endTime.Day, 18, 0, 0); if (endTime > today6pm) { endTime = today6pm; } } bool open = (time.TimeOfDay >= startTime.TimeOfDay && time.TimeOfDay < endTime.TimeOfDay && time.DayOfWeek != DayOfWeek.Saturday && time.DayOfWeek != DayOfWeek.Sunday); return(open); }
// Whole day average public IndicatorLevelMean(MarketData mktData) : base("WMA_1D_" + mktData.Id, mktData, 0) { TimeSpan timeDiff = (Config.ParseDateTimeLocal(Config.Settings["PUBLISHING_STOP_TIME"]) - Config.ParseDateTimeLocal(Config.Settings["PUBLISHING_START_TIME"])); _subPeriodSeconds = (timeDiff.Hours * 60 + timeDiff.Minutes) * 60 + timeDiff.Seconds; }
MarketLevels?GetMarketLevels(DateTime updateTime, string mktdataid) { if (_session == null) { throw new ApplicationException(EXCEPTION_CONNECTION_CLOSED); } // process previous day if (updateTime.DayOfWeek == DayOfWeek.Monday) { updateTime = updateTime.AddDays(-3); } else { updateTime = updateTime.AddDays(-1); } var stopTime = Config.ParseDateTimeLocal(Config.Settings["PUBLISHING_STOP_TIME"]); updateTime = new DateTime(updateTime.Year, updateTime.Month, updateTime.Day, stopTime.Hour, stopTime.Minute, stopTime.Second, DateTimeKind.Local); RowSet value = null; decimal high = 0m; decimal low = 0m; decimal closeBid = 0m; decimal closeOffer = 0m; string indicator = ""; try { indicator = "High_" + mktdataid; value = executeQuery(string.Format("select value from historicaldata.{0}indicators where indicatorid='{1}' and trading_time={2}", Config.UATSourceDB ? "dummy" : "", indicator, ToUnixTimestamp(updateTime))); high = (decimal)value.First()[0]; indicator = "Low_" + mktdataid; value = executeQuery(string.Format("select value from historicaldata.{0}indicators where indicatorid='{1}' and trading_time={2}", Config.UATSourceDB ? "dummy" : "", indicator, ToUnixTimestamp(updateTime))); low = (decimal)value.First()[0]; indicator = "CloseBid_" + mktdataid; value = executeQuery(string.Format("select value from historicaldata.{0}indicators where indicatorid='{1}' and trading_time={2}", Config.UATSourceDB ? "dummy" : "", indicator, ToUnixTimestamp(updateTime))); closeBid = (decimal)value.First()[0]; indicator = "CloseOffer_" + mktdataid; value = executeQuery(string.Format("select value from historicaldata.{0}indicators where indicatorid='{1}' and trading_time={2}", Config.UATSourceDB ? "dummy" : "", indicator, ToUnixTimestamp(updateTime))); closeOffer = (decimal)value.First()[0]; } catch (Exception exc) { var errorMsg = "Could not retrieve level indicators for previous COB date. Indicator: " + indicator + ". " + exc.ToString(); Log.Instance.WriteEntry(errorMsg, EventLogEntryType.Warning); return(null); } return(new MarketLevels(mktdataid, low, high, closeBid, closeOffer)); }
public override void Subscribe(Tick updateHandler, Tick tickerHandler) { _allPositionsClosed = false; _closePositionTime = Config.ParseDateTimeLocal(Config.Settings["TRADING_STOP_TIME"]); Clear(); bool subscribe = (this._updateHandlers.Count == 0); _updateHandlers.Add(updateHandler); if (tickerHandler != null) { _tickHandlers.Add(tickerHandler); } }
public void Init(getNow getNow) { Assembly thisAssem = typeof(Trader).Assembly; AssemblyName thisAssemName = thisAssem.GetName(); Version ver = thisAssemName.Version; _getNow = getNow; DateTime now = getNow(); Log.Instance.WriteEntry("Midax " + ver + " service initialized", EventLogEntryType.Information); var timerStart = new System.Threading.Timer(startSignalCallback); var timerStop = new System.Threading.Timer(stopSignalCallback); // Figure how much time until PUBLISHING_STOP_TIME _startTime = Config.ParseDateTimeLocal(Config.Settings["PUBLISHING_START_TIME"]); DateTime stopTime = Config.ParseDateTimeLocal(Config.Settings["PUBLISHING_STOP_TIME"]); DateTime closePositionTime = Config.ParseDateTimeLocal(Config.Settings["TRADING_STOP_TIME"]); if (!Config.Settings.ContainsKey("TRADING_CLOSING_TIME")) { _disconnectClosePositions = false; } // If it's already past PUBLISHING_STOP_TIME, wait until PUBLISHING_STOP_TIME tomorrow int msUntilStartTime = 10; if (now > _startTime) { if (now > stopTime) { var nextDay = _startTime.AddDays(1.0); stopTime = stopTime.AddDays(1.0); msUntilStartTime = (int)((nextDay - now).TotalMilliseconds); } } else { msUntilStartTime = (int)((_startTime - now).TotalMilliseconds); } int msUntilStopTime = (int)((stopTime - now).TotalMilliseconds); Log.Instance.WriteEntry(string.Format("Next scheduling in {0}h{1}mn", msUntilStartTime / (3600 * 1000), (msUntilStartTime - 3600 * 1000 * (msUntilStartTime / (3600 * 1000))) / (60 * 1000)), EventLogEntryType.Information); // Set the timers to elapse only once, at their respective scheduled times timerStart.Change(msUntilStartTime, Timeout.Infinite); timerStop.Change(msUntilStopTime, Timeout.Infinite); }
public virtual void Unsubscribe(Tick updateHandler, Tick tickerHandler) { _updateHandlers.Remove(updateHandler); if (tickerHandler != null) { _updateHandlers.Remove(tickerHandler); } if (this._updateHandlers.Count == 0) { MarketDataConnection.Instance.UnsubscribeMarketData(this); if (!_allPositionsClosed && _eodClosePositions) { Portfolio.Instance.CloseAllPositions(Config.ParseDateTimeLocal(Config.Settings["PUBLISHING_STOP_TIME"])); _allPositionsClosed = true; } } }
public virtual void Subscribe(Tick updateHandler, Tick tickerHandler) { _lastUpdateTime = DateTime.MinValue; _allPositionsClosed = false; _closePositionTime = Config.ParseDateTimeLocal(Config.Settings["TRADING_STOP_TIME"]); if (!Config.Settings.ContainsKey("TRADING_CLOSING_TIME")) { _eodClosePositions = false; } if (updateHandler != null) { _updateHandlers.Add(updateHandler); } if (tickerHandler != null) { _tickHandlers.Add(tickerHandler); } MarketDataConnection.Instance.SubscribeMarketData(this); }
public static bool PublishingOpen(DateTime time) { if (ReplayEnabled || MarketSelectorEnabled) { return(true); } if ((time - DateTime.Now).TotalHours > 2) { Log.Instance.WriteEntry("Skipped bad update: " + time, EventLogEntryType.Warning); return(false); } bool open = (time.TimeOfDay >= Config.ParseDateTimeLocal(_settings["PUBLISHING_START_TIME"]).TimeOfDay&& time.TimeOfDay < Config.ParseDateTimeLocal(_settings["PUBLISHING_STOP_TIME"]).TimeOfDay); if (open != _publishingOpen) { _publishingOpen = open; Log.Instance.WriteEntry("Publishing " + (_publishingOpen ? "started" : "stopped"), EventLogEntryType.Information); } return(open); }
public void StopSignals(bool stopListening = true) { try { //Thread.Sleep(1000); Log.Instance.WriteEntry("Publishing indicator levels...", EventLogEntryType.Information); foreach (var indicator in _mktEODIndicators) { indicator.Publish(Config.ParseDateTimeLocal(Config.Settings["PUBLISHING_STOP_TIME"])); } //MarketDataConnection.Instance.PublishMarketLevels(_mktData); //List<MarketData> eodLevelMktData = (from mktdata in _mktIndices where mktdata.HasEODLevels select mktdata).ToList(); //MarketDataConnection.Instance.PublishMarketLevels(eodLevelMktData); } finally { if (stopListening) { MarketDataConnection.Instance.StopListening(); } foreach (Signal sig in (from s in _mktSignals select s).Reverse()) { sig.Unsubscribe(); } foreach (Indicator ind in (from i in _mktIndicators select i).Reverse()) { ind.Unsubscribe(OnUpdateIndicator, null); ind.Clear(); } foreach (MarketData idx in (from i in _mktIndices select i).Reverse()) { idx.Unsubscribe(OnUpdateMktData, null); idx.Clear(); } foreach (MarketData stock in (from s in _mktData select s).Reverse()) { stock.Clear(); } } }
public virtual void Init() { if (Config.Settings.ContainsKey("TRADING_CLOSING_TIME")) { _closingTime = Config.ParseDateTimeLocal(Config.Settings["TRADING_CLOSING_TIME"]); } if (Config.Settings.ContainsKey("TRADING_SIGNAL")) { _tradingSignals = Config.Settings["TRADING_SIGNAL"].Split(',').ToList(); } if (Config.Settings.ContainsKey("REPLAY_POPUP")) { _replayPopup = Config.Settings["REPLAY_POPUP"] == "1"; } _amount = Config.MarketSelectorEnabled ? 0 : int.Parse(Config.Settings["TRADING_LIMIT_PER_BP"]); if (_mktData[0].Name == "SIL") { _amount *= 3; } else if (_mktData[0].Name == "FTSE") { _amount = (int)(_amount * 1.5); } }
public override void Subscribe(string[] epics, IHandyTableListener tableListener) { Dictionary <string, List <CqlQuote> > priceData = GetReplayData(epics); foreach (var epic in epics) { // for each quote, associate the observed gains in the near future var mktData = new MarketData(epic); var wmaLow = new IndicatorWMA(mktData, 10); var wmaMid = new IndicatorWMA(mktData, 30); var wmaHigh = new IndicatorWMA(mktData, 90); var wmaDailyAvg = new IndicatorLevelMean(mktData); foreach (var quote in priceData[epic]) { mktData.TimeSeries.Add(quote.t, new Price(quote.MidPrice())); } foreach (var quote in ExpectedIndicatorData[wmaLow.Id]) { wmaLow.TimeSeries.Add(quote.t, new Price(quote.ScaleValue(0, 1))); } foreach (var quote in ExpectedIndicatorData[wmaLow.Id]) { wmaLow.TimeSeries.Add(quote.t, new Price(quote.ScaleValue(0, 1))); } var expectations = new Dictionary <DateTime, KeyValuePair <CqlQuote, decimal> >(); var gainDistribution = new SortedList <int, DateTime>(); KeyValuePair <int, DateTime> minProfit = new KeyValuePair <int, DateTime>(1000000, DateTime.MinValue); KeyValuePair <int, DateTime> maxProfit = new KeyValuePair <int, DateTime>(-1000000, DateTime.MinValue); var rnd = new Random(155); var openPrice = priceData[epic][0]; foreach (var quote in priceData[epic]) { if (quote.t.TimeOfDay < Config.ParseDateTimeLocal(Config.Settings["TRADING_START_TIME"]).TimeOfDay) { continue; } var futureVal = wmaLow.Average(quote.t.AddMinutes(2)); var profit = (int)Math.Round(futureVal.Mid() - quote.MidPrice()); expectations.Add(quote.t, new KeyValuePair <CqlQuote, decimal>(quote, profit)); if (gainDistribution.ContainsKey(profit)) { if ((quote.t - gainDistribution[profit]).Hours > 3 && (rnd.Next(100) == 0)) { gainDistribution[profit] = quote.t; } } else { gainDistribution[profit] = quote.t; } if (profit < minProfit.Key) { minProfit = new KeyValuePair <int, DateTime>(profit, gainDistribution[profit]); } if (profit > maxProfit.Key) { maxProfit = new KeyValuePair <int, DateTime>(profit, gainDistribution[profit]); } quote.b -= openPrice.MidPrice(); quote.o -= openPrice.MidPrice(); } int nbPoints = 10; int idxProfit = 0; KeyValuePair <int, DateTime> nextProfit = minProfit; var selection = new SortedList <DateTime, KeyValuePair <int, CqlQuote> >(); while (idxProfit++ < nbPoints) { PublisherConnection.Instance.Insert(nextProfit.Value, epic, new Value(nextProfit.Key)); selection.Add(nextProfit.Value, new KeyValuePair <int, CqlQuote>(nextProfit.Key, expectations[nextProfit.Value].Key)); nextProfit = gainDistribution.First(keyVal => keyVal.Key >= ((decimal)minProfit.Key + (decimal)idxProfit * (decimal)(maxProfit.Key - minProfit.Key) / (decimal)nbPoints)); } foreach (var profit in selection) { PublisherConnection.Instance.Insert(gainDistribution[profit.Value.Key], wmaLow, wmaLow.Average(gainDistribution[profit.Value.Key]).Mid() - openPrice.MidPrice()); PublisherConnection.Instance.Insert(gainDistribution[profit.Value.Key], wmaMid, wmaMid.Average(gainDistribution[profit.Value.Key]).Mid() - openPrice.MidPrice()); PublisherConnection.Instance.Insert(gainDistribution[profit.Value.Key], wmaHigh, wmaHigh.Average(gainDistribution[profit.Value.Key]).Mid() - openPrice.MidPrice()); PublisherConnection.Instance.Insert(gainDistribution[profit.Value.Key], wmaDailyAvg, wmaDailyAvg.Average().Mid() - openPrice.MidPrice()); } priceData[epic] = selection.Values.Select(keyVal => keyVal.Value).ToList(); } replay(priceData, tableListener); }
public SignalANNFX_6_2(MarketData asset, List <Indicator> indicators, List <decimal> weights) : base(asset, "FX_6_2", 1, indicators, weights) { _tradingStart = Config.ParseDateTimeLocal(Config.Settings["TRADING_START_TIME"]); }
public override void Subscribe(string[] epics, IHandyTableListener tableListener) { Dictionary <string, List <CqlQuote> > priceData = GetReplayData(epics); if (priceData.Count == 0) { return; } Calendar dayCalendar = new Calendar(priceData.First().Value[0].t); foreach (var epic in epics) { // for each quote, associate the observed gains in the near future var mktData = new MarketData(epic); var wmaLow = new IndicatorEMA(mktData, 2); var wmaMid = new IndicatorEMA(mktData, 10); var wmaHigh = new IndicatorEMA(mktData, 30); var wmaVeryHigh = new IndicatorEMA(mktData, 90); var rsiShort = new IndicatorRSI(mktData, 1, 14); var rsiLong = new IndicatorRSI(mktData, 2, 14); var trendShort = new IndicatorTrend(mktData, 90, 14, false); var trendLong = new IndicatorTrend(mktData, 180, 14, false); var wmvolLow = new IndicatorWMVol(mktData, wmaLow, 60, 90); var wmvolHigh = new IndicatorWMVol(mktData, wmaMid, 60, 90); var volTrendLow = new IndicatorTrend(wmvolLow, 30, 6, true); var volTrendHigh = new IndicatorTrend(wmvolHigh, 60, 6, true); var allIndicators = new List <IndicatorWMA>(); allIndicators.Add(wmaLow); allIndicators.Add(wmaMid); allIndicators.Add(wmaHigh); allIndicators.Add(wmaVeryHigh); allIndicators.Add(rsiShort); allIndicators.Add(rsiLong); allIndicators.Add(trendShort); allIndicators.Add(trendLong); allIndicators.Add(wmvolLow); allIndicators.Add(wmvolHigh); allIndicators.Add(volTrendLow); allIndicators.Add(volTrendHigh); foreach (var quote in priceData[epic]) { var mktDataValue = new Price(quote.MidPrice()); mktData.Process(quote.t, mktDataValue); foreach (var ind in allIndicators) { ind.Process(quote.t, mktDataValue); } } var expectations = new Dictionary <DateTime, KeyValuePair <CqlQuote, decimal> >(); var gainDistribution = new SortedList <int, DateTime>(); KeyValuePair <int, DateTime> minProfit = new KeyValuePair <int, DateTime>(1000000, DateTime.MinValue); KeyValuePair <int, DateTime> maxProfit = new KeyValuePair <int, DateTime>(-1000000, DateTime.MinValue); var rnd = new Random(155); var tradingStart = Config.ParseDateTimeLocal(Config.Settings["TRADING_START_TIME"]); var tradingStop = Config.ParseDateTimeLocal(Config.Settings["TRADING_STOP_TIME"]); var wmaVeryHighStart = wmaVeryHigh.Average(tradingStart); var amplitude = 100.0m; foreach (var quote in priceData[epic]) { if (quote.t.TimeOfDay < tradingStart.TimeOfDay || quote.t.TimeOfDay > tradingStop.TimeOfDay) { continue; } string evtName = ""; if (dayCalendar.IsNearEvent(mktData.Name, quote.t, ref evtName)) { continue; } var futureVal = (mktData.TimeSeries.Max(quote.t.AddMinutes(5), quote.t.AddMinutes(20)) + mktData.TimeSeries.Min(quote.t.AddMinutes(5), quote.t.AddMinutes(20))) / 2m; var profit = (int)Math.Round(futureVal - quote.MidPrice()); expectations.Add(quote.t, new KeyValuePair <CqlQuote, decimal>(quote, profit)); if (gainDistribution.ContainsKey(profit)) { if ((quote.t - gainDistribution[profit]).Hours > 3 && (rnd.Next(100) == 0)) { gainDistribution[profit] = quote.t; } } else { gainDistribution[profit] = quote.t; } if (profit < minProfit.Key) { minProfit = new KeyValuePair <int, DateTime>(profit, gainDistribution[profit]); } if (profit > maxProfit.Key) { maxProfit = new KeyValuePair <int, DateTime>(profit, gainDistribution[profit]); } quote.b = (quote.b - wmaVeryHighStart.Bid) / amplitude; quote.o = (quote.o - wmaVeryHighStart.Offer) / amplitude; } gainDistribution = new SortedList <int, DateTime>((from elt in gainDistribution where !isTooClose(elt, gainDistribution) select elt).ToDictionary(keyVal => keyVal.Key, keyVal => keyVal.Value)); int nbPoints = 10; int idxProfit = 0; KeyValuePair <int, DateTime> nextProfit = minProfit; var selection = new SortedList <DateTime, KeyValuePair <int, CqlQuote> >(); while (idxProfit++ < nbPoints) { selection.Add(gainDistribution[nextProfit.Key], new KeyValuePair <int, CqlQuote>(nextProfit.Key, expectations[gainDistribution[nextProfit.Key]].Key)); var nextKeyVal = gainDistribution.FirstOrDefault(keyVal => keyVal.Key > nextProfit.Key && keyVal.Key >= ((decimal)minProfit.Key + (decimal)idxProfit * (decimal)(maxProfit.Key - minProfit.Key) / (decimal)nbPoints)); if (nextKeyVal.Equals(default(KeyValuePair <int, DateTime>))) { break; } nextProfit = nextKeyVal; } foreach (var dt in selection.Keys) { bool allValid = true; foreach (var ind in allIndicators) { if (ind.TimeSeries[dt] == null) { allValid = false; break; } } if (!allValid) { continue; } PublisherConnection.Instance.Insert(dt, wmaLow, (wmaLow.TimeSeries[dt].Value.Value.Mid() - wmaVeryHighStart.Mid()) / amplitude); PublisherConnection.Instance.Insert(dt, wmaMid, (wmaMid.TimeSeries[dt].Value.Value.Mid() - wmaVeryHighStart.Mid()) / amplitude); PublisherConnection.Instance.Insert(dt, wmaHigh, (wmaHigh.TimeSeries[dt].Value.Value.Mid() - wmaVeryHighStart.Mid()) / amplitude); PublisherConnection.Instance.Insert(dt, wmaVeryHigh, (wmaVeryHigh.TimeSeries[dt].Value.Value.Mid() - wmaVeryHighStart.Mid()) / amplitude); PublisherConnection.Instance.Insert(dt, rsiShort, (rsiShort.TimeSeries[dt].Value.Value.Mid() - 50m) / amplitude); PublisherConnection.Instance.Insert(dt, rsiLong, (rsiLong.TimeSeries[dt].Value.Value.Mid() - 50m) / amplitude); PublisherConnection.Instance.Insert(dt, trendShort, trendShort.TimeSeries[dt].Value.Value.Mid() / 1000m); PublisherConnection.Instance.Insert(dt, trendLong, trendLong.TimeSeries[dt].Value.Value.Mid() / 1000m); PublisherConnection.Instance.Insert(dt, wmvolLow, wmvolLow.TimeSeries[dt].Value.Value.Mid() / 10m); PublisherConnection.Instance.Insert(dt, wmvolHigh, wmvolHigh.TimeSeries[dt].Value.Value.Mid() / 10m); PublisherConnection.Instance.Insert(dt, volTrendLow, volTrendLow.TimeSeries[dt].Value.Value.Mid()); PublisherConnection.Instance.Insert(dt, volTrendHigh, volTrendHigh.TimeSeries[dt].Value.Value.Mid()); PublisherConnection.Instance.Insert(dt, epic, new Value((double)selection[dt].Key / ((double)amplitude / 2.0))); } priceData[epic] = selection.Values.Select(kv => kv.Value).ToList(); } replay(priceData, tableListener); }
public void Connect(string username, string password, string apiKey, IgRestApiClient igRestApiClient) { if (Config.Settings.ContainsKey("PUBLISHING_START_TIME")) { _startTime = Config.ParseDateTimeLocal(Config.Settings["PUBLISHING_START_TIME"]); } if (Config.Settings.ContainsKey("PUBLISHING_STOP_TIME")) { _stopTime = Config.ParseDateTimeLocal(Config.Settings["PUBLISHING_STOP_TIME"]); } if (Config.Settings.ContainsKey("SAMPLING_MS")) { _samplingMs = int.Parse(Config.Settings["SAMPLING_MS"]); } _testReplayFiles.Clear(); _igRestApiClient = igRestApiClient; if (Config.Settings.ContainsKey("DELETEDB")) { _deleteDB = true; _testReplayFiles.Add(null); // Add a fake element to trigger the replay from db _deleter = new CassandraConnection(); _reader = _deleter; _readerExpectedResults = _deleter; _hasExpectedResults = true; } else { if (Config.Settings["REPLAY_MODE"] == "DB") { _testReplayFiles.Add(null); // Add a fake element to trigger the replay from db _reader = new CassandraConnection(); } else if (Config.Settings["REPLAY_MODE"] == "CSV") { if (Config.Settings.ContainsKey("REPLAY_CSV")) { _testReplayFiles = Config.Settings["REPLAY_CSV"].Split(';').ToList(); if (_reader != null) { _reader.CloseConnection(); } _reader = new CsvReader(_testReplayFiles[0]); } else { _reader = new CsvReader(null); } } else { _reader = null; } _hasExpectedResults = Config.TestReplayEnabled || Config.CalibratorEnabled; if (_hasExpectedResults) { if (Config.Settings.ContainsKey("EXPECTEDRESULTS_CSV")) { _readerExpectedResults = new CsvReader(Config.Settings["EXPECTEDRESULTS_CSV"]); } else { _readerExpectedResults = new CsvReader(_testReplayFiles[0]); } } } _numId = 1; _numRef = 1; }
public Price Average() { return(Average(Config.ParseDateTimeLocal(Config.Settings["PUBLISHING_STOP_TIME"]))); }
public Calendar(DateTime date) { string folder = (string)Config.Settings["CALENDAR_PATH"]; int time_offset = int.Parse(Config.Settings["TIME_GMT_CALENDAR"]); int day = date.Day - (int)date.DayOfWeek; int month = date.Month; int year = date.Year; if (day <= 0) { month -= 1; if (month == 0) { month = 12; year -= 1; } day = DateTime.DaysInMonth(year, month) + day; } StreamReader csvReader = new StreamReader(File.OpenRead(folder + string.Format("\\Calendar-{0:00}-{1:00}-{2}.csv", month, day, year))); _events = new Dictionary <string, List <KeyValuePair <DateTime, string> > >(); DateTime?curDate = null; while (!csvReader.EndOfStream) { var line = csvReader.ReadLine(); if (line == "") { continue; } string curDateStr = line.Split(',')[0]; if (curDateStr == "") { if (curDate == null) { continue; } } else { DateTime nextDate; if (!DateTime.TryParse(line.Split(' ')[0] + "-" + date.Year, out nextDate)) { continue; } curDate = nextDate; } string curCcy = line.Split(',')[1]; if (!_events.ContainsKey(curCcy)) { _events[curCcy] = new List <KeyValuePair <DateTime, string> >(); } string dateTimeStr = line.Split(',')[3]; if (dateTimeStr == "") { continue; } string eventName = ""; if (line.Contains("\"")) { eventName = line.Split('\"')[1]; } else { eventName = line.Split(',')[2]; } line = line.Replace(eventName, ""); var eventDateStr = curDate.Value.Day + "-" + curDate.Value.Month + "-" + curDate.Value.Year; var eventTimeStr = line.Split(',')[3]; if (eventTimeStr != "") { eventDateStr += " " + eventTimeStr + ":00"; } var eventDateTime = Config.ParseDateTimeLocal(eventDateStr); eventDateTime = eventDateTime.AddHours(time_offset); _events[curCcy].Add(new KeyValuePair <DateTime, string>(eventDateTime, eventName)); } }
public void GetMarketLevels() { try { if (PublisherConnection.Instance.Database != null) { var mktLevels = PublisherConnection.Instance.Database.GetMarketLevels(Config.ParseDateTimeLocal(Config.Settings["PUBLISHING_STOP_TIME"]), new List <string> { _mktLevelsId }); if (mktLevels.Count == 1) { _marketLevels = new MarketLevels(mktLevels.Values.First()); } } } catch { Log.Instance.WriteEntry("Could not retrieve market levels for Market Data: " + _mktLevelsId, EventLogEntryType.Warning); } }
protected static long ToUnixTimestamp(string dateTime) { return(ToUnixTimestamp(Config.ParseDateTimeLocal(dateTime))); }