Ejemplo n.º 1
0
        /// <summary>Gets the bitfinex order history asynchronous.</summary>
        /// <param name="pair">The pair.</param>
        /// <param name="activeOrderId">The active order identifier.</param>
        /// <param name="stoppingToken">The stopping token.</param>
        /// <returns>Task of BitfinexOrder.</returns>
        /// <exception cref="Exception">processed.</exception>
        public async Task <BitfinexOrder> GetBitfinexOrderHistoryAsync(Pair pair, long activeOrderId, CancellationToken stoppingToken)
        {
            int ordersHistoryRequestMaxTry = 5;
            int ordersHistoryNullMaxTry    = 5;

            do
            {
                var ordersHistoryRequest = await _bitfinexClient.GetOrderHistoryAsync($"t{pair.Name}");

                if (!ordersHistoryRequest.Success)
                {
                    ordersHistoryRequestMaxTry -= 1;

                    if (ordersHistoryRequestMaxTry == 0)
                    {
                        await _loggerService.CreateLog(new Log(LogType.Error, $"AutoTrader v{_assemblyVersion}, GetBitfinexOrderHistoryAsync()", ordersHistoryRequest.Error.Message));

                        throw new Exception("processed");
                    }

                    await Task.Delay(1000 * 20 * 1, stoppingToken);
                }
                else
                {
                    if (!ordersHistoryRequest.Data.Any(o => o.Id == activeOrderId))
                    {
                        ordersHistoryNullMaxTry -= 1;

                        if (ordersHistoryNullMaxTry == 0)
                        {
                            await _loggerService.CreateLog(new Log(LogType.Error, $"AutoTrader v{_assemblyVersion}, GetBitfinexOrderHistoryAsync()", "Null"));

                            return(null);
                        }

                        await Task.Delay(1000 * 20 * 1, stoppingToken);
                    }
                    else
                    {
                        return(ordersHistoryRequest.Data.FirstOrDefault(o => o.Id == activeOrderId));
                    }
                }
            }while (true);
        }