Example #1
0
        public async Task CheckOperations(IExchangeClient client)
        {
            var incompleteOperations = (await _operationRepository.GetIncomplete(client.Platform, "add order")).OrderBy(x => x.Id);

            foreach (var operation in incompleteOperations)
            {
                _fileService.Write(operation.Pair, $"Incomplete operation [id:{operation.Id}] [operation:{operation.Misc}]");
                var orderIds = await client.GetOrdersIds(operation.Id);

                if (!orderIds.Any())
                {
                    if ((_dateTime.Now - operation.OperationDate).TotalMinutes > 20)
                    {
                        await _operationRepository.Complete(operation.Id);
                    }
                    continue;
                }

                foreach (var orderId in orderIds)
                {
                    await _orderRepository.Add(client.Platform, operation.Pair, orderId);
                }

                await _operationRepository.Complete(operation.Id);

                if (operation.Misc == "sell" || operation.Misc == "borrow")
                {
                    await _statusService.SetCurrentStatus(client.Platform, TradeStatus.Sell, operation.Pair);
                }
                else if (operation.Misc == "buy" || operation.Misc == "return")
                {
                    await _statusService.SetCurrentStatus(client.Platform, TradeStatus.Buy, operation.Pair);
                }
            }
        }