コード例 #1
0
        /*  This is the security type. Valid values are:
         *  STK
         *  OPT
         *  FUT
         *  IND
         *  FOP
         *  CASH
         *  BAG
         */
        private void RequestMarketData(params Currencies[] symbols)
        {
            m_tickers = new ForexTicker[symbols.Length, symbols.Length];
            m_a       = new Matrix(symbols.Length, symbols.Length);
            m_b       = new Matrix(symbols.Length, symbols.Length);
            m_c       = new Matrix(symbols.Length, symbols.Length);

            myGrid.Children.Clear();
            myGrid.RowDefinitions.Clear();
            myGrid.ColumnDefinitions.Clear();

            myGrid.RowDefinitions.Add(new RowDefinition());
            myGrid.ColumnDefinitions.Add(new ColumnDefinition());
            int OFFSET = 1;

            for (int i = 0; i < symbols.Length; i++)
            {
                for (int j = 0; j < symbols.Length; j++)
                {
                    if (i == 0)
                    {
                        myGrid.ColumnDefinitions.Add(new ColumnDefinition());
                        Label lbl = new Label();
                        lbl.Content = symbols[j];
                        Grid.SetRow(lbl, 0);
                        Grid.SetColumn(lbl, j + OFFSET);
                        myGrid.Children.Add(lbl);
                    }

                    if (j == 0)
                    {
                        myGrid.RowDefinitions.Add(new RowDefinition());
                        Label lbl = new Label();
                        lbl.Content = symbols[i];
                        Grid.SetRow(lbl, i + OFFSET);
                        Grid.SetColumn(lbl, 0);
                        myGrid.Children.Add(lbl);
                    }

                    if (i != j)
                    {
                        ForexTicker ticker = new ForexTicker(i, j, symbols[i], symbols[j]);
                        Grid.SetRow(ticker, i + OFFSET);
                        Grid.SetColumn(ticker, j + OFFSET);
                        myGrid.Children.Add(ticker);
                        m_tickers[i, j] = ticker;

                        if (m_tws.serverVersion > 0)
                        {
                            if (ticker.IsNormalized)
                            {
                                m_tws.reqMktData2(ticker.Id, ticker.LocalSymbol, "CASH", "SMART", "IDEALPRO", ticker.LocalCurrency, Contract.GENERIC_TICK_TAGS, 0);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        private void m_tws_tickPrice(int id, int tickType, double price, int canAutoExecute)
        {
            int i = id & 0xFFFF;
            int j = (id >> 16) & 0xFFFF;

            ForexTicker ticker = m_tickers[i, j];

            if (ticker != null)
            {
                ticker.Price = price;
            }

            ticker = m_tickers[j, i];
            if (ticker != null)
            {
                ticker.Price = price;
            }
        }
コード例 #3
0
        private void m_tws_errMsg(int id, int errorCode, string errorMsg)
        {
            StatusError(errorMsg + " [" + id + ":" + errorCode + "]");

            if (errorCode == NO_SECURITY_DEF_FOUND)
            {
                int i = id & 0xFFFF;
                int j = (id >> 16) & 0xFFFF;


                ForexTicker ticker = m_tickers[i, j];
                if (ticker != null)
                {
                    ticker.Price = 1;
                    //myGrid.Children.Remove(ticker);
                    //m_tickers[i, j] = null;
                }
            }
        }
コード例 #4
0
        private void CalculateA()
        {
            if (!CanCalculateArbitrage())
            {
                return;
            }

            Dispatcher.Invoke(() =>
            {
                for (int i = 0; i < m_tickers.GetLength(0); i++)
                {
                    for (int j = 0; j < m_tickers.GetLength(1); j++)
                    {
                        ForexTicker tickerLeft  = m_tickers[i, j];
                        ForexTicker tickerRight = m_tickers[j, i];
                        m_a[i, j] = tickerLeft != null && tickerRight != null ? tickerLeft.Price : 1;
                    }
                }
            });
        }
コード例 #5
0
        private void client_RateTick(int id, DateTime dt, double bid, double ask, double price, bool dealable)
        {
            int i = id & 0xFFFF;
            int j = (id >> 16) & 0xFFFF;

            Dispatcher.Invoke(() =>
            {
                ForexTicker ticker = m_tickers[i, j];
                if (ticker != null)
                {
                    ticker.Price = price;
                }

                ticker = m_tickers[j, i];
                if (ticker != null)
                {
                    ticker.Price = price;
                }
            });
        }
コード例 #6
0
        /*  This is the security type. Valid values are:
            STK
            OPT
            FUT
            IND
            FOP
            CASH
            BAG
         */
        private void RequestMarketData(params Currencies[] symbols)
        {
            m_tickers = new ForexTicker[symbols.Length, symbols.Length];
            m_a = new Matrix(symbols.Length, symbols.Length);
            m_b = new Matrix(symbols.Length, symbols.Length);
            m_c = new Matrix(symbols.Length, symbols.Length);

            myGrid.Children.Clear();
            myGrid.RowDefinitions.Clear();
            myGrid.ColumnDefinitions.Clear();

            myGrid.RowDefinitions.Add(new RowDefinition());
            myGrid.ColumnDefinitions.Add(new ColumnDefinition());
            int OFFSET = 1;

            for (int i = 0; i < symbols.Length; i++)
            {
                for (int j = 0; j < symbols.Length; j++)
                {
                    if (i == 0)
                    {
                        myGrid.ColumnDefinitions.Add(new ColumnDefinition());
                        Label lbl = new Label();
                        lbl.Content = symbols[j];
                        Grid.SetRow(lbl, 0);
                        Grid.SetColumn(lbl, j + OFFSET);
                        myGrid.Children.Add(lbl);
                    }

                    if (j == 0)
                    {
                        myGrid.RowDefinitions.Add(new RowDefinition());
                        Label lbl = new Label();
                        lbl.Content = symbols[i];
                        Grid.SetRow(lbl, i + OFFSET);
                        Grid.SetColumn(lbl, 0);
                        myGrid.Children.Add(lbl);
                    }

                    if (i != j)
                    {
                        ForexTicker ticker = new ForexTicker(i, j, symbols[i], symbols[j]);
                        Grid.SetRow(ticker, i + OFFSET);
                        Grid.SetColumn(ticker, j + OFFSET);
                        myGrid.Children.Add(ticker);
                        m_tickers[i,j] = ticker;

                        if (m_tws.serverVersion > 0)
                        {
                            if (ticker.IsNormalized) m_tws.reqMktData2(ticker.Id, ticker.LocalSymbol, "CASH", "SMART", "IDEALPRO", ticker.LocalCurrency, Contract.GENERIC_TICK_TAGS, 0);
                        }
                    }
                }
            }
        }