当前位置: 首页>>代码示例>>C#>>正文


C# NTree.Traverse方法代码示例

本文整理汇总了C#中NTree.Traverse方法的典型用法代码示例。如果您正苦于以下问题:C# NTree.Traverse方法的具体用法?C# NTree.Traverse怎么用?C# NTree.Traverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NTree的用法示例。


在下文中一共展示了NTree.Traverse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

        /// <summary>
        /// Starts the arbitrage
        /// </summary>
        /// <param name="originalAmount"></param>
        /// <param name="targetCurrency"></param>
        /// <param name="frequencyInSec"></param>
        /// <param name="profitThreshold"></param>
        /// <param name="realTrading"></param>
        /// <param name="allowedPairs"></param>
        public void Start(decimal originalAmount, string targetCurrency, int frequencyInSec, decimal profitThreshold, bool realTrading, BtcePair[] allowedPairs)
        {
            realTrading = false; //!!!DO not use real trading

            _allowedPairs = allowedPairs;
            _pairsAsString = _allowedPairs.Select(p => BtcePairHelper.ToString(p)).ToArray();

            _mustStop = false;
            OnReportProgress("Starting Arbitrage - Monitoring opportunities...");
            while (!_mustStop)
            {
                Dictionary<BtcePair, Ticker> tickers;
                try
                {
                    tickers = BtceApiV3.GetTicker(_allowedPairs);
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                    OnReportProgress("Error: " + ex.ToString());
                    System.Threading.Thread.Sleep(1000 * frequencyInSec);
                    continue;
                }

                var pairs = _allowedPairs.Where(p => p.HasCurrency(targetCurrency));

                var ac = new MyAction
                {
                    UnitsCurrency1 = 0,
                    UnitsCurrency2 = originalAmount,
                    Pair = BtcePair.Unknown

                };
                NTree<MyAction> tree = new NTree<MyAction>(ac);

                foreach (var p in pairs)
                {
                    BuildArbitrageTree(tickers, p, tree, originalAmount, p.Item1() == targetCurrency, targetCurrency);
                }

                var leaves = new List<NTree<MyAction>>();
                tree.Traverse(n =>
                {
                    if (n.Data.IsFinalAction)
                    {
                        leaves.Add(n);
                    }
                });

                decimal maxProfit = 0;
                List<NTree<MyAction>> bestChain = null;
                int bestIndex = 0;

                for (var lIndex = 0; lIndex < leaves.Count; lIndex++)
                {
                    //  System.Diagnostics.Debug.WriteLine("Option " + (lIndex + 1));
                    var l = leaves[lIndex];
                    var t = l.GetTree();
                    for (var nIndex = 1; nIndex < t.Count; nIndex++)
                    {
                        var c = t[nIndex].Data;
                        //System.Diagnostics.Debug.WriteLine(string.Format("Converting {0:0.00###} {1:0.00###} to {2:0.00###} {3:0.00###}", c.UnitsCurrency1, c.Currency1, c.UnitsCurrency2, c.Currency2));
                    }
                    decimal profit = l.Data.UnitsCurrency2 - originalAmount;
                    // System.Diagnostics.Debug.WriteLine("Profit " + profit.ToString("0.00###"));
                    if (profit > maxProfit)
                    {
                        maxProfit = l.Data.UnitsCurrency2 - originalAmount;
                        bestChain = t;
                        bestIndex = lIndex;
                    }
                }

                if (bestChain != null)
                {
                    //System.Diagnostics.Debug.WriteLine("Best Option: " + (bestIndex + 1));
                    OnReportProgress("Max profit: " + maxProfit.ToString("0.00###"));

                    for (var nIndex = 1; nIndex < bestChain.Count; nIndex++)
                    {
                        var c = bestChain[nIndex].Data;
                        OnReportProgress(c.Description);
                    }

                    _currentChain = bestChain;
                    var percentage = maxProfit / originalAmount * 100;
                    OnReportProgress(string.Format("Percentage {0:0.00}", percentage));
                    if (percentage > profitThreshold)
                    {

                        FollowChain(bestChain, realTrading);
//.........这里部分代码省略.........
开发者ID:CryptoRepairCrew,项目名称:CoinTNet,代码行数:101,代码来源:ArbitrageManager.cs


注:本文中的NTree.Traverse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。