Example #1
0
        public async Task Borrow(IExchangeClient client, string pair, decimal price)
        {
            var balanceItems = (await _balanceRepository.Get(client.Platform, pair)).Where(x => x.IsBorrowed);

            if (balanceItems.Any())
            {
                return;
            }
            var availableVolume = Math.Round(await client.GetAvailableMargin(pair.Substring(0, 3)), _config[pair].VolumeFormat);

            //availableVolume = availableVolume / 100m * (decimal)_config[pair].Share;
            if (availableVolume < _config[pair].MinVolume)
            {
                //Insufficient funds
                return;
            }

            _fileService.GatherDetails(pair, FileSessionNames.Borrow_Volume, availableVolume);
            var operationId = await _operationRepository.Add(client.Platform, "add order", pair, "borrow");

            var orderIds = await client.Sell(availableVolume, pair, _config[pair].IsMarket?(decimal?)null : price, operationId, true);

            if (orderIds == null || !orderIds.Any())
            {
                return;
            }
            await _operationRepository.Complete(operationId);

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