// Use this for initialization
    void Start()
    {
        if (client == null)
        {
            client = new LSClient();

            Debug.Log("LSClient initialized!");

            try
            {
                var th = new Thread(LightStreanerConnect);
                th.Start();
            }
            catch (SystemException se)
            {
                Debug.LogError("Unexpected error: " + se.Message);
            }
        }

        nextUpdate = Queue.Synchronized(nextUpdate);

        // Only for development.
        System.Net.ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true;

        Debug.Log("Goooooooodmorning Lightstreamer ... ");

        Component i = GetComponent <Component>();

        Component[] Children = i.GetComponentsInChildren(typeof(Renderer));
        foreach (Component child in Children)
        {
            //child is your child transform
            Debug.Log("My child: " + child.tag);
            if (child.tag.StartsWith("lightstreamer"))
            {
                LightstreamerAsset ls = child.GetComponent(typeof(LightstreamerAsset)) as LightstreamerAsset;

                if (ls != null)
                {
                    Debug.Log("My child: " + ls.ItemName);

                    // Add info for a subscription
                    ExtendedTableInfo tableInfo = new ExtendedTableInfo(
                        ls.ItemName.Split(','),
                        "MERGE",
                        ls.Schema.Split(','),
                        true)
                    {
                        DataAdapter = ls.DataAdapter
                    };
                    subscriptionsLS.Enqueue(tableInfo);

                    ls.addSender(this);
                }
            }
        }
    }
示例#2
0
        /// <summary>
        /// account details subscription
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="tableListener"></param>

        public void subscribeToAccountDetails(string accountId, IHandyTableListener tableListener, string[] fields)
        {
            ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
                new string[] { "ACCOUNT:" + accountId },
                "MERGE",
                fields,
                true
                );
            SubscribedTableKey tableKey = lsClient.SubscribeTable(extTableInfo, tableListener, false);
        }
示例#3
0
        public void Subscribe(int phase, ILightstreamerListener listener)
        {
            StocklistHandyTableListener hl = new StocklistHandyTableListener(listener, phase);

            SimpleTableInfo tableInfo = new ExtendedTableInfo(
                items, "MERGE", fields, true);

            tableInfo.DataAdapter = "QUOTE_ADAPTER";
            client.SubscribeTable(tableInfo, hl, false);
        }
        public void AddSubcribe(string[] items, string[] fields)
        {
            SimpleTableInfo tableInfo = new ExtendedTableInfo(
                items, "MERGE", fields, true);

            tableInfo.DataAdapter = this.adapter_name;

            tableKey = client.SubscribeTable(tableInfo,
                                             new StocklistHandyTableListener(listener), false);
        }
示例#5
0
        public SubscribedTableKey subscribeToTradeSubscription(string accountId, IHandyTableListener tableListener, string[] fields)
        {
            ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
                new string[] { "TRADE:" + accountId },
                "DISTINCT",
                fields,
                true
                );

            return(lsClient.SubscribeTable(extTableInfo, tableListener, false));
        }
        public SubscribedTableKey SubscribeToAccountDetails(string accountId, IHandyTableListener tableListener, IEnumerable <string> fields)
        {
            ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
                new[] { "ACCOUNT:" + accountId },
                "MERGE",
                fields.ToArray(),
                true
                );

            return(lsClient.SubscribeTable(extTableInfo, tableListener, false));
        }
        public SubscribedTableKey SubscribeToTradeSubscription(string accountId, IHandyTableListener tableListener, IEnumerable <string> fields)
        {
            ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
                new[] { "TRADE:" + accountId },
                "DISTINCT",
                fields.ToArray(),
                true
                );

            return(lsClient.SubscribeTable(extTableInfo, tableListener, false));
        }
        public void CreateSubscription(string market)
        {
            ExtendedTableInfo info = new ExtendedTableInfo(
                new string[1] {
                $"MARKET:{market}"
            }, "MERGE",
                new string[5] {
                "UPDATE_TIME", "BID", "OFFER", "CHANGE_PCT", "MARKET_STATE"
            }, true);

            Client.SubscribeItems(info, new MarketDataListener(new DebugStrategy()));
        }
        public SubscribedTableKey SubscribeToChartCandleData(IEnumerable <string> epics, ChartScale scale, IHandyTableListener tableListener, string[] fields)
        {
            string[]          items        = epics.Select(e => string.Format("CHART:{0}:{1}", e, GetScale(scale))).ToArray();
            ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
                items,
                "MERGE",
                fields,
                true
                );

            return(lsClient.SubscribeTable(extTableInfo, tableListener, false));
        }
        public SubscribedTableKey SubscribeToMarketDetails(IEnumerable <string> epics, IHandyTableListener tableListener, IEnumerable <string> fields)
        {
            string[]          items        = epics.Select(e => string.Format("L1:{0}", e)).ToArray();
            ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
                items,
                "MERGE",
                fields.ToArray(),
                true
                );

            return(lsClient.SubscribeTable(extTableInfo, tableListener, false));
        }
        public SubscribedTableKey SubscribeToChartTicks(IEnumerable <string> epics, IHandyTableListener tableListener, string[] fields)
        {
            string[]          items        = epics.Select(e => string.Format("CHART:{0}:TICK", e)).ToArray();
            ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
                items,
                "DISTINCT",
                fields,
                true
                );

            return(lsClient.SubscribeTable(extTableInfo, tableListener, false));
        }
