Beispiel #1
0
 public WalletNode(WalletTree root, Wallet parent, Wallet wallet, Market market, OrderSide orderSide)
 {
     Root      = root;
     Parent    = parent;
     Wallet    = wallet;
     Market    = market;
     OrderSide = orderSide;
 }
Beispiel #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);
        }