Beispiel #1
0
 public static int Disconnect()
 {
     try
     {
         _client.Logout("");
         _client.Disconnect();
         return(0);
     }
     catch (Exception)
     {
         return(-1);
     }
 }
Beispiel #2
0
        static void WorkingThread(string address, string login, string password, int port, DateTime from, DateTime to, string symbol, string periodicity, PriceType priceType, bool bars, bool ticks, bool level2, bool verbose)
        {
            try
            {
                // Create an instance of Quote History client
                using (var client = new QuoteHistoryClient("QuoteHistoryCache", port, false))
                {
                    // Connect to the server
                    client.Connect(address);

                    // Login
                    client.Login(login, password, "", "");

                    if (level2)
                    {
                        RequestTicksFiles(client, from, to, symbol, true, verbose);
                    }

                    if (ticks)
                    {
                        RequestTicksFiles(client, from, to, symbol, false, verbose);
                    }

                    if (bars)
                    {
                        RequestBarsFiles(client, from, to, symbol, periodicity, priceType, verbose);
                    }

                    // Logout
                    client.Logout("");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : " + ex.Message);
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            try
            {
                bool help = false;

                string address  = "localhost";
                string login    = "******";
                string password = "******";
                int    port     = 5020;

                DateTime  timestamp   = DateTime.UtcNow;
                int       count       = -100;
                string    symbol      = "EURUSD";
                string    periodicity = "M1";
                PriceType priceType   = PriceType.Bid;
                bool      bars        = false;
                bool      ticks       = false;
                bool      level2      = false;
                int       threadCount = 10;

                var options = new OptionSet()
                {
                    { "address=", v => address = v },
                    { "login="******"password="******"port=", v => port = int.Parse(v) },
                    { "?|help", v => help = v != null },
                    { "timestamp=", v => timestamp = DateTime.Parse(v) },
                    { "count=", v => count = int.Parse(v) },
                    { "symobl=", v => symbol = v },
                    { "periodicity=", v => periodicity = v },
                    { "threads=", v => threadCount = int.Parse(v) },
                    { "request=", v =>
                      {
                          switch (v.ToLowerInvariant())
                          {
                          case "bids":
                              priceType = PriceType.Bid;
                              bars      = true;
                              break;

                          case "asks":
                              priceType = PriceType.Ask;
                              bars      = true;
                              break;

                          case "ticks":
                              ticks = true;
                              break;

                          case "level2":
                              level2 = true;
                              break;

                          default:
                              throw new Exception("Unknown request type: " + v);
                          }
                      } },
                };

                try
                {
                    options.Parse(args);
                }
                catch (OptionException e)
                {
                    Console.Write("TTQuoteHistoryClientStressTest: ");
                    Console.WriteLine(e.Message);
                    Console.WriteLine("Try `TTQuoteHistoryClientStressTest --help' for more information.");
                    return;
                }

                if (help)
                {
                    Console.WriteLine("TTQuoteHistoryClientStressTest usage:");
                    options.WriteOptionDescriptions(Console.Out);
                    return;
                }

                // Create an instance of Quote History client
                using (var client = new QuoteHistoryClient("QuoteHistoryCache", port))
                {
                    // Connect to the server
                    client.Connect(address);

                    // Login
                    client.Login(login, password, "", "");

                    ThreadParams threadParams = new ThreadParams();
                    threadParams.client      = client;
                    threadParams.timestamp   = timestamp;
                    threadParams.count       = count;
                    threadParams.symbol      = symbol;
                    threadParams.periodicity = periodicity;
                    threadParams.priceType   = priceType;
                    threadParams.bars        = bars;
                    threadParams.ticks       = ticks;
                    threadParams.level2      = level2;

                    Thread[] threads = new Thread[threadCount];

                    for (int i = 0; i < threads.Length; ++i)
                    {
                        threads[i] = new Thread(new ParameterizedThreadStart(Program.Thread));
                    }

                    stop_ = false;

                    for (int i = 0; i < threads.Length; ++i)
                    {
                        threads[i].Start(threadParams);
//                        System.Threading.Thread.Sleep(10);
                    }

                    Console.WriteLine("Press any key to stop");
                    Console.ReadKey();

                    stop_ = true;

                    for (int i = 0; i < threads.Length; ++i)
                    {
                        threads[i].Join();
                    }

                    // Logout
                    client.Logout("");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : " + ex.Message);
            }
        }