public async Task AddAsync <T>(IEnumerable <T> list, ExchangesIntegratedType exchangeType, Func <T, string> symbolSelector) where T : class
 {
     foreach (T item in list)
     {
         await AddAsync(item, exchangeType, symbolSelector(item));
     }
 }
        private IExchangeIntegrationStrategy ResolveStrategy(ExchangesIntegratedType exchangesIntegratedType)
        {
            var exchangeIntegrationStrategy = _strategies.FirstOrDefault(x => x.ExchangesIntegratedType == exchangesIntegratedType);

            if (exchangeIntegrationStrategy == null)
            {
                throw new InvalidOperationException($"Invalid IntegrationType, invalidType={nameof(exchangesIntegratedType)} on ExchangeIntegrationStrategyContext");
            }

            return(exchangeIntegrationStrategy);
        }
        public async Task <T> GetAsync <T>(ExchangesIntegratedType exchangeType, string symbol) where T : class
        {
            string key   = GenerateKey(exchangeType, symbol);
            var    value = await _cache.GetStringAsync(key);

            if (string.IsNullOrWhiteSpace(value))
            {
                return(null);
            }
            return(JsonConvert.DeserializeObject <T>(value));
        }
        public Task <SimpleObjectResult> TestIntegrationUpAsync(ExchangesIntegratedType exchangesIntegratedType)
        {
            var strategy = ResolveStrategy(exchangesIntegratedType);

            return(strategy.TestIntegrationUpAsync());
        }
        public Task <decimal> GetCurrentPriceAsync(string baseAssetSymbol, string quoteAssetSymbol, ExchangesIntegratedType exchangesIntegratedType)
        {
            var strategy = ResolveStrategy(exchangesIntegratedType);

            return(strategy.GetCurrentPriceAsync(baseAssetSymbol, quoteAssetSymbol));
        }
Пример #6
0
 public Task <Exchange> GetByExchangeTypeAsync(ExchangesIntegratedType exchangesIntegratedType)
 {
     return(_ORM.GetMany(a => a.ExchangeType.Equals(exchangesIntegratedType)).FirstOrDefaultAsync());
 }
 private string GenerateKey(ExchangesIntegratedType exchangeType, string symbol)
 {
     return($"{exchangeType}/{symbol}");
 }
 public async Task AddAsync <T>(T entity, ExchangesIntegratedType exchangeType, string symbol) where T : class
 {
     string key = GenerateKey(exchangeType, symbol);
     await _cache.SetStringAsync(key, JsonConvert.SerializeObject(entity), _cacheoptions);
 }