This file contains 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
public static IObservable<TResult> WithLatestFrom<TFirst, TSecond, TResult>(this IObservable<TFirst> first, IObservable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector) | |
{ | |
if (first == null) | |
throw new ArgumentNullException("first"); | |
if (second == null) | |
throw new ArgumentNullException("second"); | |
if (resultSelector == null) | |
throw new ArgumentNullException("resultSelector"); | |
return first.Publish(f => |
This file contains 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
void Main() | |
{ | |
var slow = Observable.Interval(TimeSpan.FromSeconds(1)); | |
var fast = Observable.Interval(TimeSpan.FromMilliseconds(250)); | |
Observable.CombineLatest( | |
slow, | |
fast, | |
Tuple.Create) | |
.DistinctUntilChanged(tp => tp.Item1) |
This file contains 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
var clientsQuery = from systemStatus in clientService.SystemStatus.Where(s => s == Status.Available) | |
from clients in clientService.LoadClients() | |
select clients; |
This file contains 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
public IObservable<IStale<ITrade>> ExecuteRequest(IExecutablePrice executablePrice, long notional, string dealtCurrency) | |
{ | |
var price = executablePrice.Parent; | |
var request = new TradeRequestDto | |
{ | |
Direction = executablePrice.Direction == Direction.BUY ? DirectionDto.Buy : DirectionDto.Sell, | |
Notional = notional, | |
SpotRate = executablePrice.Rate, | |
Symbol = price.CurrencyPair.Symbol, |
This file contains 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
public static IObservable<IStale<T>> DetectStale<T>(this IObservable<T> source, TimeSpan stalenessPeriod, IScheduler scheduler) | |
{ | |
return Observable.Create<IStale<T>>(observer => | |
{ | |
var timerSubscription = new SerialDisposable(); | |
var observerLock = new object(); | |
Action scheduleStale = () => | |
{ | |
timerSubscription.Disposable = Observable |
This file contains 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
public static IObservable<T> Conflate<T>(this IObservable<T> source, TimeSpan minimumUpdatePeriod, IScheduler scheduler) | |
{ | |
return Observable.Create<T>(observer => | |
{ | |
// indicate when the last update was published | |
var lastUpdateTime = DateTimeOffset.MinValue; | |
// indicate if an update is currently scheduled | |
var updateScheduled = new MultipleAssignmentDisposable(); | |
// indicate if completion has been requested (we can't complete immediatly if an update is in flight) | |
var completionRequested = false; |
This file contains 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
public static IObservable<T> ObserveLatestOn<T>(this IObservable<T> source, IScheduler scheduler) | |
{ | |
return Observable.Create<T>(observer => | |
{ | |
var gate = new object(); | |
bool active = false; | |
var cancelable = new MultipleAssignmentDisposable(); | |
var disposable = source.Materialize().Subscribe(thisNotification => | |
{ | |
bool wasNotAlreadyActive; |
This file contains 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
private void LoadSpotTiles() | |
{ | |
_referenceDataRepository.GetCurrencyPairsStream() | |
.ObserveOn(_concurrencyService.Dispatcher) | |
.SubscribeOn(_concurrencyService.TaskPool) | |
.Subscribe( | |
currencyPairs => currencyPairs.ForEach(HandleCurrencyPairUpdate), | |
error => _log.Error("Failed to get currencies", error)); | |
} |
This file contains 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
public static IObservable<IStale<T>> DetectStale<T>(this IObservable<T> source, TimeSpan stalenessPeriod, IScheduler scheduler) | |
{ | |
return Observable.Create<IStale<T>>(observer => | |
{ | |
var timerSubscription = new SerialDisposable(); | |
var observerLock = new object(); | |
Action scheduleStale = () => | |
{ | |
timerSubscription.Disposable = Observable |
This file contains 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
internal interface IExecutionServiceClient | |
{ | |
IObservable<TradeDto> ExecuteRequest(TradeRequestDto tradeRequest); | |
} | |
interface IPriceRepository | |
{ | |
IObservable<IPrice> GetPriceStream(ICurrencyPair currencyPair); | |
} |
NewerOlder