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; } } }
public void AddToPGClusters(PGClusterBase PGCluster) { if (!PGClusters.Contains(PGCluster)) { PGClusters.Add(PGCluster); } }
private void StartCluster(PGClusterBase Cluster) { if (!Cluster.PGStatus.PGLogonSucceeded) { AppendText($"Starting...{Cluster.ClusterName}"); Cluster.Start(); } }
public void StartPGCluster(string ClusterName) { PGClusterBase PGCluster = GetPGCluster(ClusterName); if (PGCluster != null) { PGCluster.Start(); } }
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); } }
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 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 string SubscribeClusterSymbolChannels(PGClusterBase Cluster, List <string> Symbols, List <string> Channels) { // format Params by adding Channel.Symbol for each Symbol string Params = string.Empty; foreach (var Symbol in Symbols) { Params = string.Empty; foreach (var Channel in Channels) { Params += $"{Channel}.{Symbol},"; } AppendText($"Subscribing to {Params}"); Cluster.SendSubscribeMessage(Params); } return(Params.TrimEnd(',')); }
public PGClusterBase GetCluster(string ClusterName) { PGClusterBase Cluster = null; switch (ClusterName) { case PGClusterNames.Equities: Cluster = Equities; break; case PGClusterNames.Forex: Cluster = Forex; break; case PGClusterNames.Crypto: Cluster = Crypto; break; default: throw new Exception($"Unknown ClusterName: {ClusterName}"); } return(Cluster); }
internal void InitRTClusterData(PGClusterBase Cluster) { this.Cluster = Cluster; ClusterNameTextBlock.Text = ClusterName = Cluster.ClusterName; }
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); } }
public PGClusterBase GetPGCluster(string ClusterName) { PGClusterBase PGCluster = PGClusters.Find(x => x.ClusterName == ClusterName); return(PGCluster); }