Exemplo n.º 1
0
 private async Task ClearCache(int tradePairId, Guid userId)
 {
     await CacheService.InvalidateAsync
     (
         CacheKey.ExchangeUserOpenOrders(userId.ToString(), tradePairId),
         CacheKey.ExchangeUserTradeHistory(userId.ToString(), tradePairId),
         CacheKey.ExchangeUserOpenOrderDataTable(userId.ToString()),
         CacheKey.ExchangeUserOrderBook(userId.ToString(), tradePairId)
     );
 }
Exemplo n.º 2
0
        public async Task <List <string[]> > GetUserOrders(string userId, int tradePairId)
        {
            var cacheResult = await CacheService.GetOrSetHybridAsync(CacheKey.ExchangeUserOpenOrders(userId, tradePairId), TimeSpan.FromMinutes(60), async() =>
            {
                using (var context = ExchangeDataContextFactory.CreateReadOnlyContext())
                {
                    var currentUser = new Guid(userId);
                    var open        = await context.Trade
                                      .AsNoTracking()
                                      .Where(x => x.UserId == currentUser && x.TradePairId == tradePairId && (x.Status == TradeStatus.Partial || x.Status == TradeStatus.Pending))
                                      .OrderByDescending(x => x.Id)
                                      .Select(x => new
                    {
                        Timestamp = x.Timestamp,
                        Type      = x.Type,
                        Rate      = x.Rate,
                        Amount    = x.Amount,
                        Remaining = x.Remaining,
                        TradeId   = x.Id
                    }).ToListNoLockAsync().ConfigureAwait(false);

                    var orderData = open.Select(x => new[]
                    {
                        x.Timestamp.ToString(),
                        x.Type.ToString(),
                        x.Rate.ToString("F8"),
                        x.Amount.ToString("F8"),
                        x.Remaining.ToString("F8"),
                        (x.Amount *x.Rate).ToString("F8"),
                        x.TradeId.ToString()
                    });

                    return(orderData.ToList());
                }
            }).ConfigureAwait(false);

            return(cacheResult);
        }