示例#12
0
文件: Client.cs 项目: jchiver/HFT
        public SubscribedTableKey SubscribeToIndexMarketData(IHandyTableListener iHandyTableListener, String Epic)
        {
            if (ConnectionEstablished == false)
            {
                throw new Exception();
            }

            String Trade = "MARKET:" + Epic;

            String[] Items  = new String[] { Trade };
            String[] Fields = new string[] { "BID", "OFFER", "UPDATE_TIME" };

            ExtendedTableInfo extendedTableInfo = new ExtendedTableInfo(Items, "MERGE", Fields, true);

            return(lsClient.SubscribeTable(extendedTableInfo, iHandyTableListener, false));
        }
示例#13
0
        /// <summary>
        /// L1 Prices subscription
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="tableListener"></param>
        public SubscribedTableKey subscribeToMarketDetails(string[] epics, IHandyTableListener tableListener, string[] fields)
        {
            string[] items = new string[epics.Length];
            for (int i = 0; i < epics.Length; i++)
            {
                items[i] = "L1:" + epics[i];
            }
            ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
                items,
                "MERGE",
                fields,
                true
                );

            return(lsClient.SubscribeTable(extTableInfo, tableListener, false));
        }
示例#14
0
文件: Client.cs 项目: jchiver/HFT
        public SubscribedTableKey SubscribeToTradeUpdates(IHandyTableListener iHandyTableListener)
        {
            if (ConnectionEstablished == false)
            {
                throw new Exception();
            }

            String Trade = "TRADE:" + Session.Response.Response.CurrentAccountId;

            String[] Items = new String[] { Trade };
            //String[] Fields = new string[] { "CONFIRMS" };
            String[] Fields = new string[] { "CONFIRMS", "OPU", "WOU" };

            ExtendedTableInfo extendedTableInfo = new ExtendedTableInfo(Items, "DISTINCT", Fields, true);

            return(lsClient.SubscribeTable(extendedTableInfo, iHandyTableListener, true));
        }
