Пример #1
0
        private void TryDisconnect()
        {
            RunOnUiThread(() =>
            {
                m_timerUpdateQuote.Enabled = false;
            });

            MT4Ctrl1.BeginDisconnect();
            MT4Ctrl2.BeginDisconnect();

            bWorking = false;
            MT4CurrentState CurrentState = new MT4CurrentState();

            WSNode.SendDataToUser("MT4CurrentState", CurrentState);
        }
Пример #2
0
        public void On_Terminal1_QuoteUpdate(MtQuote quote)
        {
            if (_isUiQuoteUpdateReady)
            {
                _isUiQuoteUpdateReady = false;
                RunOnUiThread(() =>
                {
                    m_txtSymbol1.Text       = MT4Ctrl1.currentQuote.Instrument;
                    m_txtBid1.Text          = MT4Ctrl1.currentQuote.Bid.ToString(CultureInfo.CurrentCulture);
                    m_txtAsk1.Text          = MT4Ctrl1.currentQuote.Ask.ToString(CultureInfo.CurrentCulture);
                    m_txtExpertHandle1.Text = MT4Ctrl1.currentQuote.ExpertHandle.ToString();

                    MT4CurrentState CurrentQuoteState = new MT4CurrentState();
                    CurrentQuoteState.Symbol1         = m_txtSymbol1.Text;
                    CurrentQuoteState.Bid1            = m_txtBid1.Text;
                    CurrentQuoteState.Ask1            = m_txtAsk1.Text;
                    CurrentQuoteState.ExpertHandle1   = m_txtExpertHandle1.Text;

                    WSNode.SendDataToUser("TerminalUpdate1", CurrentQuoteState);
                });
                _isUiQuoteUpdateReady = true;
            }
            nCurSpread1 = (int)MT4Ctrl1.GetSymbolSpread(quote.Instrument);
            if (bWorking)
            {
                if (CanRebalance())
                {
                    TryReBalance();
                }
                //nCurSpread1 = (int)(quote.Ask * 100000) - (int)(quote.Bid * 100000);
                if (nCurSpread1 == nCurSpread2 && nCurSpread1 < nSpreadOpenThreshold)
                {
                    DoOpenOrder();
                }
            }
            if (bCloseOrderWorking)
            {
                if (nCurSpread1 == nCurSpread2 && nCurSpread1 < nSpreadCloseThreshold)
                {
                    DoCloseOrder();
                }
            }
        }
