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


C# Client.BeginGetPriceBars方法代码示例

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


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

示例1: Main


//.........这里部分代码省略.........
                                    } //close lambda expression
                                ); //close method invocation
                            break;
                        case 2:
                            // - Price bars via task method...
                            Console.WriteLine("Begin Sync task...");
                            Thread.Sleep(1000);
                            Task<Dictionary<String, PriceBarDTO[]>> taskWithFactoryAndState =

                               Task.Factory.StartNew<Dictionary<String, PriceBarDTO[]>>((stateObj) =>
                               {
                                   Dictionary<String, PriceBarDTO[]> pricetasks = new Dictionary<String, PriceBarDTO[]>();
                                   for (int i = 0; i < (int)stateObj; i++)
                                   {
                                       GetPriceBarResponseDTO priceBars = _ctx.GetPriceBars(markets[i], interval, 1, no);
                                       Console.WriteLine("Received bar from task sync call:" + markets[i]);
                                       priceBarResults.Add(markets[i], priceBars.PriceBars);
                                   }
                                   return pricetasks;
                               }, 10);

                            gate = new AutoResetEvent(false);

                            try
                            {
                                Task.WaitAll(taskWithFactoryAndState);
                                gate.Set();
                            }
                            catch (AggregateException aggEx)
                            {
                                gate.Set();
                                foreach (Exception ex in aggEx.InnerExceptions)
                                {
                                    Console.WriteLine(string.Format("Caught exception '{0}'",
                                        ex.Message));
                                }
                            }
                            gate.WaitOne();
                            break;
                    }
                    foreach (String market in markets)
                    {
                        Console.WriteLine("Begin async call:" + market);
                        _ctx.BeginGetPriceBars(market,interval,1,no, pricebarResult =>
                        {
                            Console.WriteLine("Received bar from async call:" + market);
                            GetPriceBarResponseDTO pricebar = _ctx.EndGetPriceBars(pricebarResult);
                            priceBarResultsASync.Add(market, pricebar.PriceBars);
                        }, null);
                    }

                    while (count <= timeout)
                    {
                        Thread.Sleep(1000);
                        count++;
                        if (priceBarResults.Count == priceBarResultsASync.Count) break;
                        Console.WriteLine("Waiting for async... " + count + " seconds elapsed.");
                    }

                    if (priceBarResults.Count == priceBarResultsASync.Count)
                    {
                        Console.WriteLine("Sync and Async calls completed now checking...");
                        foreach (KeyValuePair<String, PriceBarDTO[]> KeyPairSync in priceBarResults)
                        {
                            String marketid = KeyPairSync.Key;
                            PriceBarDTO[] priceBarSync = KeyPairSync.Value;
                            PriceBarDTO[] priceBarAsync = priceBarResultsASync[marketid];
                            for (int i = 0; i < priceBarSync.Count(); i++)
                            {
                                // Lambda expression as executable code.
                                //Func<int, bool> deleg = i => i < 5;
                                Func<Decimal, Decimal, bool> myFunc = (x, y) => x == y;
                                bool result = myFunc(priceBarSync[i].Close, priceBarAsync[i].Close);
                                if (!result)
                                {
                                    Console.WriteLine("Sync and Async mismatch: Sync: " + priceBarSync[i].Close + " Async: " + priceBarAsync[i].Close);
                                    errors++;
                                }
                            }
                        }
                        Console.WriteLine("Sync and Async match test completed... There were: " + errors + " errors.");
                        errorList.Add(errors);
                        Thread.Sleep(2000);
                    } else if(priceBarResults.Count != priceBarResultsASync.Count)
                    {
                        Console.WriteLine("Sync and Async match test completed... We timed out after " + count + " seconds.. Sync count: " + priceBarResults.Count + " Async count: " + priceBarResultsASync.Count);
                        errorList.Add(9999);
                    }
                }

            }

            Console.WriteLine("**** ERRORS ***");
            foreach (int error in errorList)
            {
                Console.Write(error + ",");
            }
            Console.WriteLine("**** END ERRORS ***");
            //String stop = Console.ReadLine();
        }
开发者ID:JasonH1,项目名称:cityindex,代码行数:101,代码来源:Program.cs


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