示例#15
0
        private void Subscribe()
        {
            lock (this)
            {
                this.syncContext.Send(this.cleanModel, "");

                //this method will try just one subscription.
                //we know that when this method executes we should be already connected
                //If we're not or we disconnect while subscribing we don't have to do anything here as an
                //event will be (or was) sent to the ConnectionListener that will handle the case.
                //If we're connected but the subscription fails we can't do anything as the same subscription
                //would fail again and again (btw this should never happen)

                try
                {
                    ExtendedTableInfo tableInfo = new ExtendedTableInfo(
                        new string[] { "item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8", "item9", "item10", "item11", "item12", "item13", "item14", "item15", "item16", "item17", "item18", "item19", "item20", "item21", "item22", "item23", "item24", "item25", "item26", "item27", "item28", "item29", "item30" },
                        "MERGE",
                        new string[] { "stock_name", "last_price", "time", "pct_change", "bid_quantity", "bid", "ask", "ask_quantity", "min", "max", "ref_price", "open_price" },
                        true);
                    tableInfo.DataAdapter = "QUOTE_ADAPTER";

                    client.SubscribeTable(
                        tableInfo,
                        new StocklistHandyTableListener(this, this.phase, gridModel),
                        false);
                }
                catch (SubscrException e)
                {
                    this.StatusChanged(this.phase, "No session is active: " + e.Message, null);
                }
                catch (PushServerException e)
                {
                    this.StatusChanged(this.phase, "Unexpected error: " + e.Message, null);
                }
                catch (PushUserException e)
                {
                    this.StatusChanged(this.phase, "Request refused: " + e.Message, null);
                }
                catch (PushConnException e)
                {
                    this.StatusChanged(this.phase, "Control connection failed: " + e.Message, null);
                }
            }
        }
        /// <summary>
        /// Subscirbe in lightstreamer
        /// server to Get item feed
        /// </summary>
        /// <param name="Item"></param>
        /// <param name="SchemaCode"></param>
        public void Subscibe(string Item, string Mode)
        {
            List <string> items = new List <string>();

            items.Add(Item);

            string            schema    = GetSchema(Item);
            ExtendedTableInfo tableInfo = new ExtendedTableInfo(
                items.ToArray(),
                Mode,
                schema.Split(new char[] { ' ' }),
                true
                );

            tableInfo.DataAdapter = FeedAdapter;

            NotificaionTableRef = m_lsClient.SubscribeTable(
                tableInfo,
                m_TableListenerForExtended,
                false
                );
        }
    public SubscribedTableKey AppendListener(ILightstreamerListener listener, string[] items, string[] fields)
    {
        SubscribedTableKey tableKey = null;

        if (listener == null)
        {
            throw new ArgumentNullException("listener is null");
        }
        if (ls != null)
        {
            ls.AppendListener(listener);
        }
        if (hl != null)
        {
            hl.AppendListener(listener);

            SimpleTableInfo tableInfo = new ExtendedTableInfo(
                items, "MERGE", fields, true);
            tableInfo.DataAdapter = "QUOTE_ADAPTER";
            tableKey = client.SubscribeTable(tableInfo, hl, false);
        }

        return(tableKey);
    }
    // Update is called once per frame
    void Update()
    {
        if (this.StateMachine == 0)
        {
            this.StateMachine = 1;
        }
        else if (this.StateMachine == 1)
        {
            if (goFlag)
            {
                this.StateMachine = 2;
            }
        }
        else if (this.StateMachine == 2)
        {
            this.StateMachine = 3;
            if (subscriptionsLS.Count > 0)
            {
                Debug.Log("Subscribing ...");

                ExtendedTableInfo tab = this.subscriptionsLS.Dequeue() as ExtendedTableInfo;
                while (tab != null)
                {
                    client.SubscribeTable(
                        tab,
                        new StocklistHandyTableListener(this),
                        false);

                    Debug.Log("Subscribe " + tab.DataAdapter);

                    if (subscriptionsLS.Count > 0)
                    {
                        tab = this.subscriptionsLS.Dequeue() as ExtendedTableInfo;
                    }
                    else
                    {
                        tab = null;
                    }
                }

                if (!goFlag)
                {
                    goFlag = true;
                }
            }
        }
        else if (this.StateMachine == 2001)
        {
            while (this.nextUpdate.Count != 0)
            {
                Debug.Log("SendMessage Update.");
                BroadcastMessage("RTUpdates", (IUpdateInfo)this.nextUpdate.Dequeue());
            }

            this.StateMachine = 3;
        }
        else if (this.StateMachine == 2010)
        {
            if (this.nextStatus != null)
            {
                Debug.Log("SendMessage Status: " + this.nextStatus);
                BroadcastMessage("RTStatus", this.nextStatus);
            }
            this.nextStatus   = null;
            this.StateMachine = 3;
        }
    }
