Skip to content

Question: How to produce single updates in an IObservableCache when batch editing a SourceCache #569

Description

@Kl-Li

Hello,
Is it possible to have only the latest update event (per key) instead of multiple in case of batch editing when using a SourceCache and an IObservableCache?

I use batch edit to add some market prices in the SourceCache (as shown below)

    public void AddTicks(ICollection<Tick> newTicks)
    {
        _ticksCache.Edit(innerCache => innerCache.AddOrUpdate(newTicks));
    }

I also have an IObservableCache<Tick, string> NewTicks (as shown below)

    NewTicks = _ticksCache
        .Connect()
        .Filter(tick => tick.LastUpdate > DateTime.UtcNow - TimeSpan.FromSeconds(1))
        .Batch(TimeSpan.FromSeconds(1))
        .AsObservableCache();

When i subscribe to the IObservableCache i get multiple update events for the same currency pairs eg EURUSD per second

    tickService.NewTicks
        .Connect()
        .Watch("EURUSD")
    .Subscribe(price => Console.WriteLine(price));

In my case I'm only interested about the latest value of a currency pair (eg if EURUSD had 3 price changes in 1 second i'm only interested about the 3rd).

Update, Key: EURUSD, Current: Name: EURUSD, Price: 1, LastUpdate: 14/03/2022 4:14:21 pm, Previous: Name: EURUSD, Price: 0, LastUpdate: 14/03/2022 4:14:20 pm
Update, Key: EURUSD, Current: Name: EURUSD, Price: 2, LastUpdate: 14/03/2022 4:14:21 pm, Previous: Name: EURUSD, Price: 1, LastUpdate: 14/03/2022 4:14:21 pm
Update, Key: EURUSD, Current: Name: EURUSD, Price: 3, LastUpdate: 14/03/2022 4:14:21 pm, Previous: Name: EURUSD, Price: 2, LastUpdate: 14/03/2022 4:14:21 pm

Is what I'm asking possible? If yes how?

ps: Yesterday I asked this question in stackoverflow. There i have my full sample code. I can copy it here as well if it's preferable. Also assuming i get an answer i will update/close this question accordingly (and vice versa of course).

Activity

  1. locked and limited conversation to collaborators on Mar 15, 2022
  2. converted this issue into a discussion #570 on Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions