コード例 #1
0
ファイル: Subscriber.cs プロジェクト: ram1991/qSharp
        private static void Main(string[] args)
        {
            var q = new QCallbackConnection((args.Length >= 1) ? args[0] : "localhost",
                                            (args.Length >= 2) ? int.Parse(args[1]) : 5000);

            try
            {
                q.DataReceived += OnData;
                q.ErrorOccured += OnError;
                q.Open();
                Console.WriteLine("conn: " + q + "  protocol: " + q.ProtocolVersion);
                Console.WriteLine("Press <ENTER> to close application");

                q.Sync("sub:{[x] .sub.h: .z.w }");
                q.Sync(".z.ts:{ (neg .sub.h) .z.p}");
                q.Sync("value \"\\\\t 100\"");
                q.StartListener();
                q.Async("sub", 0);

                Console.ReadLine();
                q.Sync("value \"\\\\t 0\"");
                q.StopListener();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error occured: " + e);
                Console.ReadLine();
            }
            finally
            {
                q.Close();
            }
        }
コード例 #2
0
ファイル: TickClientForm.cs プロジェクト: ram1991/qSharp
        private void subscribeBtn_Click(object sender, EventArgs e)
        {
            if (q == null)
            {
                var conn = qhostTB.Text.Split(':');
                q = new QCallbackConnection(conn.Length >= 1 ? conn[0] : "localhost",
                                            conn.Length >= 2 ? int.Parse(conn[1]) : 5010);

                try
                {
                    q.Open();
                    var model = (QTable)((object[])q.Sync(".u.sub", qtableTB.Text, ""))[1];
                    data.Columns.Clear();
                    foreach (var column in model.Columns)
                    {
                        data.Columns.Add(column);
                    }

                    q.DataReceived += OnData;
                }
                catch (Exception e1)
                {
                    Console.Error.WriteLine(e1);
                    Console.ReadLine();
                    q.Close();
                }
            }
            q.StartListener();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            QCallbackConnection q = new QCallbackConnection(host: (args.Length >= 1) ? args[0] : "localhost",
                                                            port: (args.Length >= 2) ? Int32.Parse(args[1]) : 17010);
            try
            {
                q.DataReceived += OnData;
                q.ErrorOccured += OnError;
                q.Open();
                Console.WriteLine("conn: " + q + "  protocol: " + q.ProtocolVersion);
                Console.WriteLine("Press <ENTER> to close application");

                Object response = q.Sync(".u.sub", "trade", ""); // subscribe to tick
                QTable model = (QTable)((Object[])response)[1]; // get table model

                q.StartListener();
                Console.ReadLine();
                q.StopListener();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error occured: " + e);
                Console.ReadLine();
            }
            finally
            {
                q.Close();
            }
        }
コード例 #4
0
        private static void Main(string[] args)
        {
            var q = new QCallbackConnection((args.Length >= 1) ? args[0] : "localhost",
                                            (args.Length >= 2) ? int.Parse(args[1]) : 17010);

            try
            {
                q.DataReceived += OnData;
                q.ErrorOccured += OnError;
                q.Open();
                Console.WriteLine("conn: " + q + "  protocol: " + q.ProtocolVersion);
                Console.WriteLine("Press <ENTER> to close application");

                var response = q.Sync(".u.sub", "trade", "");   // subscribe to tick
                var model    = (QTable)((object[])response)[1]; // get table model

                q.StartListener();
                Console.ReadLine();
                q.StopListener();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error occured: " + e);
                Console.ReadLine();
            }
            finally
            {
                q.Close();
            }
        }
コード例 #5
0
ファイル: Subscriber.cs プロジェクト: CharlesSkelton/qSharp
        static void Main(string[] args)
        {
            QCallbackConnection q = new QCallbackConnection(host: (args.Length >= 1) ? args[0] : "localhost",
                                                            port: (args.Length >= 2) ? Int32.Parse(args[1]) : 5000);
            try
            {
                q.DataReceived += OnData;
                q.ErrorOccured += OnError;
                q.Open();
                Console.WriteLine("conn: " + q + "  protocol: " + q.ProtocolVersion);
                Console.WriteLine("Press <ENTER> to close application");

                q.Sync("sub:{[x] .sub.h: .z.w }");
                q.Sync(".z.ts:{ (neg .sub.h) .z.p}");
                q.Sync("value \"\\\\t 100\"");
                q.StartListener();
                q.Async("sub", 0);

                Console.ReadLine();
                q.Sync("value \"\\\\t 0\"");
                q.StopListener();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error occured: " + e);
                Console.ReadLine();
            }
            finally
            {
                q.Close();
            }
        }
