Exemplo n.º 1
0
        public void onRequestCompleted(string requestID, O2GResponse response)
        {
            Console.WriteLine("Request completed ID: " + requestID);
            switch (response.Type)
            {
            case O2GResponseType.GetOffers:
            {
                Console.WriteLine("Received offers");
                logger.Debug("Received Offers");
                LoginForm.getInstance().fillRatesGrid();
                break;
            }

            case O2GResponseType.MarketDataSnapshot:
            {
                //All threads are saved to the thread dictionary
                if (HddMainFormBasic.ThreadDictionary.ContainsKey(requestID))
                {
                    DataSetup dataSetup = HddMainFormBasic.ThreadDictionary[requestID];
                    dataSetup.processData(response, HddMainFormBasic.getInstance(), dataSetup);
                    HddMainFormBasic.ThreadDictionary.Remove(requestID);
                }

                break;
            }
            }
        }
Exemplo n.º 2
0
 public static HddMainFormBasic getInstance()
 {
     lock (_MainInstanceLocker)
     {
         if (INSTANCE == null)
         {
             INSTANCE = new HddMainFormBasic();
         }
         return(INSTANCE);
     }
 }
Exemplo n.º 3
0
        private void loginLogoutButton_Click(object sender, EventArgs e)
        {
            //Validate username and password
            if (usernameDropdownList.Text.Trim().Equals(""))
            {
                MessageBox.Show("Please enter a valid username!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            else if (passwordTextbox.Text.Trim().Equals(""))
            {
                MessageBox.Show("Please enter a valid password!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }



            //Instantiate trading session and try to login
            tss = new TradingSession();
            tss.login(usernameDropdownList.Text, passwordTextbox.Text, "http://www.fxcorporate.com/Hosts.jsp", accountTypeDropdownList.Text);
            //Log.logMessageToFile("Login","Login method called");
            logger.Debug("Login method was called");


            //Wait for 5000 milliseconds to make sure the application logged in
            Stopwatch timer = new Stopwatch();

            timer.Start();
            while (tss.ConnectionStatus != O2GSessionStatusCode.Connected)
            {
                Thread.Sleep(1000);
                if (tss.ConnectionStatus == O2GSessionStatusCode.Unknown)
                {
                    logger.Error("Connection Status is unknown");
                    MessageBox.Show("Please check user credentials", "Error logging in");
                    return;
                }

                if (timer.Elapsed.TotalSeconds > 90 && tss.ConnectionStatus != O2GSessionStatusCode.Connected)
                {
                    logger.Error("Login is taking longer than 20 seconds!");
                    MessageBox.Show("Please check user credentials", "Error logging in");
                    return;
                }
            }

            timer.Stop();


            //Check if any login errors occurred, if exist return and throw error.
            if (tss.Error.Length != 0)
            {
                MessageBox.Show("Please check user credentials", "Error logging in");
                return;
            }


            //this.Invoke((MethodInvoker)delegate () {

            //});

            this.Hide();
            fillRatesGrid();

            logger.Debug("Starting HDD Basic");
            HddMainFormBasic.setPassword(passwordTextbox.Text);
            HddMainFormBasic.setUsername(usernameDropdownList.Text);
            HddMainFormBasic.setAccountType(accountTypeDropdownList.Text);
            HddMainFormBasic.setTradingSession(tss);
            HddMainFormBasic.setStatusLabel("Connected");
            HddMainFormBasic.setCurrencyList(temp, templist);
            HddMainFormBasic.setVersionLabel(mVersionLabel.Text);
            hddBasic = new HddMainFormBasic();
            hddBasic.Show();


            if (saveLoginButton.Checked)
            {
                set.username   = usernameDropdownList.Text;
                set.connection = accountTypeDropdownList.Text;
                set.saveMe     = saveLoginButton.Checked;
                set.Save();
            }


            //Save the user information into SQL lite
            fillTable(usernameDropdownList.Text.Trim(), accountTypeDropdownList.SelectedItem.ToString());
        }
Exemplo n.º 4
0
        public void processData(O2GResponse response, HddMainFormBasic hdd, DataSetup dataSetup)
        {
            bool     outOfRangeDateFound = false;
            DateTime tempEndDate         = new DateTime();

            try
            {
                //Exit thread if the value is false
                if (!keepThreadRunning)
                {
                    return;
                }

                var query1 = HddMainFormBasic.threadDictionary.Keys.FirstOrDefault(t => t == response.RequestID);
                if (query1 != null)
                {
                    HddMainFormBasic.threadDictionary[query1].CallBack = true;
                }


                O2GResponseReaderFactory readerfactory = tss.Session.getResponseReaderFactory();

                O2GMarketDataSnapshotResponseReader reader = readerfactory.createMarketDataSnapshotReader(response);

                DateTime from = new DateTime();
                DateTime to   = new DateTime();
                if (reader.Count > 0)
                {
                    from = reader.getDate(0);
                    to   = reader.getDate(reader.Count - 1);
                }
                Console.WriteLine("Market data received from " + from.ToString("MM/dd/yyyy HH:mm:ss") + " to " + to.ToString("MM/dd/yyyy HH:mm:ss"));

                //insert data into price list
                for (int j = reader.Count - 1; j > -1; j--)
                {
                    prices.Add(new Data(reader.getAskOpen(j), reader.getAskHigh(j), reader.getAskLow(j), reader.getAskClose(j), reader.getBidOpen(j), reader.getBidHigh(j), reader.getBidLow(j), reader.getBidClose(j), reader.getDate(j), reader.getVolume(j)));
                }
                //if less rates are obtained then it means we reached the end.
                //Nothing came back for the timeframe specified means, nothing exist in the remaining timeframe.
                if (reader.Count < 300 || reader.Count == 0)
                {
                    outOfRangeDateFound = true;
                    tempEndDate         = endDate;
                }

                if (!outOfRangeDateFound)
                {
                    removeLastDate(prices[prices.Count - 1].StartTime, prices);

                    tempEndDate = prices[prices.Count - 1].StartTime;
                }
                if (prices.Count > 3000)
                {
                    DataBaseHandler.getInstance().addEntries(prices);
                    prices.Clear();
                    if (timeInterval.Equals("t1"))
                    {
                        Thread.Sleep(2000);
                    }
                }

                //Get total ticks between end date and start date
                long totalTicks = tempEndDate.Ticks - dataSetup.StartDate.Ticks;

                currentStep           = 0;
                currentStep           = ((double)(totalTicks * maxIterations)) / initialTotalTicks;
                dataSetup.currentStep = currentStep;
                tick = reader.Count;
                Time = sw.Elapsed;

                #region repeat process OR quit
                if (outOfRangeDateFound == false)
                {
                    try
                    {
                        //Call HDD function to calculate more data
                        DataSetup ds = new DataSetup();
                        ds = dataSetup;

                        ds.EndDate = tempEndDate;
                        hdd.sendRequest(startDate, tempEndDate, ds);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("Error: " + e.Message);
                    }
                }
                else
                {
                    Console.WriteLine("Done");

                    #region Final flushing to database
                    try
                    {
                        if (prices.Count > 0)
                        {
                            //Finally write to database
                            DataBaseHandler.getInstance().addEntries(prices);
                        }
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message, "Error in writing data", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        logger.Debug(e.Message);
                        logger.Debug(e.StackTrace);
                    }
                    finally
                    {
                        prices.Clear();
                    }
                    #endregion

                    #region Writing to a File
                    long rows = 0;
                    rows = DataBaseHandler.getInstance().getNumberOfRows();

                    //Calculate the levels first before requesting data.
                    long        templevel = 0;
                    List <long> levels    = new List <long>();
                    levels.Add(0);
                    while (true)
                    {
                        if (templevel + 5000 < rows)
                        {
                            templevel += 5000;
                            levels.Add(templevel);
                        }
                        else
                        {
                            levels.Add(rows);
                            break;
                        }
                    }
                    logger.Debug("Levels of data to be requested from database: " + levels.ToString());
                    dataSetup.isAlive = false;
                    #endregion
                }
                #endregion
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + "\n" + e.Source, "Error");
            }
        }