コード例 #1
0
        private async Task ProcessEthBuy(AggregatedTransfer operation, IAsset asset, IClientTrade[] clientTrades, string orderId)
        {
            string errMsg     = string.Empty;
            var    transferId = Guid.NewGuid();

            try
            {
                var toAddress = await _bcnClientCredentialsRepository.GetClientAddress(operation.ClientId);

                await _ethereumTransactionRequestRepository.InsertAsync(new EthereumTransactionRequest
                {
                    AddressTo    = toAddress,
                    AssetId      = asset.Id,
                    ClientId     = operation.ClientId,
                    Id           = transferId,
                    OperationIds =
                        clientTrades.Where(x => x.ClientId == operation.ClientId && x.Amount > 0)
                        .Select(x => x.Id)
                        .ToArray(),
                    OperationType = OperationType.Trade,
                    OrderId       = orderId,
                    Volume        = operation.Amount
                });

                var res = await _srvEthereumHelper.SendTransferAsync(transferId, string.Empty, asset,
                                                                     _settings.HotwalletAddress, toAddress, operation.Amount);

                if (res.HasError)
                {
                    errMsg = res.Error.ToJson();

                    await _log.WriteWarningAsync(nameof(TradeQueue), nameof(ProcessEthGuaranteeTransfer), errMsg, string.Empty);
                }
            }
            catch (Exception e)
            {
                await _log.WriteErrorAsync(nameof(TradeQueue), nameof(ProcessEthGuaranteeTransfer), e.Message, e);

                errMsg = $"{e.GetType()}\n{e.Message}";
            }

            if (!string.IsNullOrEmpty(errMsg))
            {
                await _ethClientEventLogs.WriteEvent(operation.ClientId, Event.Error, new
                {
                    Info      = $"{asset.Id} was not transferred to client",
                    RequestId = transferId,
                    Operation = operation.ToJson(),
                    Error     = errMsg
                }.ToJson());
            }
        }
コード例 #2
0
        private async Task <(AggregatedTransfer sellTransfer, AggregatedTransfer buyTransfer)> AggregateSwaps(List <TradeQueueItem.TradeInfo> swaps)
        {
            var marketAsset = swaps[0].MarketAsset;
            var limitAsset  = swaps[0].LimitAsset;

            var sellTransfer = new AggregatedTransfer
            {
                TransferId = Guid.NewGuid().ToString(),
                Asset      = await _assetsServiceWithCache.TryGetAssetAsync(marketAsset),
                Amount     = -swaps.Sum(x => Convert.ToDecimal(x.MarketVolume))
            };

            var buyTransfer = new AggregatedTransfer
            {
                TransferId = Guid.NewGuid().ToString(),
                Asset      = await _assetsServiceWithCache.TryGetAssetAsync(limitAsset),
                Amount     = swaps.Sum(x => Convert.ToDecimal(x.LimitVolume))
            };

            return(sellTransfer, buyTransfer);
        }