Пример #1
0
        /* Prepare Params for Orders */
        public void PrepareParamsFromLoginRules(O2GLoginRules loginRules)
        {
            O2GResponseReaderFactory factory = m_o2gsession.getResponseReaderFactory();

            if (factory == null)
            {
                return;
            }
            // Gets first account from login.
            O2GResponse accountsResponse = loginRules.getTableRefreshResponse(O2GTableType.Accounts);
            O2GAccountsTableResponseReader accountsReader = factory.createAccountsTableReader(accountsResponse);
            O2GAccountRow account = accountsReader.getRow(0);

            // Store account id
            m_accountid = account.AccountID;
            // Store base iAmount
            m_baseamount = account.BaseUnitSize;
            // Get offers for eur/usd
            O2GResponse offerResponse = loginRules.getTableRefreshResponse(O2GTableType.Offers);
            O2GOffersTableResponseReader offersReader = factory.createOffersTableReader(offerResponse);

            for (int i = 0; i < offersReader.Count; i++)
            {
                O2GOfferRow offer = offersReader.getRow(i);
                if (string.Compare(offer.Instrument, m_instrument /*"EUR/USD"*/, true) == 0)
                {
                    m_offerid   = offer.OfferID;
                    m_ask       = offer.Ask;
                    m_bid       = offer.Bid;
                    m_pointsize = offer.PointSize;
                    break;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Find valid offer by instrument name
        /// </summary>
        /// <param name="session"></param>
        /// <param name="sInstrument"></param>
        /// <returns>offer</returns>
        private static O2GOfferRow GetOffer(O2GSession session, string sInstrument)
        {
            O2GOfferRow offer     = null;
            bool        bHasOffer = false;
            O2GResponseReaderFactory readerFactory = session.getResponseReaderFactory();

            if (readerFactory == null)
            {
                throw new Exception("Cannot create response reader factory");
            }
            O2GLoginRules loginRules = session.getLoginRules();
            O2GResponse   response   = loginRules.getTableRefreshResponse(O2GTableType.Offers);
            O2GOffersTableResponseReader offersResponseReader = readerFactory.createOffersTableReader(response);

            for (int i = 0; i < offersResponseReader.Count; i++)
            {
                offer = offersResponseReader.getRow(i);
                if (offer.Instrument.Equals(sInstrument))
                {
                    if (offer.SubscriptionStatus.Equals("T"))
                    {
                        bHasOffer = true;
                        break;
                    }
                }
            }
            if (!bHasOffer)
            {
                return(null);
            }
            else
            {
                return(offer);
            }
        }
        /// <summary>
        /// Listener: Forex Connect request handled.
        /// </summary>
        /// <param name="requestId"></param>
        /// <param name="response"></param>
        public void onRequestCompleted(string requestId, O2GResponse response)
        {
            // we need only offer table refresh for our example
            if (response.Type == O2GResponseType.GetOffers)
            {
                // so simply read and store offers
                O2GOffersTableResponseReader reader = mSession.getResponseReaderFactory().createOffersTableReader(response);
                for (int i = 0; i < reader.Count; i++)
                {
                    O2GOfferRow row = reader.getRow(i);
                    if (mInstrument.Equals(row.Instrument))
                    {
                        mOffer = new Offer(row.Instrument, row.Time, row.Bid, row.Ask, row.Volume, row.Digits);
                        mSyncOfferEvent.Set();
                        break;
                    }
                }

                if (mOffer == null)
                {
                    Console.WriteLine("Instrument is not found.\n");
                    mInitFailed = true;
                    mSyncOfferEvent.Set();
                }
            }
        }
Пример #4
0
        public OrderObject prepareParamsFromLoginRules(string instrument)
        {
            OrderObject              orderObject = new OrderObject();
            O2GLoginRules            loginRules  = _session.Session.getLoginRules();
            O2GResponseReaderFactory factory     = _session.Session.getResponseReaderFactory();
            // Gets first account from login.
            O2GResponse accountsResponse = loginRules.getTableRefeshResponse(O2GTable.Accounts);
            O2GAccountsTableResponseReader accountsReader = factory.createAccountsTableReader(accountsResponse);
            O2GAccountRow account = accountsReader.getRow(0);

            orderObject.AccountID = account.AccountID;
            // Store base iAmount
            orderObject.BaseAmount = account.BaseUnitSize;

            O2GResponse offerResponse = loginRules.getTableRefeshResponse(O2GTable.Offers);
            O2GOffersTableResponseReader offersReader = factory.createOffersTableReader(offerResponse);

            for (int i = 0; i < offersReader.Count; i++)
            {
                O2GOfferRow offer = offersReader.getRow(i);
                if (instrument.Equals(offer.Instrument))
                {
                    orderObject.OfferID   = offer.OfferID;
                    orderObject.Ask       = offer.Ask;
                    orderObject.Bid       = offer.Bid;
                    orderObject.PointSize = offer.PointSize;
                    orderObject.Symbol    = new Symbol(instrument);
                    break;
                }
            }

            return(orderObject);
        }
Пример #5
0
        private IEnumerable <OfferRow> GetGenericResponse(O2GOffersTableResponseReader reader)
        {
            var rows = new List <OfferRow>();

            for (var i = 0; i < reader.Count; i++)
            {
                rows.Add(this.GetRow <OfferRow, O2GOfferRow>(reader.getRow(i)));
            }

            return(rows);
        }
Пример #6
0
 /// <summary>
 /// Listener: Forex Connect request handled
 /// </summary>
 /// <param name="requestId"></param>
 /// <param name="response"></param>
 public void onRequestCompleted(string requestId, O2GResponse response)
 {
     // we need only offer table refresh for our example
     if (response.Type == O2GResponseType.GetOffers)
     {
         // so simply read and store offers
         O2GOffersTableResponseReader reader = mTradingSession.getResponseReaderFactory().createOffersTableReader(response);
         mOffers.Clear();
         for (int i = 0; i < reader.Count; i++)
         {
             O2GOfferRow row = reader.getRow(i);
             mOffers.Add(row.OfferID, row.Instrument, row.Time, row.Bid, row.Ask, row.Volume, row.Digits);
         }
         // if price history communicator has been initialized before we get offer - notify that we're ready.
         if (mPriceHistoryCommunicator.isReady() && OnStateChange != null)
         {
             OnStateChange(true);
         }
     }
 }
Пример #7
0
        /// <summary>
        /// Print offers and find offer by instrument name
        /// </summary>
        /// <param name="session"></param>
        /// <param name="sInstrument"></param>
        /// <returns>offer</returns>
        private static O2GOfferRow GetOffer(O2GSession session, string sInstrument)
        {
            O2GOfferRow offer = null;
            O2GResponseReaderFactory readerFactory = session.getResponseReaderFactory();

            if (readerFactory == null)
            {
                throw new Exception("Cannot create response reader factory");
            }
            O2GLoginRules loginRules = session.getLoginRules();
            O2GResponse   response   = loginRules.getTableRefreshResponse(O2GTableType.Offers);
            O2GOffersTableResponseReader offersResponseReader = readerFactory.createOffersTableReader(response);

            for (int i = 0; i < offersResponseReader.Count; i++)
            {
                O2GOfferRow offerRow = offersResponseReader.getRow(i);
                if (offerRow.Instrument.Equals(sInstrument))
                {
                    offer = offerRow;
                }
                switch (offerRow.SubscriptionStatus)
                {
                case Constants.SubscriptionStatuses.ViewOnly:
                    Console.WriteLine("{0} : [V]iew only", offerRow.Instrument);
                    break;

                case Constants.SubscriptionStatuses.Disable:
                    Console.WriteLine("{0} : [D]isabled", offerRow.Instrument);
                    break;

                case Constants.SubscriptionStatuses.Tradable:
                    Console.WriteLine("{0} : Available for [T]rade", offerRow.Instrument);
                    break;

                default:
                    Console.WriteLine("{0} : {1}", offerRow.Instrument, offerRow.SubscriptionStatus);
                    break;
                }
            }
            return(offer);
        }
Пример #8
0
        /// <summary>
        /// Store offers data from response and print it
        /// </summary>
        /// <param name="session"></param>
        /// <param name="response"></param>
        /// <param name="sInstrument"></param>
        public void PrintOffers(O2GSession session, O2GResponse response, string sInstrument)
        {
            O2GResponseReaderFactory readerFactory = session.getResponseReaderFactory();

            if (readerFactory == null)
            {
                throw new Exception("Cannot create response reader factory");
            }
            O2GOffersTableResponseReader responseReader = readerFactory.createOffersTableReader(response);

            for (int i = 0; i < responseReader.Count; i++)
            {
                O2GOfferRow offerRow = responseReader.getRow(i);
                Offer       offer;
                if (mOffers.FindOffer(offerRow.OfferID, out offer))
                {
                    if (offerRow.isTimeValid && offerRow.isBidValid && offerRow.isAskValid)
                    {
                        offer.Date = offerRow.Time;
                        offer.Bid  = offerRow.Bid;
                        offer.Ask  = offerRow.Ask;
                    }
                }
                else
                {
                    offer = new Offer(offerRow.OfferID, offerRow.Instrument,
                                      offerRow.Digits, offerRow.PointSize, offerRow.Time,
                                      offerRow.Bid, offerRow.Ask);
                    mOffers.AddOffer(offer);
                }
                if (string.IsNullOrEmpty(sInstrument) || offerRow.Instrument.Equals(sInstrument))
                {
                    if (offer.Instrument.Equals("Copper"))
                    {
                        //Console.WriteLine("{0}, {1}, Bid={2}, Ask={3}", offer.OfferID, offer.Instrument, offer.Bid, offer.Ask);
                    }
                    Console.WriteLine("{0}, {1}, Bid={2}, Ask={3}", offer.OfferID, offer.Instrument, offer.Bid, offer.Ask);
                }
            }
        }
        void ReadOffers(O2GResponse offers)
        {
            O2GResponseReaderFactory factory = mSession.getResponseReaderFactory();

            if (factory != null)
            {
                O2GOffersTableResponseReader reader = factory.createOffersTableReader(offers);

                mOffers.Clear();
                mOffersList.Clear();

                for (int i = 0; i < reader.Count; i++)
                {
                    O2GOfferRow row = reader.getRow(i);
                    //mTimeConverter.convert(row.Time, O2GTimeConverterTimeZone.UTC, mTimezone)
                    //DateTime dt = mTimeConverter.convert(row.Time, O2GTimeConverterTimeZone.Server, O2GTimeConverterTimeZone.UTC);
                    DateTime dt    = row.Time;
                    Offer    offer = new Offer(row.Instrument, dt, row.Bid, row.Ask, row.Volume, row.Digits, row.PointSize);
                    mOffers[row.OfferID] = offer;
                    mOffersList.Add(offer);
                    SendTick(offer);
                }
            }
        }
Пример #10
0
        // Print trading settings of the first account
        private static void PrintTradingSettings(O2GSession session)
        {
            O2GLoginRules loginRules = session.getLoginRules();

            if (loginRules == null)
            {
                throw new Exception("Cannot get login rules");
            }
            O2GResponse accountsResponse = loginRules.getTableRefreshResponse(O2GTableType.Accounts);

            if (accountsResponse == null)
            {
                throw new Exception("Cannot get response");
            }
            O2GResponse offersResponse = loginRules.getTableRefreshResponse(O2GTableType.Offers);

            if (offersResponse == null)
            {
                throw new Exception("Cannot get response");
            }
            O2GTradingSettingsProvider tradingSettingsProvider = loginRules.getTradingSettingsProvider();
            O2GResponseReaderFactory   factory = session.getResponseReaderFactory();

            if (factory == null)
            {
                throw new Exception("Cannot create response reader factory");
            }
            O2GAccountsTableResponseReader accountsReader    = factory.createAccountsTableReader(accountsResponse);
            O2GOffersTableResponseReader   instrumentsReader = factory.createOffersTableReader(offersResponse);
            O2GAccountRow account = accountsReader.getRow(0);

            for (int i = 0; i < instrumentsReader.Count; i++)
            {
                O2GOfferRow     instrumentRow         = instrumentsReader.getRow(i);
                string          instrument            = instrumentRow.Instrument;
                int             condDistStopForTrade  = tradingSettingsProvider.getCondDistStopForTrade(instrument);
                int             condDistLimitForTrade = tradingSettingsProvider.getCondDistLimitForTrade(instrument);
                int             condDistEntryStop     = tradingSettingsProvider.getCondDistEntryStop(instrument);
                int             condDistEntryLimit    = tradingSettingsProvider.getCondDistEntryLimit(instrument);
                int             minQuantity           = tradingSettingsProvider.getMinQuantity(instrument, account);
                int             maxQuantity           = tradingSettingsProvider.getMaxQuantity(instrument, account);
                int             baseUnitSize          = tradingSettingsProvider.getBaseUnitSize(instrument, account);
                O2GMarketStatus marketStatus          = tradingSettingsProvider.getMarketStatus(instrument);
                int             minTrailingStep       = tradingSettingsProvider.getMinTrailingStep();
                int             maxTrailingStep       = tradingSettingsProvider.getMaxTrailingStep();
                double          mmr = tradingSettingsProvider.getMMR(instrument, account);
                double          mmr2 = 0, emr = 0, lmr = 0;
                bool            threeLevelMargin = tradingSettingsProvider.getMargins(instrument, account, ref mmr2, ref emr, ref lmr);
                string          sMarketStatus    = "unknown";
                switch (marketStatus)
                {
                case O2GMarketStatus.MarketStatusOpen:
                    sMarketStatus = "Market Open";
                    break;

                case O2GMarketStatus.MarketStatusClosed:
                    sMarketStatus = "Market Close";
                    break;
                }
                Console.WriteLine("Instrument: {0}, Status: {1}", instrument, sMarketStatus);
                Console.WriteLine("Cond.Dist: ST={0}; LT={1}", condDistStopForTrade, condDistLimitForTrade);
                Console.WriteLine("Cond.Dist entry stop={0}; entry limit={1}", condDistEntryStop,
                                  condDistEntryLimit);
                Console.WriteLine("Quantity: Min={0}; Max={1}. Base unit size={2}; MMR={3}", minQuantity,
                                  maxQuantity, baseUnitSize, mmr);
                if (threeLevelMargin)
                {
                    Console.WriteLine("Three level margin: MMR={0}; EMR={1}; LMR={2}", mmr2, emr, lmr);
                }
                else
                {
                    Console.WriteLine("Single level margin: MMR={0}; EMR={1}; LMR={2}", mmr2, emr, lmr);
                }
                Console.WriteLine("Trailing step: {0}-{1}", minTrailingStep, maxTrailingStep);
            }
        }
Пример #11
0
        // **AFTER LOG IN**
        // Background worker for table listeners
        private void priceBW_DoWork(object sender, DoWorkEventArgs e)
        {
            Console.WriteLine("Entered BW");

            mSession.useTableManager(O2GTableManagerMode.Yes, null);

            tableManager  = mSession.getTableManager();
            managerStatus = tableManager.getStatus();

            while (managerStatus == O2GTableManagerStatus.TablesLoading)
            {
                Thread.Sleep(50);
                managerStatus = tableManager.getStatus();
            }
            if (managerStatus == O2GTableManagerStatus.TablesLoadFailed)
            {
                this.Invoke(new MethodInvoker(delegate { actiBox.AppendText("WARNING: LOADING TABLES FAILED!" + Environment.NewLine); }));
                return;
            }
            // Check Accounts Table and Grab Information
            try
            {
                O2GLoginRules loginRules = mSession.getLoginRules();
                Console.WriteLine("Tables are loaded!");
                // Check if Accounts table is loaded automatically
                if (loginRules != null && loginRules.isTableLoadedByDefault(O2GTableType.Accounts))
                {
                    // If table is loaded, use getTableRefreshResponse method
                    O2GResponse accountsResponse             = loginRules.getTableRefreshResponse(O2GTableType.Accounts);
                    O2GResponseReaderFactory responseFactory = mSession.getResponseReaderFactory();
                    if (responseFactory != null)
                    {
                        O2GAccountsTableResponseReader accountsReader = responseFactory.createAccountsTableReader(accountsResponse);

                        for (int i = 0; i < accountsReader.Count; i++)
                        {
                            account      = accountsReader.getRow(i);
                            accountValue = account.Balance;
                            this.Invoke(new MethodInvoker(delegate { accountValueBox.Text = "$" + Convert.ToString(accountValue); }));
                            acctEq = account.Balance;
                            this.Invoke(new MethodInvoker(delegate { accountLevBox.Text = "$" + Convert.ToString(acctEq); }));
                            this.Invoke(new MethodInvoker(delegate { accountEquityBox.Text = "$" + Convert.ToString(acctEq); }));
                            sAccountID  = account.AccountID.ToString();
                            amountLimit = account.AmountLimit;
                            baseSize    = account.BaseUnitSize;
                            if (account.MaintenanceType == "Y")
                            {
                                this.Invoke(new MethodInvoker(delegate { hedgingBox.Text = "Yes"; }));
                                hedgingLong = true;
                                Settings.Default.hedgeLong = true;
                                hedgingShort = true;
                                Settings.Default.hedgeShort = true;
                                this.Invoke(new MethodInvoker(delegate { longCheckBox.Checked = true; }));
                                this.Invoke(new MethodInvoker(delegate { shortCheckBox.Checked = true; }));
                            }
                            else
                            {
                                this.Invoke(new MethodInvoker(delegate { hedgingBox.Text = "No"; }));
                                if (hedgingShort == false)
                                {
                                    hedgingLong = true;
                                    this.Invoke(new MethodInvoker(delegate { longCheckBox.Checked = true; }));
                                    this.Invoke(new MethodInvoker(delegate { shortCheckBox.Checked = false; }));
                                }
                                else
                                {
                                    hedgingShort = true;
                                    this.Invoke(new MethodInvoker(delegate { longCheckBox.Checked = false; }));
                                    this.Invoke(new MethodInvoker(delegate { shortCheckBox.Checked = true; }));
                                }
                            }
                        }
                    }
                }
                else
                {
                    // If table is not loaded, use createRefreshTableRequest method
                    O2GRequestFactory requestFactory = mSession.getRequestFactory();
                    if (requestFactory != null)
                    {
                        O2GRequest request = requestFactory.createRefreshTableRequest(O2GTableType.Accounts);
                        mSession.sendRequest(request);
                        Thread.Sleep(1000);
                    }
                }
            }
            catch (Exception acctErr)
            {
                Console.WriteLine(acctErr);
            }

            // Check if all 20 pairs needed are subscribed to on the account.
            try
            {
                O2GLoginRules loginRules = mSession.getLoginRules();

                if (loginRules != null && loginRules.isTableLoadedByDefault(O2GTableType.Offers))
                {
                    O2GResponse offersResponse = loginRules.getTableRefreshResponse(O2GTableType.Offers);
                    O2GResponseReaderFactory responseFactory = mSession.getResponseReaderFactory();
                    if (responseFactory != null)
                    {
                        O2GOffersTableResponseReader offersReader = responseFactory.createOffersTableReader(offersResponse);

                        for (int i = 0; i < offersReader.Count; i++)
                        {
                            O2GOfferRow offers = offersReader.getRow(i);

                            string checkOffer = offers.OfferID;
                        }
                    }
                }
            }
            catch (Exception mmrErr)
            {
                Console.WriteLine(mmrErr);
            }

            Console.WriteLine("Initializing needed table events.");
            // Initiate Table Getters
            O2GOffersTable offersTable = (O2GOffersTable)tableManager.getTable(O2GTableType.Offers);

            accountsTable = (O2GAccountsTable)tableManager.getTable(O2GTableType.Accounts);
            O2GSummaryTable      summaryTable = (O2GSummaryTable)tableManager.getTable(O2GTableType.Summary);
            O2GClosedTradesTable closedTable  = (O2GClosedTradesTable)tableManager.getTable(O2GTableType.ClosedTrades);

            // Trigger Table Events for Subscription
            offersTable.RowChanged   += new EventHandler <RowEventArgs>(offersTable_RowChanged);
            accountsTable.RowChanged += new EventHandler <RowEventArgs>(accountsTable_RowChanged);
            summaryTable.RowChanged  += new EventHandler <RowEventArgs>(summaryTable_RowChanged);
            closedTable.RowChanged   += new EventHandler <RowEventArgs>(closedTable_RowChanged);

            // Check pair subscription status, and add if needed.

            this.Invoke(new MethodInvoker(delegate { actiBox.AppendText("Connection Established.... Monitoring Pairs..." + Environment.NewLine); }));
            pastTimer.Start();
        }
Пример #12
0
        // **AFTER LOG IN**
        // Background worker for table listeners
        private void priceBW_DoWork(object sender, DoWorkEventArgs e)
        {
            Console.WriteLine("Entered BW");
            // Enable timers.
            pastTimer.Enabled = true;
            pastTimer.Start();
            oneSecTimer.Enabled = true;
            oneSecTimer.Start();

            mSession.useTableManager(O2GTableManagerMode.Yes, null);

            tableManager  = mSession.getTableManager();
            managerStatus = tableManager.getStatus();

            while (managerStatus == O2GTableManagerStatus.TablesLoading)
            {
                Console.WriteLine("Tables are loading...");
                Thread.Sleep(50);
                managerStatus = tableManager.getStatus();
            }
            if (managerStatus == O2GTableManagerStatus.TablesLoadFailed)
            {
                Console.WriteLine("Tabled loading failed");
                this.Invoke(new MethodInvoker(delegate { actiBox.AppendText("WARNING: LOADING TABLES FAILED!" + Environment.NewLine); }));
                return;
            }
            // Check Accounts Table and Grab Information
            try
            {
                O2GLoginRules loginRules = mSession.getLoginRules();
                Console.WriteLine("Tables are loaded!");
                // Check if Accounts table is loaded automatically
                if (loginRules != null && loginRules.isTableLoadedByDefault(O2GTableType.Accounts))
                {
                    Console.WriteLine("Login rules != null");
                    // If table is loaded, use getTableRefreshResponse method
                    O2GResponse accountsResponse             = loginRules.getTableRefreshResponse(O2GTableType.Accounts);
                    O2GResponseReaderFactory responseFactory = mSession.getResponseReaderFactory();
                    if (responseFactory != null)
                    {
                        Console.WriteLine("Grabbing account data....");
                        O2GAccountsTableResponseReader accountsReader = responseFactory.createAccountsTableReader(accountsResponse);

                        for (int i = 0; i < accountsReader.Count; i++)
                        {
                            account      = accountsReader.getRow(i);
                            accountValue = account.Balance;
                            this.Invoke(new MethodInvoker(delegate { accountValueBox.Text = "$" + Convert.ToString(accountValue); }));
                            availLev = account.Balance;
                            this.Invoke(new MethodInvoker(delegate { accountLevBox.Text = "$" + Convert.ToString(availLev); }));
                            sAccountID  = account.AccountID.ToString();
                            amountLimit = account.AmountLimit;
                            baseSize    = account.BaseUnitSize;
                        }
                    }
                }
                else
                {
                    // If table is not loaded, use createRefreshTableRequest method
                    O2GRequestFactory requestFactory = mSession.getRequestFactory();
                    if (requestFactory != null)
                    {
                        O2GRequest request = requestFactory.createRefreshTableRequest(O2GTableType.Accounts);
                        mSession.sendRequest(request);
                        Thread.Sleep(1000);
                    }
                }
            }
            catch (Exception acctErr)
            {
                Console.WriteLine(acctErr);
            }

            // Check if all 20 pairs needed are subscribed to on the account.
            try
            {
                O2GLoginRules loginRules = mSession.getLoginRules();

                if (loginRules != null && loginRules.isTableLoadedByDefault(O2GTableType.Offers))
                {
                    O2GResponse offersResponse = loginRules.getTableRefreshResponse(O2GTableType.Offers);
                    O2GResponseReaderFactory responseFactory = mSession.getResponseReaderFactory();
                    if (responseFactory != null)
                    {
                        Console.WriteLine("Triggering offers row");
                        O2GOffersTableResponseReader offersReader = responseFactory.createOffersTableReader(offersResponse);

                        for (int i = 0; i < offersReader.Count; i++)
                        {
                            O2GOfferRow offers = offersReader.getRow(i);

                            string checkOffer = offers.OfferID;
                        }
                    }
                }
                // Get MMR prices and set position initial cost
                Console.WriteLine("Grabbing MMR");
                this.Invoke(new MethodInvoker(delegate { actiBox.AppendText("Retrieving Pair MMR..." + Environment.NewLine); }));
                O2GTradingSettingsProvider settingResponse = loginRules.getTradingSettingsProvider();
                audcadMMR     = settingResponse.getMMR("AUD/CAD", account);
                audcadInitial = shortLot * audcadMMR;
                audjpyMMR     = settingResponse.getMMR("AUD/JPY", account);
                audjpyInitial = shortLot * audjpyMMR;
                audusdMMR     = settingResponse.getMMR("AUD/USD", account);
                audusdInitial = shortLot * audusdMMR;
                cadjpyMMR     = settingResponse.getMMR("CAD/JPY", account);
                cadjpyInitial = shortLot * cadjpyMMR;
                chfjpyMMR     = settingResponse.getMMR("CHF/JPY", account);
                chfjpyInitial = shortLot * chfjpyMMR;
                euraudMMR     = settingResponse.getMMR("EUR/AUD", account);
                euraudInitial = shortLot * euraudMMR;
                eurcadMMR     = settingResponse.getMMR("EUR/CAD", account);
                eurcadInitial = shortLot * eurcadMMR;
                eurchfMMR     = settingResponse.getMMR("EUR/CHF", account);
                eurchfInitial = shortLot * eurchfMMR;
                eurjpyMMR     = settingResponse.getMMR("EUR/JPY", account);
                eurjpyInitial = shortLot * eurjpyMMR;
                eurusdMMR     = settingResponse.getMMR("EUR/USD", account);
                eurusdInitial = shortLot * eurusdMMR;
                gbpaudMMR     = settingResponse.getMMR("GBP/AUD", account);
                gbpaudInitial = shortLot * gbpaudMMR;
                gbpchfMMR     = settingResponse.getMMR("GBP/CHF", account);
                gbpchfInitial = shortLot * gbpchfMMR;
                gbpjpyMMR     = settingResponse.getMMR("GBP/JPY", account);
                gbpjpyInitial = shortLot * gbpjpyMMR;
                gbpnzdMMR     = settingResponse.getMMR("GBP/NZD", account);
                gbpnzdInitial = shortLot * gbpnzdMMR;
                gbpusdMMR     = settingResponse.getMMR("GBP/USD", account);
                gbpusdInitial = shortLot * gbpusdMMR;
                nzdjpyMMR     = settingResponse.getMMR("NZD/JPY", account);
                nzdjpyInitial = shortLot * nzdjpyMMR;
                nzdusdMMR     = settingResponse.getMMR("NZD/USD", account);
                nzdusdInitial = shortLot * nzdusdMMR;
                usdcadMMR     = settingResponse.getMMR("USD/CAD", account);
                usdcadInitial = shortLot * usdcadMMR;
                usdchfMMR     = settingResponse.getMMR("USD/CHF", account);
                usdchfInitial = shortLot * usdchfMMR;
                usdjpyMMR     = settingResponse.getMMR("USD/JPY", account);
                usdjpyInitial = shortLot * usdjpyMMR;

                // Set highest move to 0
                highestMove = 0;

                // Set all move values to 0;
            }
            catch (Exception mmrErr)
            {
                Console.WriteLine(mmrErr);
            }

            Console.WriteLine("Initializing needed table events.");
            // Initiate Table Getters
            O2GOffersTable offersTable = (O2GOffersTable)tableManager.getTable(O2GTableType.Offers);

            accountsTable = (O2GAccountsTable)tableManager.getTable(O2GTableType.Accounts);
            O2GTradesTable tradesTable = (O2GTradesTable)tableManager.getTable(O2GTableType.Trades);

            //O2GOrdersTable ordersTable = (O2GOrdersTable)tableManager.getTable(O2GTableType.Orders);
            //O2GClosedTradesTable closedTradesTable = (O2GClosedTradesTable)tableManager.getTable(O2GTableType.ClosedTrades);
            //O2GMessagesTable messagesTable = (O2GMessagesTable)tableManager.getTable(O2GTableType.Messages);
            //O2GSummaryTable summaryTable = (O2GSummaryTable)tableManager.getTable(O2GTableType.Summary);


            // Trigger Table Events for Subscription
            offersTable.RowChanged   += new EventHandler <RowEventArgs>(offersTable_RowChanged);
            accountsTable.RowChanged += new EventHandler <RowEventArgs>(accountsTable_RowChanged);
            tradesTable.RowChanged   += new EventHandler <RowEventArgs>(tradesTable_RowChanged);
            //ordersTable.RowChanged += new EventHandler<RowEventArgs>(ordersTable_RowChanged);
            //closedTradesTable.RowChanged += new EventHandler<RowEventArgs>(closedTradesTable_RowChanged);
            //messagesTable.RowChanged += new EventHandler<RowEventArgs>(messagesTable_RowChanged);
            //summaryTable.RowChanged += new EventHandler<RowEventArgs>(summaryTable_RowChanged);

            // Check pair subscription status, and add if needed.

            this.Invoke(new MethodInvoker(delegate { actiBox.AppendText("Connection Established.... Monitoring Pairs..." + Environment.NewLine); }));
            // Start Past Price Timer
            pastTimer.Start();
        }
 void IO2GResponseListener.onTablesUpdates(O2GResponse response)
 {
     if (response.Type == O2GResponseType.GetOffers || response.Type == O2GResponseType.TablesUpdates)
     {
         O2GResponseReaderFactory factory = mSession.getResponseReaderFactory();
         if (factory != null)
         {
             O2GOffersTableResponseReader reader = factory.createOffersTableReader(response);
             for (int i = 0; i < reader.Count; i++)
             {
                 O2GOfferRow row   = reader.getRow(i);
                 Offer       offer = null;
                 mOffers.TryGetValue(row.OfferID, out offer);
                 if (offer == null)
                 {
                     if (row.isInstrumentValid && row.isTimeValid && row.isBidValid && row.isAskValid &&
                         row.isVolumeValid && row.isDigitsValid && row.isPointSizeValid)
                     {
                         //mTimeConverter.convert(row.Time, O2GTimeConverterTimeZone.UTC, mTimezone)
                         //DateTime dt = mTimeConverter.convert(row.Time, O2GTimeConverterTimeZone.Server, O2GTimeConverterTimeZone.UTC);
                         DateTime dt = row.Time;
                         offer = new Offer(row.Instrument, dt, row.Bid, row.Ask, row.Volume, row.Digits, row.PointSize);
                         mOffers[row.OfferID] = offer;
                         mOffersList.Add(offer);
                         SendTick(offer);
                     }
                 }
                 else
                 {
                     if (row.isTimeValid)
                     {
                         //mTimeConverter.convert(row.Time, O2GTimeConverterTimeZone.UTC, mTimezone)
                         //DateTime dt = mTimeConverter.convert(row.Time, O2GTimeConverterTimeZone.Server, O2GTimeConverterTimeZone.UTC);
                         DateTime dt = row.Time;
                         offer.Time = dt;
                     }
                     if (row.isBidValid)
                     {
                         offer.Bid = row.Bid;
                     }
                     if (row.isAskValid)
                     {
                         offer.Ask = row.Ask;
                     }
                     if (row.isVolumeValid)
                     {
                         offer.Volume = row.Volume;
                     }
                     if (row.isPointSizeValid)
                     {
                         offer.PointSize = row.PointSize;
                     }
                     if (row.isDigitsValid)
                     {
                         offer.Precision = row.Digits;
                     }
                     SendTick(offer);
                 }
             }
         }
     }
 }