public TestAccAgregator Calculate(float[] parameters, out IAlgorithm alg)
 {
     using (var mc = new MemoryCache <T>(_cache))
     {
         alg = (IAlgorithm)Activator.CreateInstance(typeof(T1));
         var acc = new TestAccAgregator();
         alg.Initialize(parameters);
         Candle curr = mc.Current;
         while (mc.MoveNext())
         {
             var answer = alg.Check(mc.Current);
             if (answer == AlgResult.Buy)
             {
                 acc.Buy(1 - acc.Assets, mc.Current);
             }
             if (answer == AlgResult.Sell)
             {
                 acc.Sell(1 + acc.Assets, mc.Current);
             }
             if (answer == AlgResult.Exit)
             {
                 acc.Close(mc.Current);
             }
             curr = mc.Current;
         }
         acc.Close(curr);
         return(acc);
     }
 }
        /// <summary>
        /// 异步发送
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        protected async override Task <HttpResponseMessage> SendAsync(
            HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var checkResult = _algorithm.Check(request);

            if (checkResult.IsLimit)
            {
                HttpResponseMessage response = new HttpResponseMessage();
                response.StatusCode = (System.Net.HttpStatusCode)_error.HttpStatusCode;

                Dictionary <string, string> headers = null;
                if (_error.BuildHttpHeadersAsync != null)
                {
                    headers = await _error.BuildHttpHeadersAsync(request, checkResult).ConfigureAwait(false);
                }
                else if (_error.BuildHttpHeaders != null)
                {
                    headers = _error.BuildHttpHeaders(request, checkResult);
                }
                if (headers != null && headers.Count > 0)
                {
                    foreach (var h in headers)
                    {
                        response.Headers.Add(h.Key, h.Value);
                    }
                }

                string content = null;
                if (_error.BuildHttpContentAsync != null)
                {
                    content = await _error.BuildHttpContentAsync(request, checkResult).ConfigureAwait(false);
                }
                else if (_error.BuildHttpContent != null)
                {
                    content = _error.BuildHttpContent(request, checkResult);
                }
                if (!string.IsNullOrWhiteSpace(content))
                {
                    response.Content = new StringContent(content);
                }
                else
                {
                    response.Content = new StringContent(string.Empty);
                }

                return(response);
            }

            return(await base.SendAsync(request, cancellationToken));
        }