Created
April 8, 2012 21:59
-
-
Save bobbychopra/2340049 to your computer and use it in GitHub Desktop.
Last Price every 1 sec or every 5 entries (rx framework)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Reactive; | |
using System.Reactive.Linq; | |
using System.Reactive.Concurrency; | |
namespace LastPriceUpdate | |
{ | |
public class Equity | |
{ | |
public string Ticker { get; set; } | |
public int Px { get; set; } | |
public Equity(string ticker, int px) | |
{ | |
this.Ticker = ticker; | |
this.Px = px; | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var l = new List<Equity>{ | |
new Equity("AAA", 1), | |
new Equity("AAA", 2), | |
new Equity("AAA", 3), | |
new Equity("AAA", 4), | |
new Equity("AAA", 5), | |
new Equity("BBB", 1), | |
new Equity("CCC", 2), | |
new Equity("BBB", 3), | |
new Equity("CCC", 4), | |
new Equity("CCC", 5), | |
new Equity("CCC", 1), | |
new Equity("BBB", -1) | |
}; | |
l.ToObservable() | |
.Do(e => Console.WriteLine(">>>>> Ticker: " + e.Ticker + ": " + e.Px)) | |
.Buffer(5) //buffer every 5 entries | |
//.Buffer(TimeSpan.FromSeconds(1) //buffer every 1 second | |
.Subscribe(w => w.GroupBy(e => e.Ticker) | |
.ToObservable() | |
.Subscribe(g => Console.WriteLine("----> " + g.Key + "+++ " + g.Last().Px)) | |
); | |
Console.Write("Done!!!"); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment