コード例 #1
0
 public void LoadState(BackgroundFetcherState state)
 {
     if (state.LastRequested is DateTimeOffset lastRequested)
     {
         this.LastRequested = state.LastRequested;
     }
     if (state.LastUpdated is DateTimeOffset updated && state.Rates is List <BackgroundFetcherRate> rates)
     {
         var fetch = new LatestFetch()
         {
             Latest      = rates.Select(r => new PairRate(r.Pair, r.BidAsk)).ToArray(),
             Updated     = updated,
             NextRefresh = updated + RefreshRate,
             Expiration  = updated + ValidatyTime
         };
         _Latest = fetch;
     }
 }
コード例 #2
0
        public BackgroundFetcherState GetState()
        {
            var state = new BackgroundFetcherState()
            {
                LastRequested = LastRequested
            };

            if (_Latest is LatestFetch fetch && fetch.Latest is not null)
            {
                state.LastUpdated = fetch.Updated;
                state.Rates       = fetch.Latest
                                    .Select(r => new BackgroundFetcherRate()
                {
                    Pair   = r.CurrencyPair,
                    BidAsk = r.BidAsk
                }).ToList();
            }
            return(state);
        }
コード例 #3
0
        public BackgroundFetcherState GetState()
        {
            var state = new BackgroundFetcherState()
            {
                ExchangeName  = ExchangeName,
                LastRequested = LastRequested
            };

            if (_Latest is LatestFetch fetch)
            {
                state.LastUpdated = fetch.Updated;
                state.Rates       = fetch.Latest
                                    .Where(e => e.Exchange == ExchangeName)
                                    .Select(r => new BackgroundFetcherRate()
                {
                    Pair   = r.CurrencyPair,
                    BidAsk = r.BidAsk
                }).ToList();
            }
            return(state);
        }
コード例 #4
0
 public void LoadState(BackgroundFetcherState state)
 {
     if (ExchangeName != state.ExchangeName)
     {
         throw new InvalidOperationException("The state does not belong to this fetcher");
     }
     if (state.LastRequested is DateTimeOffset lastRequested)
     {
         this.LastRequested = state.LastRequested;
     }
     if (state.LastUpdated is DateTimeOffset updated && state.Rates is List <BackgroundFetcherRate> rates)
     {
         var fetch = new LatestFetch()
         {
             Latest      = rates.Select(r => new PairRate(r.Pair, r.BidAsk)).ToArray(),
             Updated     = updated,
             NextRefresh = updated + RefreshRate,
             Expiration  = updated + ValidatyTime
         };
         _Latest = fetch;
     }
 }