Пример #3
0
        private void UpdatedCurrentQuote()
        {
            if (_isUiQuoteUpdateReady)
            {
                _isUiQuoteUpdateReady = false;
                RunOnUiThread(() => {
                    MT4CurrentState CurrentState = new MT4CurrentState();

                    m_txtSymbol1.Text       = MT4Ctrl1.currentQuote.Instrument;
                    m_txtBid1.Text          = MT4Ctrl1.currentQuote.Bid.ToString(CultureInfo.CurrentCulture);
                    m_txtAsk1.Text          = MT4Ctrl1.currentQuote.Ask.ToString(CultureInfo.CurrentCulture);
                    m_txtExpertHandle1.Text = MT4Ctrl1.currentQuote.ExpertHandle.ToString();

                    CurrentState.Symbol1       = m_txtSymbol1.Text;
                    CurrentState.Bid1          = m_txtBid1.Text;
                    CurrentState.Ask1          = m_txtAsk1.Text;
                    CurrentState.ExpertHandle1 = m_txtExpertHandle1.Text;

                    if (MT4Ctrl1.bAvailable)
                    {
                        if (mtOrderBindingSource.DataSource != MT4Ctrl1.listOrders)
                        {
                            mtOrderBindingSource.DataSource = MT4Ctrl1.listOrders;
                            WSNode.SendDataToUser("TerminalOrders1", MT4Ctrl1.listOrders);
                        }
                    }
                    else
                    {
                        m_dataGridOpenOrders1.DataSource = null;
                    }

                    m_txtBalance1.Text    = MT4Ctrl1.AccountBalance.ToString();
                    m_txtEquity1.Text     = MT4Ctrl1.AccountEquity.ToString();
                    m_txtFreeMargin1.Text = MT4Ctrl1.AccountFreeMargin.ToString();
                    m_txtMargin1.Text     = MT4Ctrl1.AccountMargin.ToString();
                    m_txtProfit1.Text     = MT4Ctrl1.AccountProfit.ToString();
                    m_txtSwapBuy1.Text    = MT4Ctrl1.dSwapBuy.ToString();
                    m_txtSwapSell1.Text   = MT4Ctrl1.dSwapSell.ToString();
                    m_txtAccountNo1.Text  = MT4Ctrl1.AccountNumber.ToString();

                    CurrentState.Balance1    = m_txtBalance1.Text;
                    CurrentState.Equity1     = m_txtEquity1.Text;
                    CurrentState.FreeMargin1 = m_txtFreeMargin1.Text;
                    CurrentState.Margin1     = m_txtMargin1.Text;
                    CurrentState.Profit1     = m_txtProfit1.Text;
                    CurrentState.Swap_Buy1   = m_txtSwapBuy1.Text;
                    CurrentState.Swap_Sell1  = m_txtSwapSell1.Text;
                    CurrentState.Account_No1 = m_txtAccountNo1.Text;


                    m_txtSymbol2.Text       = MT4Ctrl2.currentQuote.Instrument;
                    m_txtBid2.Text          = MT4Ctrl2.currentQuote.Bid.ToString(CultureInfo.CurrentCulture);
                    m_txtAsk2.Text          = MT4Ctrl2.currentQuote.Ask.ToString(CultureInfo.CurrentCulture);
                    m_txtExpertHandle2.Text = MT4Ctrl2.currentQuote.ExpertHandle.ToString();

                    CurrentState.Symbol2       = m_txtSymbol2.Text;
                    CurrentState.Bid2          = m_txtBid2.Text;
                    CurrentState.Ask2          = m_txtAsk2.Text;
                    CurrentState.ExpertHandle2 = m_txtExpertHandle2.Text;

                    if (MT4Ctrl2.bAvailable)
                    {
                        if (mtOrderBindingSource1.DataSource != MT4Ctrl2.listOrders)
                        {
                            mtOrderBindingSource1.DataSource = MT4Ctrl2.listOrders;
                            WSNode.SendDataToUser("TerminalOrders2", MT4Ctrl2.listOrders);
                        }
                    }
                    else
                    {
                        m_dataGridOpenOrders2.DataSource = null;
                    }

                    m_txtBalance2.Text    = MT4Ctrl2.AccountBalance.ToString();
                    m_txtEquity2.Text     = MT4Ctrl2.AccountEquity.ToString();
                    m_txtFreeMargin2.Text = MT4Ctrl2.AccountFreeMargin.ToString();
                    m_txtMargin2.Text     = MT4Ctrl2.AccountMargin.ToString();
                    m_txtProfit2.Text     = MT4Ctrl2.AccountProfit.ToString();
                    m_txtSwapBuy2.Text    = MT4Ctrl2.dSwapBuy.ToString();
                    m_txtSwapSell2.Text   = MT4Ctrl2.dSwapSell.ToString();
                    m_txtAccountNo2.Text  = MT4Ctrl2.AccountNumber.ToString();

                    CurrentState.Balance2    = m_txtBalance2.Text;
                    CurrentState.Equity2     = m_txtEquity2.Text;
                    CurrentState.FreeMargin2 = m_txtFreeMargin2.Text;
                    CurrentState.Margin2     = m_txtMargin2.Text;
                    CurrentState.Profit2     = m_txtProfit2.Text;
                    CurrentState.Swap_Buy2   = m_txtSwapBuy2.Text;
                    CurrentState.Swap_Sell2  = m_txtSwapSell2.Text;
                    CurrentState.Account_No2 = m_txtAccountNo2.Text;

                    if (MT4Ctrl1.bAvailable)
                    {
                        if (MT4Ctrl1.bIsWithSwap)
                        {
                            m_lblSwapState1.ForeColor = Color.Yellow;
                            m_lblSwapState1.Text      = "This Account get Swap Mode!";
                        }
                        else
                        {
                            m_lblSwapState1.ForeColor = Color.Blue;
                            m_lblSwapState1.Text      = "This Account don't get Swap Mode!";
                        }
                    }
                    else
                    {
                        m_lblSwapState1.Text = "";
                    }

                    if (MT4Ctrl2.bAvailable)
                    {
                        if (MT4Ctrl2.bIsWithSwap)
                        {
                            m_lblSwapState2.ForeColor = Color.Yellow;
                            m_lblSwapState2.Text      = "This Account get Swap Mode!";
                        }
                        else
                        {
                            m_lblSwapState2.ForeColor = Color.Blue;
                            m_lblSwapState2.Text      = "This Account don't get Swap Mode!";
                        }
                    }
                    else
                    {
                        m_lblSwapState2.Text = "";
                    }

                    if (MT4Ctrl1.bAvailable == false)
                    {
                        m_dataGridOpenOrders1.DataSource = null;
                    }
                    if (MT4Ctrl2.bAvailable == false)
                    {
                        m_dataGridOpenOrders2.DataSource = null;
                    }
                    if (MT4Ctrl1.bAvailable == false && MT4Ctrl2.bAvailable == false)
                    {
                        m_comboCurrencyPairs.Items.Clear();
                    }

                    //SendData To Socket!!!
                    WSNode.SendDataToUser("MT4CurrentState", CurrentState);
                });
                _isUiQuoteUpdateReady = true;
            }
        }