private void SubscribeChannelsForSymbol(ComboBox CBox, bool Subscribe)
        {
            // Note: it is benign to Subscribe and already Subscribed symbol
            string Symbol = CBox.Text;

            if (string.IsNullOrEmpty(Symbol))
            {
                return;
            }

            string ClusterName = CBox.Tag as string;

            PGClusterBase Cluster = PGApi.GetPGCluster(ClusterName);

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

            // check for PGApi Cluster ready
            if (!Cluster.PGStatus.PGLogonSucceeded)
            {
                AppendText($"{ClusterName} has not been started (use the Start button)");
            }

            if (Subscribe)
            {
                Cluster.SubscribeSymbol(Symbol);
            }
            else
            {
                Cluster.UnSubscribeSymbol(Symbol);
            }
        }
        private void OnClusterComboBoxKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                ComboBox CBox        = (sender as ComboBox);
                string   ClusterName = CBox.Tag as string;
                string   Symbol      = CBox.Text;

                if (!string.IsNullOrEmpty(Symbol))
                {
                    List <string> SymbolsList = CBox.ItemsSource as List <string>;

                    // is Symbol already there?
                    if (SymbolsList.Contains(Symbol))
                    {
                        PGClusterBase Cluster      = PGApi.GetCluster(ClusterName);
                        bool          IsSubscribed = Cluster.IsSymbolSubscribed(Symbol);

                        // Subscribe on Enter
                        if (!IsSubscribed)
                        {
                            SubscribeChannelsForSymbol(CBox, true);
                        }
                    }
                    else if (!string.IsNullOrEmpty(Symbol))
                    {
                        // add a new Symbol
                        SymbolsList.Add(Symbol);
                        SymbolsList.Sort();
                        SubscribeChannelsForSymbol(CBox, true);
                    }
                    e.Handled = true;
                }
            }
        }
        private void InitConfig()
        {
            try
            {
                // load app's json config file
                configHelper.LoadConfig();

                // Note: data is read from json\PGDemoConfig.json
                appValues = ConfigHelper.Instance.appConfig.appValues;

                // check for hard-coded ApiKey
                if (string.IsNullOrEmpty(ApiKey))
                {
                    ApiKey = appValues.ApiKey;
                }
                // check for ApiKey in config file
                if (!string.IsNullOrEmpty(ApiKey))
                {
                    PGApi.SetApiKey(ApiKey);
                }

                // VerboseInfo will provide more text info
                VerboseInfo         = appValues.VerboseInfo;
                CloseWindowOnEscape = appValues.CloseWindowOnEscape;
            }
            catch (System.Exception ex)
            {
                string ErrorMessage = $"InitConfig() error: {ex.Message}";
                Debug.WriteLine(ErrorMessage);
            }
        }
 private void OnApiKeyEntered(string ApiKey)
 {
     if (!string.IsNullOrEmpty(ApiKey))
     {
         ApiKeyText.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("LightGreen"));
         PGApi.SetApiKey(ApiKey);
         IsPaused = false;
         StartApp();
     }
 }
        private void OnRTDataRowMouseDoubleClick(string ClusterName, string Symbol)
        {
            PGClusterBase Cluster      = PGApi.GetCluster(ClusterName);
            bool          IsSubscribed = Cluster.IsSymbolSubscribed(Symbol);

            // UnSubscribe on RTDataRow DoubleClick
            if (IsSubscribed)
            {
                Cluster.UnSubscribeSymbol(Symbol);
            }
        }
示例#6
0
 public static float[,] Generate2DMapUnity(int width, int height, float scale, float offsetX, float offsetY)
 {
     float[,] noiseMap = new float[width, height];
     for (int y = 0; y < height; y++)
     {
         for (int x = 0; x < width; x++)
         {
             float xCoord = (float)x / width * scale + offsetX;
             float yCoord = (float)y / height * scale + offsetY;
             noiseMap[x, y] = PGApi.ZgomotulPerlin_Îmbunătățit2D(xCoord, yCoord);
         }
     }
     return(noiseMap);
 }
        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);
        }
        private void OnApiKeyPaste(object sender, DataObjectPastingEventArgs e)
        {
            var IsText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true);

            if (!IsText)
            {
                return;
            }

            string ApiKey = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string;

            PGApi.SetApiKey(ApiKey);

            e.Handled = true;
        }
        private void OnClusterComboBoxDropDownClosed(object sender, EventArgs e)
        {
            ComboBox CBox        = (sender as ComboBox);
            string   ClusterName = CBox.Tag as string;
            string   Symbol      = CBox.Text;

            if (!string.IsNullOrEmpty(Symbol))
            {
                PGClusterBase Cluster      = PGApi.GetCluster(ClusterName);
                bool          IsSubscribed = Cluster.IsSymbolSubscribed(Symbol);
                if (IsSubscribed)
                {
                    return;
                }

                SubscribeChannelsForSymbol((sender as ComboBox), true);
            }
        }
        private void InitPolygonWPFDemo()
        {
            PGBase.Dispatcher = dispatcher;

            // capture initial RTDataGridHeight
            RTDataGridHeight = RTDataControlsGrid.Height;
            DisplayRTDataGrid(false, false);

            // local initialization
            PGApi.SetVerboseInfo(VerboseInfo);

            InitEquitiesUI();
            InitForexUI();
            InitCryptoUI();

            // PGApi initialization
            PGApi.InitPGClusters();
            PGApi.InitEvents();

            InitPGClusterEvents();

            // Note: optional, used for consolidated Trade/Quote
            // unused in this app
            PGApi.Equities.SetConsolidateLevel1(true);

            InitClearTextPrompt();
            InitEvents();

            // realtime data initialization
            InitClustersRTData();

            if (!string.IsNullOrEmpty(ApiKey))
            {
                OnApiKeyEntered(ApiKey);
            }
        }
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     PGApi.TerminateApiInterface();
 }
 private void UnSubscribeAll(object sender, RoutedEventArgs e)
 {
     PGApi.UnSubscribeAllChannels();
 }
        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);
            }
        }