コード例 #6
0
        private static void Main(string[] args)
        {
            var q = new QCallbackConnection((args.Length >= 1) ? args[0] : "localhost",
                                            (args.Length >= 2) ? int.Parse(args[1]) : 5000);

            try
            {
                q.DataReceived += OnData;
                q.Open();
                Console.WriteLine("conn: " + q + "  protocol: " + q.ProtocolVersion);
                Console.WriteLine("Press <ENTER> to close application");

                // definition of asynchronous multiply function
                // queryid - unique identifier of function call - used to identify
                // the result
                // a, b - actual parameters to the query
                q.Sync("asynchMult:{[queryid;a;b] res:a*b; (neg .z.w)(`queryid`result!(queryid;res)) }");
                q.StartListener();

                var gen = new Random();
                // send asynchronous queries
                for (var i = 0; i < 10; i++)
                {
                    int a = gen.Next(20), b = gen.Next(20);
                    Console.WriteLine("Asynchronous call with queryid=" + i + " with arguments= " + a + ", " + b);
                    q.Async("asynchMult", i, a, b);
                }

                Thread.Sleep(2000);

                Console.ReadLine();
                q.Sync("value \"\\\\t 0\"");
                q.StopListener();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
                Console.ReadLine();
            }
            finally
            {
                q.Close();
            }
        }
コード例 #7
0
ファイル: AsynchQuery.cs プロジェクト: CharlesSkelton/qSharp
        static void Main(string[] args)
        {
            QCallbackConnection q = new QCallbackConnection(host: (args.Length >= 1) ? args[0] : "localhost",
                                                            port: (args.Length >= 2) ? Int32.Parse(args[1]) : 5000);
            try
            {
                q.DataReceived += OnData;
                q.Open();
                Console.WriteLine("conn: " + q + "  protocol: " + q.ProtocolVersion);
                Console.WriteLine("Press <ENTER> to close application");

                // definition of asynchronous multiply function
                // queryid - unique identifier of function call - used to identify
                // the result
                // a, b - actual parameters to the query
                q.Sync("asynchMult:{[queryid;a;b] res:a*b; (neg .z.w)(`queryid`result!(queryid;res)) }");
                q.StartListener();

                Random gen = new Random();
                // send asynchronous queries
                for (int i = 0; i < 10; i++)
                {
                    int a = gen.Next(20), b = gen.Next(20);
                    Console.WriteLine("Asynchronous call with queryid=" + i + " with arguments= " + a + ", " + b);
                    q.Async("asynchMult", i, a, b);
                }

                Thread.Sleep(2000);

                Console.ReadLine();
                q.Sync("value \"\\\\t 0\"");
                q.StopListener();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
                Console.ReadLine();
            }
            finally
            {
                q.Close();
            }
        }
コード例 #8
0
ファイル: TickClientForm.cs プロジェクト: mrecht/qSharp
        private void subscribeBtn_Click(object sender, EventArgs e)
        {
            if (q == null)
            {
                var conn = qhostTB.Text.Split(':');
                q = new QCallbackConnection(conn.Length >= 1 ? conn[0] : "localhost",
                    conn.Length >= 2 ? int.Parse(conn[1]) : 5010);

                try
                {
                    q.Open();
                    var model = (QTable) ((object[]) q.Sync(".u.sub", qtableTB.Text, ""))[1];
                    data.Columns.Clear();
                    foreach (var column in model.Columns)
                    {
                        data.Columns.Add(column);
                    }

                    q.DataReceived += OnData;
                }
                catch (Exception e1)
                {
                    Console.Error.WriteLine(e1);
                    Console.ReadLine();
                    q.Close();
                }
            }
            q.StartListener();
        }
コード例 #9
0
// ReSharper disable UnusedMember.Global
        public static object RtdOpen([ExcelArgument("Logical identifier for the connection.")] object alias,
// ReSharper restore UnusedMember.Global
                                     [ExcelArgument(
                                          "Hostname, fqdn or ip of the machine running q process to which connection should be established."
                                          )] object hostname,
                                     [ExcelArgument("Port number of the q process.")] object port,
                                     [ExcelArgument("Username")] object username = null,
                                     [ExcelArgument("Password")] object password = null)
        {
            try
            {
                if (alias == null || !alias.ToString().Trim().Any())
                {
                    return("Invalid alias");
                }

                if (hostname == null || !hostname.ToString().Trim().Any())
                {
                    return("Invalid hostname");
                }

                try
                {
                    port = Int32.Parse(port.ToString());
                }
                catch
                {
                    return("Invalid port");
                }

                var c = GetConnection(alias.ToString());
                if (c != null)
                {
                    return(alias);
                }

                var u = username != null && username.GetType() == ExcelMissing.Value.GetType()
                    ? null
                    : username as string;
                var p = password != null && password.GetType() == ExcelMissing.Value.GetType()
                    ? null
                    : password as string;
                try
                {
                    c = new QCallbackConnection(hostname.ToString(), (int)port, u, p);
                    c.Open();
                    c.DataReceived += OnUpdate; //assign handler function.
                    c.StartListener();

                    Connections[alias.ToString()] = c;

                    if (WildCardMapping.ContainsKey(alias.ToString()))
                    {
                        RtdSubscribeAllTables(alias.ToString());
                    }
                    if (Mapping.ContainsKey(alias.ToString()) && !WildCardMapping.ContainsKey(alias.ToString()))
                    {
                        RtdSubscribeAll(alias.ToString());
                    }
                }
                catch (QException e)
                {
                    return(e.Message);
                }
            }
            catch (Exception e)
            {
                return(e.Message);
            }
            return(alias);
        }