Exemplo n.º 1
0
        private async Task <Swap> AddSwapAsync(Swap receivedSwap)
        {
            var order = await GetOrderAsync(receivedSwap)
                        .ConfigureAwait(false);

            if (order == null || !order.IsApproved) // || !clientSwap.Order.IsContinuationOf(order))
            {
                Log.Warning("Probably swap {@swapId} created on another device", receivedSwap.Id);
                return(null);
            }

            var swap = new Swap
            {
                Id              = receivedSwap.Id,
                OrderId         = receivedSwap.OrderId,
                Status          = receivedSwap.Status,
                TimeStamp       = receivedSwap.TimeStamp,
                Symbol          = receivedSwap.Symbol,
                Side            = receivedSwap.Side,
                Price           = receivedSwap.Price,
                Qty             = receivedSwap.Qty,
                IsInitiative    = receivedSwap.IsInitiative,
                MakerNetworkFee = order.MakerNetworkFee,

                FromAddress       = order.FromAddress,
                FromOutputs       = order.FromOutputs,
                ToAddress         = order.ToAddress,
                RedeemFromAddress = order.RedeemFromAddress
            };

            var result = await _account
                         .AddSwapAsync(swap)
                         .ConfigureAwait(false);

            if (!result)
            {
                Log.Error("Can't add swap {@swapId} to account swaps repository", receivedSwap.Id);
                return(null);
            }

            return(swap);
        }
Exemplo n.º 2
0
        private async Task RunSwapAsync(Swap receivedSwap)
        {
            var order = await GetOrderAsync(receivedSwap)
                        .ConfigureAwait(false);

            if (order == null || !order.IsApproved) // || !clientSwap.Order.IsContinuationOf(order))
            {
                Log.Warning("Probably swap {@swapId} created on another device", receivedSwap.Id);
                return;
            }

            var swap = new Swap
            {
                Id           = receivedSwap.Id,
                OrderId      = receivedSwap.OrderId,
                Status       = receivedSwap.Status,
                TimeStamp    = receivedSwap.TimeStamp,
                Symbol       = receivedSwap.Symbol,
                Side         = receivedSwap.Side,
                Price        = receivedSwap.Price,
                Qty          = receivedSwap.Qty,
                IsInitiative = receivedSwap.IsInitiative,
            };

            var result = await _account
                         .AddSwapAsync(swap)
                         .ConfigureAwait(false);

            if (!result)
            {
                Log.Error("Can't add swap {@swapId} to account swaps repository", receivedSwap.Id);
                return;
            }

            if (swap.IsInitiator)
            {
                await InitiateSwapAsync(swap)
                .ConfigureAwait(false);
            }
        }
Exemplo n.º 3
0
        private async Task RunSwapAsync(ClientSwap clientSwap)
        {
            //var order = _account.GetOrderById(clientSwap.Order.ClientOrderId);

            //if (order == null || !clientSwap.Order.IsContinuationOf(order))
            //{
            //    Log.Warning("Probably swap {@swapId} created on another device", clientSwap.Id);
            //    return;
            //}

            var swap = new ClientSwap
            {
                Id           = clientSwap.Id,
                Status       = clientSwap.Status,
                TimeStamp    = clientSwap.TimeStamp,
                Symbol       = clientSwap.Symbol,
                Side         = clientSwap.Side,
                Price        = clientSwap.Price,
                Qty          = clientSwap.Qty,
                IsInitiative = clientSwap.IsInitiative,
            };

            var result = await _account
                         .AddSwapAsync(swap)
                         .ConfigureAwait(false);

            if (!result)
            {
                Log.Error("Can't add swap {@swapId} to account swaps repository", clientSwap.Id);
                return;
            }

            if (swap.IsInitiator)
            {
                await InitiateSwapAsync(swap)
                .ConfigureAwait(false);
            }
        }