static void OnHistoryUpdated(object sender, CandleHistoryCandleUpdatedEventArgs args) { CandleHistory history = (CandleHistory)sender; List <ICandleDataWriter> writers = null; if (mDataWriters.TryGetValue(history.ID, out writers)) { foreach (ICandleDataWriter writer in writers) { writer.WriteCandleData(args.Candle); } } }
internal CandleManagerHistory(TransportHistoryRequest request, bool subscribe, TimeFrameCalculator calculator, int precision) { mPrecision = precision; mTimeframe = Timeframe.Parse(request.Timeframe); mHistory = new CandleHistory(request.Instrument, mTimeframe, calculator, mPrecision); if (subscribe) { mTicks = new LinkedList <Tick>(); } mWaitForData = true; mSubscribe = subscribe; mFailed = false; mCount = request.Count; mLastMinute = DateTime.MinValue; }
static void OnHistoryLoaded(object sender, CandleHistoryLoadedEventArgs args) { CandleHistory history = (CandleHistory)sender; List <ICandleDataWriter> writers = null; if (mDataWriters.TryGetValue(history.ID, out writers)) { for (int i = 0; i < history.Count; i++) { foreach (ICandleDataWriter writer in writers) { writer.WriteCandleData(history[i]); } } } }
static void Main(string[] args) { ITransport transport = null; CandleManager manager = null; mDataWriters = new Dictionary <string, List <ICandleDataWriter> >(); try { ReadDataFromConfig("Configuration.xml"); if (args.Length == 0) { throw new Exception("Please specify password via command line"); } CtrlCHandler ctrlc = new CtrlCHandler(); mExit = mConnected = false; transport = TransportFactory.CreateForexConnectTransport(mLogin, args[0], mUrl, mConnection, mTimezone); //getDayOffsetByTimeZone should depend on the server zone manager = new CandleManager(transport, -3 /*getDayOffsetByTimeZone(mTimezone)*/, -1); transport.OnSessionStatusChanged += OnStatus; transport.OnError += OnError; transport.login(); while (!mExit && !mConnected) { Thread.Sleep(10); } if (mConnected) { foreach (HistoryConfigData config in mHistory) { CandleHistory history = manager.GetHistory(config.Instrument, config.Timeframe, config.NumBars); mDataWriters[history.ID] = new List <ICandleDataWriter>(); //mDataWriters[history.ID].Add(new ConsoleCandleDataWriter(config.Instrument, config.Timeframe, true)); mDataWriters[history.ID].Add(new CSVCandleDataWriter(config.Instrument, config.Timeframe, mOutputDir, config.Filename, mDelimiter, mFormatDecimal.ToLower().Equals("y"), mDateTimeSeparator, true, mTimezone, transport.getTimeConverter(), config.AddHeader)); history.OnLoaded += OnHistoryLoaded; history.OnFailed += OnHistoryFailed; history.OnUpdated += OnHistoryUpdated; } while (!ctrlc.ExitRequest) { Thread.Sleep(10); } transport.logout(); while (!mExit) { ; } } } catch (Exception ex) { Console.WriteLine("Error: {0}", ex.Message); } finally { manager = null; if (transport != null) { transport.Dispose(); } foreach (List <ICandleDataWriter> writers in mDataWriters.Values) { foreach (ICandleDataWriter writer in writers) { writer.Dispose(); } } } }
static void OnHistoryFailed(object sender, CandleHistoryFailedEventArgs args) { CandleHistory history = (CandleHistory)sender; Console.WriteLine("{0} {1} {2}", history.Instrument, history.Timeframe, args.Error); }