Ejemplo n.º 1
0
        public async Task Publish(MarketOrderWithTrades marketOrderWithTrades)
        {
            if (marketOrderWithTrades == null)
            {
                return;
            }

            var clientId = await _clientAccountClient.GetClientByWalletAsync(marketOrderWithTrades.Order.ClientId);

            var order = await _ordersConverter.ConvertAsync(marketOrderWithTrades.Order);

            PublishOrdersToClient(clientId, new[] { order });
        }
        public async Task <(string, string)> GetClientIdAndWalletIdAsync(string id)
        {
            if (_clientIdToTradingWalletIdMap.TryGetValue(id, out var walletId))
            {
                return(id, walletId);
            }

            if (_tradingWalletIdToClientIdMap.TryGetValue(id, out var clientId))
            {
                return(clientId, id);
            }

            clientId = await _clientAccountClient.GetClientByWalletAsync(id);

            if (string.IsNullOrWhiteSpace(clientId))
            {
                throw new InvalidOperationException($"Client not found by wallet {id}");
            }

            if (clientId == id)
            {
                var wallets = await _clientAccountClient.GetClientWalletsByTypeAsync(clientId, WalletType.Trading);

                walletId = wallets?.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i?.Id))?.Id;
                if (string.IsNullOrWhiteSpace(walletId))
                {
                    throw new InvalidOperationException($"Trading wallet not found for client {clientId}");
                }
            }
            else
            {
                walletId = id;
            }
            _clientIdToTradingWalletIdMap.TryAdd(clientId, walletId);
            _tradingWalletIdToClientIdMap.TryAdd(walletId, clientId);

            return(clientId, walletId);
        }