Example #1
0
        public WalletPath JumpPath(Wallet wallet)
        {
            WalletNode node = Nodes.FirstOrDefault(i => i.Wallet.Code.Equals(wallet.Code));

            if (node != null)
            {
                var walletPath = new WalletPath(this, wallet);
                walletPath.Path.Add((node.Market, node.OrderSide));
                return(walletPath);
            }
            else
            {
                foreach (var n in Nodes)
                {
                    WalletPath nodePath = new WalletPath(this, wallet);
                    nodePath.Path.Add((n.Market, n.OrderSide));
                    WalletPath subNodePath = n.JumpPath(wallet, nodePath);
                    if (subNodePath != null)
                    {
                        return(subNodePath);
                    }
                }
            }
            return(null);
        }
Example #2
0
        public static WalletTree Parse(Wallet wallet)
        {
            WalletTree root = new WalletTree()
            {
                Wallet = wallet
            };

            root.Wallets.Add(wallet);

            List <WalletNode> parentNodes = new List <WalletNode>();

            foreach (var conv in wallet.GetConversions())
            {
                if (!root.Wallets.Contains(conv.Wallet))
                {
                    root.Wallets.Add(conv.Wallet);
                    var node = new WalletNode(root, wallet, conv.Wallet, conv.Market, conv.Side);
                    root.Nodes.Add(node);
                    parentNodes.Add(node);
                }
            }
            do
            {
                List <WalletNode> newParentNodes = new List <WalletNode>();
                foreach (WalletNode parentNode in parentNodes)
                {
                    foreach (var conv in parentNode.Wallet.GetConversions())
                    {
                        if (!root.Wallets.Contains(conv.Wallet))
                        {
                            root.Wallets.Add(conv.Wallet);
                            var node = new WalletNode(root, parentNode.Wallet, conv.Wallet, conv.Market, conv.Side);
                            parentNode.Nodes.Add(node);
                            newParentNodes.Add(node);
                        }
                    }
                }
                parentNodes.Clear();
                parentNodes.AddRange(newParentNodes);
            }while (parentNodes.Count > 0);
            return(root);
        }