public virtual async Task Handle(QuoteExt quote, Queue <QuoteExt> output) { if (_next != null) { await _next.Handle(quote, output); } }
public override async Task Handle(QuoteExt quote, Queue <QuoteExt> output) { var assetKey = quote.AssetPair.ToLowerInvariant(); var copy = quote.Clone(); // Update current ask/bid values if (quote.PriceType == PriceType.Bid) { QuoteExt latest = null; this.bid.TryGetValue(assetKey, out latest); this.bid[assetKey] = GetLatest(latest, copy); } else if (quote.PriceType == PriceType.Ask) { QuoteExt latest = null; this.ask.TryGetValue(assetKey, out latest); this.ask[assetKey] = GetLatest(latest, copy); } else { await base.Handle(quote, output); return; } // Make Mid quote QuoteExt mid = await MakeMiddle(assetKey, quote.AssetPair); // Pass further orignial quote and new mid quote. if (mid != null) { await base.Handle(mid, output); } await base.Handle(quote, output); }
private async Task <QuoteExt> MakeMiddle(string assetKey, string asset) { QuoteExt currentAsk = null; QuoteExt currentBid = null; this.ask.TryGetValue(assetKey, out currentAsk); this.bid.TryGetValue(assetKey, out currentBid); var assetPair = await this.env.GetAssetPair(asset); QuoteExt mid = null; // If asset dictionary does not contain asset, ignore it. if (assetPair != null && currentAsk != null && currentBid != null) { mid = new QuoteExt() { AssetPair = asset, Price = Math.Round((currentAsk.Price + currentBid.Price) / 2, assetPair.Accuracy), // Controller ensures that both dates are in UTC Timestamp = DateTime.Compare(currentAsk.Timestamp, currentBid.Timestamp) >= 0 ? currentAsk.Timestamp : currentBid.Timestamp, PriceType = PriceType.Mid }; } return(mid); }
public async Task HandleQuote(Quote quote) { // Validate incoming quote // ICollection <string> validationErrors = this.Validate(quote); if (validationErrors.Count > 0) { foreach (string error in validationErrors) { await this.log.WriteErrorAsync(this.componentName, PROCESS, "", new ArgumentException("Received invalid quote. " + error)); } return; // Skipping invalid quotes } // Add quote to the processing queue var quoteExt = new QuoteExt() { AssetPair = quote.AssetPair, IsBuy = quote.IsBuy, Price = quote.Price, Timestamp = quote.Timestamp, PriceType = quote.IsBuy ? PriceType.Bid : PriceType.Ask }; this.quotesQueue.Enqueue(quoteExt); }
private static QuoteExt GetLatest(QuoteExt lhs, QuoteExt rhs) { if (lhs != null && rhs != null) { return(lhs.Timestamp > rhs.Timestamp ? lhs : rhs); } return(lhs != null ? lhs : rhs); }
public override async Task Handle(QuoteExt quote, Queue <QuoteExt> output) { // If asset dictionary does not contain asset, then ignore this quote. var assetPair = await this.env.GetAssetPair(quote.AssetPair); if (assetPair != null) { await base.Handle(quote, output); } else { #if DEBUG await this.log.WriteInfoAsync("FeedCandlesHistoryWriterBroker", "", "", "Ignoring incoming asset " + quote.AssetPair); #endif } }
public override async Task Handle(QuoteExt quote, Queue <QuoteExt> output) { output.Enqueue(quote); await base.Handle(quote, output); }