static void stock_PriceChanged(object sender, PriceChangedEventArgs e) { if ((e.newPrice - e.lastPrice) / e.lastPrice > 0.1M) { Console.WriteLine("Alert, 10% stock price increase!"); } }
protected virtual void OnPriceChanged(PriceChangedEventArgs е) { if (PriceChanged != null) { PriceChanged(this, е); } }
private static void Stock2_PriceChanged(object sender, PriceChangedEventArgs e) { if ((e.NewPrice - e.LastPrice) / e.LastPrice > 0.1M) { Console.WriteLine("Alert, 10% price increase!"); } }
void item_BuyPriceChanged(object sender, PriceChangedEventArgs e) { if (BuyPriceChanged != null) { BuyPriceChanged(sender, e); } }
void item_ItemBuild(object sender, PriceChangedEventArgs e) { if (ItemBuild != null) { ItemBuild(sender, e); } }
void item_SellPriceChanged(object sender, PriceChangedEventArgs e) { if (SellPriceChanged != null) { SellPriceChanged(sender, e); } }
public void Client_OnPriceChanged(object sender, PriceChangedEventArgs e) { //Check if Price client is raising events with valid data . //i.e. simple test check if symbol is always present Assert.IsTrue(e.Symbol != ""); privateObject.Invoke("ProcessData", ConvertEventObjectToStock(e)); }
public void TestCoreDataProcessorWithMockClient() { var mock = new Mock <IPriceClient>(); mock.Object.OnPriceChanged += Client_OnPriceChanged; var priceChangedEvent = new PriceChangedEventArgs("A", 10, 20.3m, 21.3m, 11); mock.Raise(item => item.OnPriceChanged += null, "sender", priceChangedEvent); var list = (BindingList <Stock>)privateObject.GetField("_stocks"); //1. Check if the processed object in the bindinglist is the same as the event Assert.AreEqual(list[0], ConvertEventObjectToStock(priceChangedEvent)); //2. Raise another event and check if the list contains the new object at index 1 var priceChangedEvent1 = new PriceChangedEventArgs("B", 11, 20.4m, 21.3m, 11); mock.Raise(item => item.OnPriceChanged += null, "sender", priceChangedEvent1); list = (BindingList <Stock>)privateObject.GetField("_stocks"); Assert.AreEqual(list[1], ConvertEventObjectToStock(priceChangedEvent1)); //3. Raise an event which updates the exisiting entry in the list @ index 0 var priceChangedEvent2 = new PriceChangedEventArgs("A", 211, 26.4m, 21.3m, 110); mock.Raise(item => item.OnPriceChanged += null, "sender", priceChangedEvent2); list = (BindingList <Stock>)privateObject.GetField("_stocks"); Assert.AreEqual(list[0], ConvertEventObjectToStock(priceChangedEvent2)); }
private void PriceClient_OnPriceChanged(object sender, PriceChangedEventArgs e) { #if DEBUG Debug.WriteLine($"Price changed.. Symbol {e.Symbol}, BidQty {e.BidQty}, BidPrice {e.BidPrice}, AskQty {e.AskQty}, AskPrice {e.AskPrice}"); #endif var stock = new Stock() { Symbol = e.Symbol, AskPrice = e.AskPrice, BidPrice = e.BidPrice, AskQty = e.AskQty, BidQty = e.BidQty }; if (_useMsgQueue) { /* * If Producer outpaces the consumer, then one can see a slight delay but the queue is * acting as a buffer for the messages and it's assumed that this is acceptable. If not, * then, the UseMessageQueue flag should be set to false in App.Config and the program should be rerun. * * With Producer-Consumer queue, the task cancels will take a while i.e. consumer queue should * become empty after which the program stops updating the grid * */ _queue.Add(stock); } else { /* This snippet of code will bypass the usage of concurrent queue which speeds up * the consumption of data and response to stop task is instantaneous*/ ProcessData(stock); } }
private void OnPriceChanged(IGFClient client, PriceChangedEventArgs e) { if (e.Contract.ID == SubscribedContract.ID) { UpdatePrice(); } }
static void StockPriceChanged(object sender, PriceChangedEventArgs e) { if ((e.NewPrice - e.LastPrice) / e.LastPrice > 0.1M) { WriteLine("Alert, 10% stock price increase!"); } }
static void stock_PriceChanged(object sender, PriceChangedEventArgs e) { decimal percent = (e.NewPrice - e.LastPrice) / e.LastPrice; if (percent > 0.15M) { Console.WriteLine(String.Format("Alert, {0:#.0}% stock price increase!", percent * 100)); } }
protected virtual void OnPriceChanged(PriceChangedEventArgs e) { //when there is method is added to PriceChanged event delegate if (PriceChanged != null) { //invoke the method: // stock_PriceChanged(object sender, PriceChangedEventArgs e) PriceChanged.Invoke(this, e); } }
public static Stock ConvertEventObjectToStock(PriceChangedEventArgs e) { return(new Stock() { Symbol = e.Symbol, AskPrice = e.AskPrice, BidPrice = e.BidPrice, BidQty = e.BidQty, AskQty = e.AskQty }); }
static void stock_Decision(object sender, PriceChangedEventArgs e) { if ((e.NewPrice - e.LastPrice) / e.LastPrice > 0.1M) { Console.WriteLine("It is time to sell stock!"); } else { Console.WriteLine("It is time to hold stock!"); } }
//response when stock prices change event is triggered public void StockReaction(object sender, PriceChangedEventArgs e) { if(e.newPrice > e.lastPrice) { Console.WriteLine(this.name + " is buying more shares"); this.stockShares++; } else { Console.WriteLine(this.name + " is selling more shares"); this.stockShares--; } }
protected virtual void OnPriceChanged(object source, PriceChangedEventArgs e) { EventHandler <PriceChangedEventArgs> handler = PriceChanged; // if (handler != null) { // handler(source, e); // } // the same as try { handler?.Invoke(source, e); } catch (Exception exception) { // ignored } }
/// <summary> /// Event handler /// </summary> public void HandleEvent(object sender, PriceChangedEventArgs e) { checkFlag = true; Console.WriteLine("Price has been changed."); }
protected virtual void OnPriceChanged(PriceChangedEventArgs e) { if (PriceChanged != null) PriceChanged(this, e); }
void fw_PriceChanged(object sender, PriceChangedEventArgs e) { var pair = e.Price.Pair; OnLoadRates(pair); }
// The Standard Event Pattern requires a protected virtual method that fires the event. // The name has to match the name of the event, prefixed with the word "On". // It has to accept a single EventArgs argument protected virtual void OnPriceChanged(PriceChangedEventArgs e) { // This is a thread-safe and succint way to envoke the event. PriceChanged?.Invoke(this, e); }
private void OnPriceChangeCheckValue(object source, PriceChangedEventArgs args) { Assert.AreSame(m_stock, source); Assert.AreEqual(m_stock.Price, args.OriginalPrice);// has not been changed yet Assert.AreEqual(m_newPrice, args.NewPrice); }
private void OnPriceChangeSetFlag(object source, PriceChangedEventArgs args) { m_bEvtInvoked = true; }
protected virtual void OnPriceChanged(PriceChangedEventArgs e) { PriceChanged?.Invoke(this, e); }
public static void WrapperEvtHandler(object source, PriceChangedEventArgs evtargs) { m_wrapperFired = true; }
void Stock_PriceChanged(object sender, PriceChangedEventArgs e) { Console.WriteLine(e); }
private void OnPriceChangeCheckValue(object source, PriceChangedEventArgs args) { Assert.AreSame(m_stock,source); Assert.AreEqual(m_stock.Price,args.OriginalPrice);// has not been changed yet Assert.AreEqual(m_newPrice,args.NewPrice); }
void fwLocal_PriceChanged(object sender, PriceChangedEventArgs e) { InvokeSyncronize(); }
public void Action2(object obj, PriceChangedEventArgs write) { Product prodt = obj as Product; System.Diagnostics.Debug.WriteLine($"Name: {prodt.Name} Price: {write.LastPrice}"); }
public static void N_Listener3(object sender, PriceChangedEventArgs e) { Console.WriteLine("N_listener3: {0}: from {1} to {2}\n", sender, e.LastPrice, e.NewPrice); }