示例#1
0
        internal void AddSymbolRTDataRow(RTDataRec rtDataRec)
        {
            RTDataRowBase RTDataRow = RTDataRows.Find(x => x.Symbol == rtDataRec.Symbol);

            if (RTDataRow == null)
            {
                switch (ClusterName)
                {
                case PGClusterNames.Equities:
                    RTDataRow = new RTEquitiesDataRow(rtDataRec.Symbol);
                    break;

                case PGClusterNames.Forex:
                    RTDataRow = new RTForexDataRow(rtDataRec.Symbol);
                    break;

                case PGClusterNames.Crypto:
                    RTDataRow = new RTCryptoDataRow(rtDataRec.Symbol);
                    break;

                default:
                    throw new Exception($"Unknown ClusterName: {ClusterName}");
                }

                RTDataRow.RowDef = new RowDefinition();
                RTDataRow.OnRTDataRowMouseDoubleClickEvent += FireOnRTDataRowMouseDoubleClick;
                RTDataRows.Add(RTDataRow);

                // binding
                RTDataRow.DataContext = rtDataRec;

                InitRTDataRows();
                SetRTClusterDataGridHeight();
            }
        }
        private void OnSubscribedSymbol(RTDataRec rtDataRec)
        {
            switch (rtDataRec.ClusterName)
            {
            case PGClusterNames.Equities:
                EquitiesRTData.AddSymbolRTDataRow(rtDataRec);
                EquitiesRTData.Visibility = Visibility.Visible;
                break;

            case PGClusterNames.Forex:
                ForexRTData.AddSymbolRTDataRow(rtDataRec);
                ForexRTData.Visibility = Visibility.Visible;
                break;

            case PGClusterNames.Crypto:
                CryptoRTData.AddSymbolRTDataRow(rtDataRec);
                CryptoRTData.Visibility = Visibility.Visible;
                break;

            default:
                throw new Exception($"Unknown ClusterName: {rtDataRec.ClusterName}");
            }

            DisplayRTDataGrid(true);

            if (rtDataRec.RequestLast)
            {
                RequestLast(rtDataRec);
            }
        }
        private void HandleInvalidSymbol(RTDataRec rtDataRec)
        {
            AppendText($"{rtDataRec.Symbol} is an invalid symbol", true);

            PGClusterBase Cluster = PGApi.GetPGCluster(rtDataRec.ClusterName);

            if (Cluster == null)
            {
                throw new Exception($"Unknown ClusterName: {rtDataRec.ClusterName}");
            }

            Cluster.RemoveSymbol(rtDataRec.Symbol);
            RTDataHelper.Instance.RemoveRTData(rtDataRec);
        }
示例#4
0
        internal void RemoveSymbolRTDataRow(RTDataRec rtDataRec)
        {
            RTDataRowBase RTDataRow = RTDataRows.Find(x => x.Symbol == rtDataRec.Symbol);

            if (RTDataRow != null)
            {
                RTDataRow.OnRTDataRowMouseDoubleClickEvent -= FireOnRTDataRowMouseDoubleClick;
                RTDataRow.DataContext = null;

                RTDataRows.Remove(RTDataRow);

                InitRTDataRows();
                SetRTClusterDataGridHeight();
            }
        }
        private void OnUnSubscribedSymbol(RTDataRec rtDataRec)
        {
            switch (rtDataRec.ClusterName)
            {
            case PGClusterNames.Equities:
                EquitiesRTData.RemoveSymbolRTDataRow(rtDataRec);
                if (EquitiesRTData.RTDataRows.Count == 0)
                {
                    EquitiesRTData.Visibility = Visibility.Collapsed;
                }
                break;

            case PGClusterNames.Forex:
                ForexRTData.RemoveSymbolRTDataRow(rtDataRec);
                if (ForexRTData.RTDataRows.Count == 0)
                {
                    ForexRTData.Visibility = Visibility.Collapsed;
                }
                break;

            case PGClusterNames.Crypto:
                CryptoRTData.RemoveSymbolRTDataRow(rtDataRec);
                if (CryptoRTData.RTDataRows.Count == 0)
                {
                    CryptoRTData.Visibility = Visibility.Collapsed;
                }
                break;

            default:
                throw new Exception($"Unknown ClusterName: {rtDataRec.ClusterName}");
            }

            int TotalRows = EquitiesRTData.RTDataRows.Count + ForexRTData.RTDataRows.Count + CryptoRTData.RTDataRows.Count;

            if (TotalRows == 0)
            {
                DisplayRTDataGrid(false);
            }
        }
        private void RequestLast(RTDataRec rtDataRec)
        {
            AppendText($"Request Last for {rtDataRec.Symbol}");

            switch (rtDataRec.ClusterName)
            {
            case PGClusterNames.Equities:
                LastTrade lastTrade = PGApi.Equities.RequestLastTrade(rtDataRec.Symbol);
                if (lastTrade != null)
                {
                    // check invalid symbol
                    if (lastTrade.status == PGStatusMessages.NotFound)
                    {
                        HandleInvalidSymbol(rtDataRec);
                    }
                    else if (lastTrade != null && lastTrade.last != null)
                    {
                        rtDataRec.Price    = lastTrade.last.price;
                        rtDataRec.LastSize = lastTrade.last.size;
                    }
                }

                LastQuote LastQuote = PGApi.Equities.RequestLastQuote(rtDataRec.Symbol);
                if (LastQuote != null)
                {
                    if (LastQuote != null && LastQuote.last != null)
                    {
                        rtDataRec.Ask = LastQuote.last.askprice;
                        rtDataRec.Bid = LastQuote.last.bidprice;
                    }
                }
                break;

            case PGClusterNames.Forex:
                ForexLastQuote ForexLastquote = PGApi.Forex.RequestForexLastQuote(rtDataRec.Symbol);
                if (ForexLastquote != null)
                {
                    // check invalid symbol
                    if (ForexLastquote.status == PGStatusMessages.NotFound)
                    {
                        HandleInvalidSymbol(rtDataRec);
                    }
                    else if (ForexLastquote != null && ForexLastquote.last != null)
                    {
                        rtDataRec.Ask = ForexLastquote.last.ask;
                        rtDataRec.Bid = ForexLastquote.last.bid;
                    }
                }
                break;

            case PGClusterNames.Crypto:
                CryptoLastTrade CryptoLasttrade = PGApi.Crypto.RequestCryptoLastTrade(rtDataRec.Symbol);
                if (CryptoLasttrade != null)
                {
                    // check invalid symbol
                    if (CryptoLasttrade.status == PGStatusMessages.NotFound)
                    {
                        HandleInvalidSymbol(rtDataRec);
                    }
                    else if (CryptoLasttrade != null && CryptoLasttrade.last != null)
                    {
                        rtDataRec.Price      = CryptoLasttrade.last.price;
                        rtDataRec.CryptoSize = CryptoLasttrade.last.size;
                    }
                }
                break;

            default:
                throw new Exception($"Unknown ClusterName: {rtDataRec.ClusterName}");
            }

            // get Previous values
            PGClusterBase Cluster = PGApi.GetPGCluster(rtDataRec.ClusterName);

            if (Cluster != null)
            {
                Cluster.RequestPreviousClose(rtDataRec.Symbol);
                Cluster.RequestDailyOpenClose(rtDataRec.Symbol);
            }
        }