Ejemplo n.º 1
0
        /// <summary>
        /// Tries to start next remove task.
        /// </summary>
        /// <param name="quotesManager">The QuotesManager instance</param>
        /// <param name="removeTasks">Collection of remove tasks</param>
        /// <param name="removeQuoteListener">Listener of remove quotes task</param>
        private static void StartNextRemoveTask(QuotesManager quotesManager, Queue <RemoveQuotesTask> removeTasks, RemoveQuotesListener removeQuoteListener)
        {
            RemoveQuotesTask removeTask = removeTasks.Dequeue();

            quotesManager.executeTask(removeTask);
            removeQuoteListener.WaitEvents();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Removes quotes from local cache.
        /// </summary>
        /// <param name="quotesManager">The QuotesManager instance</param>
        /// <param name="instrument">Instrument name</param>
        /// <param name="year">Year</param>
        static void RemoveLocalQuotes(QuotesManager quotesManager, string instrument, int year)
        {
            if (instrument == null)
            {
                throw new ArgumentNullException("instrument");
            }

            if (quotesManager == null)
            {
                Console.WriteLine("Failed to remove local quotes");
                return;
            }

            ICollection <IQMData> quotes = null;

            try
            {
                quotes = GetQuotes(quotesManager, instrument, year);
            }
            catch (Exception error)
            {
                Console.WriteLine("Failed to remove local quotes : {0}", error.Message);
                return;
            }

            if (quotes == null || quotes.Count == 0)
            {
                Console.WriteLine("There are no quotes to remove");
                return;
            }

            RemoveData(quotesManager, quotes);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Prepares the collection of the quotes stored in the Quotes Manager cache.
        /// </summary>
        ///<param name="quotesManager">QuotesManager instance</param>
        public static IQMDataCollection PrepareListOfQMData(QuotesManager quotesManager)
        {
            QMDataCollection collection  = new QMDataCollection();
            BaseTimeframes   timeframes  = quotesManager.getBaseTimeframes();
            Instruments      instruments = quotesManager.getInstruments();

            int instrumentCount = instruments.size();

            for (int i = 0; i < instrumentCount; i++)
            {
                Instrument instrument     = instruments.get(i);
                int        timeframeCount = timeframes.size();
                for (int j = 0; j < timeframeCount; j++)
                {
                    string timeframe = timeframes.get(j);
                    int    y1        = instrument.getOldestQuoteDate(timeframe).Year;
                    int    y2        = instrument.getLatestQuoteDate(timeframe).Year;
                    if (y2 >= y1)
                    {
                        for (int y = y1; y <= y2; y++)
                        {
                            long size = quotesManager.getDataSize(instrument.getName(), timeframe, y);
                            if (size > 0)
                            {
                                collection.Add(new QMData(instrument.getName(), timeframe, y, size));
                            }
                        }
                    }
                }
            }

            return(collection);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Remove quotes.
        /// </summary>
        /// <param name="quotesManager">The QuotesManager instance</param>
        /// <param name="arguments">Parameters of remove command</param>
        static void RemoveQuotes(QuotesManager quotesManager, SampleParams sampleParams)
        {
            if (sampleParams.Year <= 0)
            {
                Console.WriteLine("Error : year must be positive integer value");
                return;
            }

            RemoveLocalQuotes(quotesManager, sampleParams.Instrument, sampleParams.Year);
        }
Ejemplo n.º 5
0
        private void editQuotesButton_Click(object sender, RoutedEventArgs e)
        {
            QuotesManager manager = new QuotesManager();

            manager.Owner = Window.GetWindow(this);

            if (manager.ShowDialog() == true && manager.ChangesMade)
            {
                BackstageEvents.StaticUpdater.InvokeQuotesChanged();
            }
        }
        private QuotesController SetupStubbedQuotesController()
        {
            var builder = new DbContextOptionsBuilder <AppDbContext>().UseSqlite(_connection);

            var appDataContext = new AppDbContext(builder.Options);

            appDataContext.Database.EnsureDeleted();
            appDataContext.Database.EnsureCreated();

            var repository = new QuotesRepository(appDataContext);
            var manager    = new QuotesManager(repository, null);

            return(new QuotesController(manager, Mappings.Setup()));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Removes the data from cache.
        /// </summary>
        /// <param name="quotesManager">The QuotesManager instance</param>
        /// <param name="list">Collection of quotes manager storage data.</param>
        public static void RemoveData(QuotesManager quotesManager, IEnumerable <IQMData> list)
        {
            Queue <RemoveQuotesTask> removeTasks          = new Queue <RemoveQuotesTask>();
            RemoveQuotesListener     removeQuotesListener = new RemoveQuotesListener();

            foreach (IQMData data in list)
            {
                RemoveQuotesTask task = quotesManager.createRemoveQuotesTask(data.Instrument,
                                                                             data.Timeframe, removeQuotesListener);
                task.addYear(data.Year);
                removeTasks.Enqueue(task);
            }

            while (removeTasks.Count > 0)
            {
                StartNextRemoveTask(quotesManager, removeTasks, removeQuotesListener);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Fills QuotesManager data for the specified instrument and year.
        /// </summary>
        /// <param name="quotesManager">QuotesManager instance</param>
        /// <param name="instrument">Instrument name</param>
        /// <param name="year">Year</param>
        /// <returns>Collection of quotes manager storage data</returns>
        static ICollection <IQMData> GetQuotes(QuotesManager quotesManager, string instrument, int year)
        {
            BaseTimeframes baseTimeframes  = quotesManager.getBaseTimeframes();
            int            timeframesCount = baseTimeframes.size();
            List <IQMData> quotes          = new List <IQMData>(timeframesCount);

            for (int i = 0; i < timeframesCount; ++i)
            {
                string timeframe = baseTimeframes.get(i);
                long   size      = quotesManager.getDataSize(instrument, timeframe, year);
                if (size > 0)
                {
                    quotes.Add(new QMData(instrument, timeframe, year, size));
                }
            }

            return(quotes);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Shows quotes that are available in local cache.
        /// </summary>
        /// <param name="quotesManager">QuotesManager instance</param>
        static void ShowLocalQuotes(QuotesManager quotesManager)
        {
            if (quotesManager == null)
            {
                Console.WriteLine("Failed to get local quotes");
                return;
            }

            // if the instruments list is not updated, update it now
            if (!quotesManager.areInstrumentsUpdated())
            {
                UpdateInstrumentsListener instrumentsCallback = new UpdateInstrumentsListener();
                UpdateInstrumentsTask     task = quotesManager.createUpdateInstrumentsTask(instrumentsCallback);
                quotesManager.executeTask(task);
                instrumentsCallback.WaitEvents();
            }

            IQMDataCollection collection = PrepareListOfQMData(quotesManager);

            ShowPreparedQMDataList(collection);
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            O2GSession session = null;
            IPriceHistoryCommunicator communicator   = null;
            SessionStatusListener     statusListener = null;
            bool loggedIn = false;

            try
            {
                LoginParams  loginParams  = new LoginParams(ConfigurationManager.AppSettings);
                SampleParams sampleParams = new SampleParams(ConfigurationManager.AppSettings);

                PrintSampleParams("RemoveQuotes", loginParams, sampleParams);

                // use the application module path as a base path for quotes storage
                string storagePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "History");

                // create the ForexConnect trading session
                session        = O2GTransport.createSession();
                statusListener = new SessionStatusListener(session, loginParams.SessionID, loginParams.Pin);
                // subscribe IO2GSessionStatus interface implementation for the status events
                session.subscribeSessionStatus(statusListener);
                statusListener.Reset();

                // create an instance of IPriceHistoryCommunicator
                communicator = PriceHistoryCommunicatorFactory.createCommunicator(session, storagePath);

                // log in to ForexConnect
                session.login(loginParams.Login, loginParams.Password, loginParams.URL, loginParams.Connection);
                if (statusListener.WaitEvents() && statusListener.Connected)
                {
                    loggedIn = true;

                    CommunicatorStatusListener communicatorStatusListener = new CommunicatorStatusListener();
                    communicator.addStatusListener(communicatorStatusListener);

                    // wait until the communicator signals that it is ready
                    if (communicator.isReady() ||
                        (communicatorStatusListener.WaitEvents() && communicatorStatusListener.Ready))
                    {
                        // set open price candles mode, it must be called after login
                        QuotesManager quotesManager = communicator.getQuotesManager();

                        RemoveQuotes(quotesManager, sampleParams);
                        Console.WriteLine();
                        ShowLocalQuotes(quotesManager);
                    }
                    communicator.removeStatusListener(communicatorStatusListener);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e.ToString());
            }
            finally
            {
                if (communicator != null)
                {
                    communicator.Dispose();
                }
                if (session != null)
                {
                    try
                    {
                        statusListener.Reset();
                        session.logout();
                        statusListener.WaitEvents();
                    }
                    catch (Exception ee)
                    {
                    }

                    session.unsubscribeSessionStatus(statusListener);
                    session.Dispose();
                }
            }
        }
Ejemplo n.º 11
0
        private void GetData()
        {
            try
            {
                //data = XElement.Load(path + @"Data\" + symbol + ".XML");

                // New in alpha-2

                quotesManager = new QuotesManager(symbol);

                data = quotesManager.Data;

                if (toolStripComboBoxPeriod.SelectedIndex == 0)
                {
                    IEnumerable <XElement> newdata = (from c in data.Elements("quote") where (DateTime)c.Element("date") >= quotesManager.GetLastDate().AddMonths(-1) select c);

                    data = new XElement("quotes", newdata);
                }
                else if (toolStripComboBoxPeriod.SelectedIndex == 1)
                {
                    IEnumerable <XElement> newdata = (from c in data.Elements("quote") where (DateTime)c.Element("date") >= quotesManager.GetLastDate().AddMonths(-2) select c);

                    data = new XElement("quotes", newdata);
                }
                else if (toolStripComboBoxPeriod.SelectedIndex == 2)
                {
                    IEnumerable <XElement> newdata = (from c in data.Elements("quote") where (DateTime)c.Element("date") >= quotesManager.GetLastDate().AddMonths(-3) select c);

                    data = new XElement("quotes", newdata);
                }
                else if (toolStripComboBoxPeriod.SelectedIndex == 3)
                {
                    IEnumerable <XElement> newdata = (from c in data.Elements("quote") where (DateTime)c.Element("date") >= quotesManager.GetLastDate().AddMonths(-4) select c);

                    data = new XElement("quotes", newdata);
                }
                else if (toolStripComboBoxPeriod.SelectedIndex == 4)
                {
                    IEnumerable <XElement> newdata = (from c in data.Elements("quote") where (DateTime)c.Element("date") >= quotesManager.GetLastDate().AddMonths(-6) select c);

                    data = new XElement("quotes", newdata);
                }
                else if (toolStripComboBoxPeriod.SelectedIndex == 5)
                {
                    IEnumerable <XElement> newdata = (from c in data.Elements("quote") where (DateTime)c.Element("date") >= quotesManager.GetLastDate().AddYears(-1) select c);

                    data = new XElement("quotes", newdata);
                }
                else if (toolStripComboBoxPeriod.SelectedIndex == 6)
                {
                    IEnumerable <XElement> newdata = (from c in data.Elements("quote") where (DateTime)c.Element("date") >= quotesManager.GetLastDate().AddYears(-2) select c);

                    data = new XElement("quotes", newdata);
                }
                else if (toolStripComboBoxPeriod.SelectedIndex == 7)
                {
                    IEnumerable <XElement> newdata = (from c in data.Elements("quote") where (DateTime)c.Element("date") >= quotesManager.GetLastDate().AddYears(-3) select c);

                    data = new XElement("quotes", newdata);
                }
                else if (toolStripComboBoxPeriod.SelectedIndex == 8)
                {
                    IEnumerable <XElement> newdata = (from c in data.Elements("quote") where (DateTime)c.Element("date") >= quotesManager.GetLastDate().AddYears(-5) select c);

                    data = new XElement("quotes", newdata);
                }

                layers = symbolManager.GetLayers(symbol);

                layersChanged   = new EventHandler <XObjectChangeEventArgs>(Layers_Changed);
                layers.Changed += layersChanged;

                toolStripButtonSave.Enabled = false;

                if (layers.Nodes().Count() != 0)
                {
                    toolStripButtonUndoLast.Enabled = true;
                    toolStripButtonUndoAll.Enabled  = true;
                }
                else
                {
                    toolStripButtonUndoLast.Enabled = false;
                    toolStripButtonUndoAll.Enabled  = false;
                }
            }
            catch (IOException ex)
            {
                MessageBox.Show(this, "Can not load symbol: " + ex.Message, "Error");
            }
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            O2GSession session = null;
            IPriceHistoryCommunicator communicator   = null;
            SessionStatusListener     statusListener = null;

            try
            {
                Console.WriteLine("GetHistPrices sample\n");

                ArgumentParser argParser = new ArgumentParser(args, "GetHistPrices");

                argParser.AddArguments(ParserArgument.Login,
                                       ParserArgument.Password,
                                       ParserArgument.Url,
                                       ParserArgument.Connection,
                                       ParserArgument.SessionID,
                                       ParserArgument.Pin,
                                       ParserArgument.Instrument,
                                       ParserArgument.TimeFrame,
                                       ParserArgument.DateFrom,
                                       ParserArgument.DateTo,
                                       ParserArgument.QuotesCount,
                                       ParserArgument.OpenPriceCandlesMode);

                argParser.ParseArguments();

                if (!argParser.AreArgumentsValid)
                {
                    argParser.PrintUsage();
                    return;
                }

                argParser.PrintArguments();

                LoginParams  loginParams  = argParser.LoginParams;
                SampleParams sampleParams = argParser.SampleParams;

                // use the application module path as a base path for quotes storage
                string storagePath = System.IO.Path.Combine(AppContext.BaseDirectory, "History");

                // create the ForexConnect trading session
                session        = O2GTransport.createSession();
                statusListener = new SessionStatusListener(session, loginParams.SessionID, loginParams.Pin);
                // subscribe IO2GSessionStatus interface implementation for the status events
                session.subscribeSessionStatus(statusListener);
                statusListener.Reset();

                // create an instance of IPriceHistoryCommunicator
                communicator = PriceHistoryCommunicatorFactory.createCommunicator(session, storagePath);

                // log in to ForexConnect
                session.login(loginParams.Login, loginParams.Password, loginParams.URL, loginParams.Connection);
                if (statusListener.WaitEvents() && statusListener.Connected)
                {
                    CommunicatorStatusListener communicatorStatusListener = new CommunicatorStatusListener();
                    communicator.addStatusListener(communicatorStatusListener);

                    // wait until the communicator signals that it is ready
                    if (communicator.isReady() ||
                        (communicatorStatusListener.WaitEvents() && communicatorStatusListener.Ready))
                    {
                        // set open price candles mode, it must be called after login
                        QuotesManager quotesManager = communicator.getQuotesManager();
                        quotesManager.openPriceCandlesMode = sampleParams.OpenPriceCandlesMode;

                        // attach the instance of the class that implements the IPriceHistoryCommunicatorListener
                        // interface to the communicator
                        ResponseListener responseListener = new ResponseListener();
                        communicator.addListener(responseListener);

                        GetHistoryPrices(communicator, sampleParams.Instrument, sampleParams.Timeframe,
                                         sampleParams.DateFrom, sampleParams.DateTo, sampleParams.QuotesCount, responseListener);
                        Console.WriteLine("Done!");

                        communicator.removeListener(responseListener);
                    }

                    communicator.removeStatusListener(communicatorStatusListener);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e.ToString());
            }
            finally
            {
                if (communicator != null)
                {
                    communicator.Dispose();
                }
                if (session != null)
                {
                    try
                    {
                        statusListener.Reset();
                        session.logout();
                        statusListener.WaitEvents();
                    }
                    catch (Exception)
                    {
                    }

                    session.unsubscribeSessionStatus(statusListener);
                    session.Dispose();
                }
            }
        }
Ejemplo n.º 13
0
 public void Start()
 {
     instance = gameObject.AddComponent <QuotesManager>();
 }