private Task ProcessPrice(IInstrumentPrice assetBid) { var price = assetBid.ClonePrice() as Price; _priceCache.AddPrice(assetBid.Instrument, price); return(Task.FromResult(0)); }
private void QuoteSubscriber_MessageReceived(object sender, IInstrumentPrice e) { try { Task.Run(async() => { await ProcessPrice(e); }).Wait(); } catch { //TODO: Log Error throw; } }
/// <summary> /// Event Handler for messages received from IAssetQuoteSubscriber /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Subscriber_MessageReceived(object sender, IInstrumentPrice e) { try { await ProcessPrice(e); } catch { //TODO: Log Error throw; } }
/// <summary> /// Process AssetQuote received from IAssetQuoteSubscriber /// </summary> /// <param name="assetQuote"></param> /// <returns></returns> private Task ProcessPrice(IInstrumentPrice assetBid) { // Parameter validation if (assetBid == null || string.IsNullOrEmpty(assetBid.Instrument) || assetBid.Ask <= 0 || assetBid.Bid <= 0) { return(Task.FromResult(0)); } PublishInstrumentPair(assetBid); return(Task.FromResult(0)); }
/// <summary> /// Process AssetQuote received from IAssetQuoteSubscriber /// </summary> /// <param name="assetQuote"></param> /// <returns></returns> private Task ProcessPrice(IInstrumentPrice assetBid) { // Parameter validation if (assetBid == null || string.IsNullOrEmpty(assetBid.Instrument) || assetBid.Ask <= 0 || assetBid.Bid <= 0) { return(Task.FromResult(0)); } // Add Received Asset Quote to Graph Data lock (GraphQueueLock) { // If assetbid has Ask and Bid prices, add it to Graphdata if (assetBid.Ask > 0 && assetBid.Bid > 0) { // Add AssetPair to graph; if (!graphData.ContainsKey(assetBid.Instrument)) { graphData.Add(assetBid.Instrument, new List <Price>()); } // Add Quote Data graphData[assetBid.Instrument].Add(new Price { Bid = assetBid.Bid, Ask = assetBid.Ask, Date = assetBid.Date }); // If quote data array is to big, resize it. if (graphData[assetBid.Instrument].Count > settings.PricesSettingsBoxOptions.GraphPointsCount) { graphData[assetBid.Instrument] = graphData[assetBid.Instrument] .GetRange(1, graphData[assetBid.Instrument].Count - 1); } } } return(Task.FromResult(0)); }
private async void QuoteFeed_MessageReceived(object sender, IInstrumentPrice e) { //Activate Mutual Exclusion Semaphore await quoteReceivedSemaphoreSlim.WaitAsync(); try { // Add price to cache if (!assetCache.ContainsKey(e.Instrument)) { assetCache.Add(e.Instrument, new PriceCache()); } // Update price cache assetCache[e.Instrument].PreviousPrice = assetCache[e.Instrument].CurrentPrice; assetCache[e.Instrument].CurrentPrice = (InstrumentPrice)e.ClonePrice(); // Get bets for current asset // That are not yet with WIN status var betCacheSnap = GetRunningBets(); var assetBets = (from b in betCacheSnap where b.AssetPair == e.Instrument && b.BetStatus != BetStates.Win select b).ToList(); if (assetBets.Count == 0) { return; } foreach (var bet in assetBets) { ProcessBetCheck(bet, false); } } catch (Exception ex) { LogError("QuoteFeed_MessageReceived", ex); } finally { quoteReceivedSemaphoreSlim.Release(); } }
/// <summary> /// Publish Intrument Bid/Ask pair to WAMP topic /// </summary> /// <param name="instrumentBidAskPair"></param> /// <returns></returns> private Task PublishInstrumentPair(IInstrumentPrice instrumentBidAskPair) { //string json = instrumentBidAskPair.ToJson(); subject.OnNext(instrumentBidAskPair); return(Task.FromResult(0)); }
/// <summary> /// Event Handler for messages received from IAssetQuoteSubscriber /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Subscriber_MessageReceived(object sender, IInstrumentPrice e) { await ProcessPrice(e); }