示例#19
0
        /// <summary>
        /// Opens a connection, performs a table subscription and unsubscription
        /// and closes the connection after some time.
        /// </summary>
        /// <param name="args">Should specify the host name of the Server, the port number
        /// and optionally the "extended", "multiple" and "command" flags.
        /// </param>
        /// <throws>Exception Thrown in case of any error.</throws>
        public static void Main(string[] args) {

            LSClient.SetLoggerProvider(new Log4NetLoggerProviderWrapper());

            string pushServerHost = args[0];
            int pushServerPort = Int32.Parse(args[1]);

            ArrayList opts = new ArrayList();
            for (int i = 2; i < args.Length; i++) {
                opts.Add(args[i]);
            }
            bool extended = opts.Contains("extended");
            bool multiple = opts.Contains("multiple");
            bool command = opts.Contains("command");

            Thread.Sleep(2000);

            ConnectionInfo connInfo= new ConnectionInfo();
            connInfo.PushServerUrl= "http://" + pushServerHost + ":" + pushServerPort;
            connInfo.Adapter= "DEMO";

            LSClient myClient = new LSClient();
            myClient.OpenConnection(connInfo, new TestConnectionListener());
        
            Thread.Sleep(5000);

            ArrayList refs = new ArrayList();
            SubscribedTableKey[] tableRefs;

            if (!command) {
                if (extended) {
                    ExtendedTableInfo tableInfo= new ExtendedTableInfo(
                        new string[] { "item1", "item2", "item3" },
                        "MERGE",
                        new string[] { "last_price", "time", "pct_change" },
                        true
                        );

                    tableInfo.DataAdapter = "QUOTE_ADAPTER";
                
                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestTableListenerForExtended(),
                        false
                        );
                
                    tableRefs = new SubscribedTableKey[] { tableRef };

                } else if (multiple) {
                    ExtendedTableInfo tableInfo= new ExtendedTableInfo(
                        new string[] { "item1", "item2", "item3" },
                        "MERGE",
                        new string[] { "last_price", "time", "pct_change" },
                        true
                        );

                    tableInfo.DataAdapter = "QUOTE_ADAPTER";

                    tableRefs = myClient.SubscribeItems(
                        tableInfo,
                        new TestTableListenerForMultiple()
                        );

                } else {
                    // Group and Schema names have to be manageable by
                    // the LiteralBasedProvider used for the StockListDemo
                    string groupName = "item1 item2 item3";
                    string schemaName = "last_price time pct_change";

                    SimpleTableInfo tableInfo= new SimpleTableInfo(
                        groupName, 
                        "MERGE", 
                        schemaName, 
                        true
                        );

                    tableInfo.DataAdapter = "QUOTE_ADAPTER";

                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestTableListenerForSimple(),
                        false
                        );

                    tableRefs = new SubscribedTableKey[] { tableRef };
                }
            } else {
                if (extended) {
                    ExtendedTableInfo tableInfo = new ExtendedTableInfo(
                        new String[] { "portfolio1" },
                        "COMMAND",
                        new String[] { "key", "command", "qty" },
                        true
                        );

                    tableInfo.DataAdapter = "PORTFOLIO_ADAPTER";

                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestPortfolioListenerForExtended(),
                        true
                        );

                    tableRefs = new SubscribedTableKey[] { tableRef };

                } else {
                    // Group and Schema names have to be manageable by
                    // the LiteralBasedProvider used for the StockListDemo
                    String groupName = "portfolio1";
                    String schemaName = "key command qty";

                    SimpleTableInfo tableInfo = new SimpleTableInfo(
                        groupName,
                        "COMMAND",
                        schemaName,
                        true
                        );

                    tableInfo.DataAdapter = "PORTFOLIO_ADAPTER";

                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestPortfolioListenerForSimple(),
                        true
                        );

                    tableRefs = new SubscribedTableKey[] { tableRef };
                }
            }

            for (int j = 0; j < tableRefs.Length; j++) {
                refs.Add(tableRefs[j]);
            }

            Thread.Sleep(20000);

            SubscribedTableKey[] allTableRefs = new SubscribedTableKey[refs.Count];
            for (int i= 0; i < refs.Count; i++) allTableRefs[i]= (SubscribedTableKey) refs[i];
            myClient.UnsubscribeTables(allTableRefs);

            Thread.Sleep(5000);
        
            myClient.CloseConnection();
        
            Thread.Sleep(2000);
            Environment.Exit(0);
        }
