コード例 #1
0
        /// <summary>
        /// Quality of Service provides the different rates of data updates per protocol (binary, websocket etc), or per user based.
        /// </summary>
        /// <param name="quality">Quality of Service, or the rate the data will be sent to the client.</param>
        /// <returns></returns>
        public Task RequestQOS(TDQOSLevels quality)
        {
            var request = new TDRealtimeRequestContainer
            {
                requests = new TDRealtimeRequest[]
                {
                    new TDRealtimeRequest
                    {
                        service    = "ADMIN",
                        command    = "QOS",
                        requestid  = Interlocked.Increment(ref _counter),
                        account    = _account.accountId,
                        source     = _prince.streamerInfo.appId,
                        parameters = new
                        {
                            qoslevel = ((int)quality)
                        }
                    }
                }
            };

            var data = JsonConvert.SerializeObject(request, _settings);

            return(SendToServer(data));
        }
コード例 #2
0
        /// <summary>
        /// Unsubscribe to the level two order book. Note this stream has no official documentation, and it's not entirely clear what exchange it corresponds to.Use at your own risk.
        /// </summary>
        /// <returns></returns>
        public Task UnsubscribeBook(string symbols, TDBookOptions option)
        {
            var request = new TDRealtimeRequestContainer
            {
                requests = new TDRealtimeRequest[]
                {
                    new TDRealtimeRequest
                    {
                        service    = option.ToString(),
                        command    = "UNSUBS",
                        requestid  = Interlocked.Increment(ref _counter),
                        account    = _account.accountId,
                        source     = _prince.streamerInfo.appId,
                        parameters = new
                        {
                            keys = symbols,
                        }
                    }
                }
            };

            var data = JsonConvert.SerializeObject(request, _settings);

            return(SendToServer(data));
        }
コード例 #3
0
        /// <summary>
        /// Subscribed to the time&sales event service
        /// </summary>
        /// <param name="symbols">spy,qqq,amd</param>
        /// <param name="service">data service to subscribe to</param>
        /// <returns></returns>
        public Task SubscribeTimeSale(string symbols, TDTimeSaleServices service)
        {
            var request = new TDRealtimeRequestContainer
            {
                requests = new TDRealtimeRequest[]
                {
                    new TDRealtimeRequest
                    {
                        service    = service.ToString(),
                        command    = "SUBS",
                        requestid  = Interlocked.Increment(ref _counter),
                        account    = _account.accountId,
                        source     = _prince.streamerInfo.appId,
                        parameters = new
                        {
                            keys   = symbols,
                            fields = "0,1,2,3,4"
                        }
                    }
                }
            };

            var data = JsonConvert.SerializeObject(request, _settings);

            return(SendToServer(data));
        }
コード例 #4
0
        /// <summary>
        /// Subscribeds to the level one quote event service
        /// </summary>
        /// <param name="symbols"></param>
        /// <returns></returns>
        public Task SubscribeQuote(string symbols)
        {
            var request = new TDRealtimeRequestContainer
            {
                requests = new TDRealtimeRequest[]
                {
                    new TDRealtimeRequest
                    {
                        service    = "QUOTE",
                        command    = "SUBS",
                        requestid  = Interlocked.Increment(ref _counter),
                        account    = _account.accountId,
                        source     = _prince.streamerInfo.appId,
                        parameters = new
                        {
                            keys   = symbols,
                            fields = "0,1,2,3,4,5,8,9,10,11,12,13,14,15,24,28"
                        }
                    }
                }
            };

            var data = JsonConvert.SerializeObject(request, _settings);

            return(SendToServer(data));
        }
コード例 #5
0
        public Task Subscribe_Chart(string symbol)
        {
            var request = new TDRealtimeRequestContainer
            {
                requests = new TDRealtimeRequest[]
                {
                    new TDRealtimeRequest
                    {
                        service    = "CHART_EQUITY",
                        command    = "SUBS",
                        requestid  = 2,
                        account    = _account.accountId,
                        source     = _prince.streamerInfo.appId,
                        parameters = new TDRealtimeParams
                        {
                            keys   = symbol,
                            fields = "0,1,2,3,4,5,6,7,8"
                        }
                    }
                }
            };
            var data = JsonSerializer.Serialize(request);

            return(SendString(data, _cancel.Token));
        }
コード例 #6
0
        private Task Login()
        {
            //Converts ISO-8601 response in snapshot to ms since epoch accepted by Streamer
            var tokenTimeStampAsDateObj = DateTime.Parse(_prince.streamerInfo.tokenTimestamp);
            var tokenTimeStampAsMs      = tokenTimeStampAsDateObj.ToUniversalTime().ToUnixTimeMilliseconds();

            NameValueCollection queryString = HttpUtility.ParseQueryString(string.Empty);

            queryString.Add("userid", _account.accountId);
            queryString.Add("company", _account.company);
            queryString.Add("segment", _account.segment);
            queryString.Add("cddomain", _account.accountCdDomainId);

            queryString.Add("token", _prince.streamerInfo.token);
            queryString.Add("usergroup", _prince.streamerInfo.userGroup);
            queryString.Add("accessLevel", _prince.streamerInfo.accessLevel);
            queryString.Add("appId", _prince.streamerInfo.appId);
            queryString.Add("acl", _prince.streamerInfo.acl);

            queryString.Add("timestamp", tokenTimeStampAsMs.ToString());
            queryString.Add("authorized", "Y");

            var credits = queryString.ToString();
            var encoded = HttpUtility.UrlEncode(credits);

            var request = new TDRealtimeRequestContainer
            {
                requests = new TDRealtimeRequest[]
                {
                    new TDRealtimeRequest
                    {
                        service    = "ADMIN",
                        command    = "LOGIN",
                        requestid  = Interlocked.Increment(ref _counter),
                        account    = _account.accountId,
                        source     = _prince.streamerInfo.appId,
                        parameters = new
                        {
                            token      = _prince.streamerInfo.token,
                            version    = "1.0",
                            credential = encoded,
                        }
                    }
                }
            };
            var data = JsonConvert.SerializeObject(request);

            return(SendToServer(data));
        }
コード例 #7
0
        private Task LogOut()
        {
            var request = new TDRealtimeRequestContainer
            {
                requests = new TDRealtimeRequest[]
                {
                    new TDRealtimeRequest
                    {
                        service    = "ADMIN",
                        command    = "LOGOUT",
                        requestid  = Interlocked.Increment(ref _counter),
                        account    = _account.accountId,
                        source     = _prince.streamerInfo.appId,
                        parameters = new { }
                    }
                }
            };
            var data = JsonConvert.SerializeObject(request);

            return(SendToServer(data));
        }