Merging historical and live stock price data with Rx

前端 未结 4 753
清酒与你
清酒与你 2020-12-14 11:54

I\'m trying out Rx because it seems like a good fit for our domain but the learning curve has taken me by surprise.

I need to knit together historical price data wit

4条回答
  •  再見小時候
    2020-12-14 12:10

    If your historical and live data are both time-or-scheduler-based, that is, the event stream looks like this over time:

    |---------------------------------------------------->  time
        h   h   h   h  h  h                                 historical
                    l  l  l  l  l  l                        live
    

    You can use a simple TakeUntil construct:

    var historicalStream = ;
    var liveStream = ;
    
    var mergedWithoutOverlap = 
         // pull from historical
         historicalStream
           // until we start overlapping with live
           .TakeUntil(liveStream)
           // then continue with live data
           .Concat(liveStream);
    

    If you get all your historical data all at once, like a IEnumerable, you can use a combination of StartWith and your other logic:

    var historicalData = ;
    var liveData = ;
    
    var mergedWithOverlap = 
        // the observable is the "long running" feed
        liveData
        // But we'll inject the historical data in front of it
        .StartWith(historicalData)
        // Perform filtering based on your needs
        .Where( .... );
    

提交回复
热议问题