示例#20
0
        /// <summary>
        /// Opens a connection, performs a table subscription and unsubscription
        /// and closes the connection after some time.
        /// </summary>
        /// <param name="args">Should specify the host name of the Server, the port number
        /// and optionally the "extended", "multiple" and "command" flags.
        /// </param>
        /// <throws>Exception Thrown in case of any error.</throws>
        public static void Main(string[] args)
        {
            LSClient.SetLoggerProvider(new Log4NetLoggerProviderWrapper());

            string pushServerHost = args[0];
            int    pushServerPort = Int32.Parse(args[1]);

            ArrayList opts = new ArrayList();

            for (int i = 2; i < args.Length; i++)
            {
                opts.Add(args[i]);
            }
            bool extended = opts.Contains("extended");
            bool multiple = opts.Contains("multiple");
            bool command  = opts.Contains("command");

            Thread.Sleep(2000);

            ConnectionInfo connInfo = new ConnectionInfo();

            connInfo.PushServerUrl = "http://" + pushServerHost + ":" + pushServerPort;
            connInfo.Adapter       = "DEMO";

            LSClient myClient = new LSClient();

            myClient.OpenConnection(connInfo, new TestConnectionListener());

            Thread.Sleep(5000);

            ArrayList refs = new ArrayList();

            SubscribedTableKey[] tableRefs;

            if (!command)
            {
                if (extended)
                {
                    ExtendedTableInfo tableInfo = new ExtendedTableInfo(
                        new string[] { "item1", "item2", "item3" },
                        "MERGE",
                        new string[] { "last_price", "time", "pct_change" },
                        true
                        );

                    tableInfo.DataAdapter = "QUOTE_ADAPTER";

                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestTableListenerForExtended(),
                        false
                        );

                    tableRefs = new SubscribedTableKey[] { tableRef };
                }
                else if (multiple)
                {
                    ExtendedTableInfo tableInfo = new ExtendedTableInfo(
                        new string[] { "item1", "item2", "item3" },
                        "MERGE",
                        new string[] { "last_price", "time", "pct_change" },
                        true
                        );

                    tableInfo.DataAdapter = "QUOTE_ADAPTER";

                    tableRefs = myClient.SubscribeItems(
                        tableInfo,
                        new TestTableListenerForMultiple()
                        );
                }
                else
                {
                    // Group and Schema names have to be manageable by
                    // the LiteralBasedProvider used for the StockListDemo
                    string groupName  = "item1 item2 item3";
                    string schemaName = "last_price time pct_change";

                    SimpleTableInfo tableInfo = new SimpleTableInfo(
                        groupName,
                        "MERGE",
                        schemaName,
                        true
                        );

                    tableInfo.DataAdapter = "QUOTE_ADAPTER";

                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestTableListenerForSimple(),
                        false
                        );

                    tableRefs = new SubscribedTableKey[] { tableRef };
                }
            }
            else
            {
                if (extended)
                {
                    ExtendedTableInfo tableInfo = new ExtendedTableInfo(
                        new String[] { "portfolio1" },
                        "COMMAND",
                        new String[] { "key", "command", "qty" },
                        true
                        );

                    tableInfo.DataAdapter = "PORTFOLIO_ADAPTER";

                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestPortfolioListenerForExtended(),
                        true
                        );

                    tableRefs = new SubscribedTableKey[] { tableRef };
                }
                else
                {
                    // Group and Schema names have to be manageable by
                    // the LiteralBasedProvider used for the StockListDemo
                    String groupName  = "portfolio1";
                    String schemaName = "key command qty";

                    SimpleTableInfo tableInfo = new SimpleTableInfo(
                        groupName,
                        "COMMAND",
                        schemaName,
                        true
                        );

                    tableInfo.DataAdapter = "PORTFOLIO_ADAPTER";

                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestPortfolioListenerForSimple(),
                        true
                        );

                    tableRefs = new SubscribedTableKey[] { tableRef };
                }
            }

            for (int j = 0; j < tableRefs.Length; j++)
            {
                refs.Add(tableRefs[j]);
            }

            Thread.Sleep(20000);

            SubscribedTableKey[] allTableRefs = new SubscribedTableKey[refs.Count];
            for (int i = 0; i < refs.Count; i++)
            {
                allTableRefs[i] = (SubscribedTableKey)refs[i];
            }
            myClient.UnsubscribeTables(allTableRefs);

            Thread.Sleep(5000);

            myClient.CloseConnection();

            Thread.Sleep(2000);
            Environment.Exit(0);
        }