public TickerHub(ILogger <TickerHub> logger, IConfiguration configuration, IMemoryCache cache, Ticker ticker, TickCache tickCache) { _logger = logger; _configuration = configuration; _ticker = ticker; _ticker.OnConnect += this.OnTickerConnect; _ticker.OnClose += this.OnTickerClose; _ticker.OnError += this.OnTickerError; _ticker.OnTick += this.OnTick; this._cache = cache; this._tickCache = tickCache; }
/// <summary> /// Initialize websocket client instance. /// </summary> /// <param name="APIKey">API key issued to you</param> /// <param name="UserID">Zerodha client id of the authenticated user</param> /// <param name="AccessToken">Token obtained after the login flow in /// exchange for the `request_token`.Pre-login, this will default to None, /// but once you have obtained it, you should /// persist it in a database or session to pass /// to the Kite Connect class initialisation for subsequent requests.</param> /// <param name="Root">Websocket API end point root. Unless you explicitly /// want to send API requests to a non-default endpoint, this can be ignored.</param> /// <param name="Reconnect">Enables WebSocket autreconnect in case of network failure/disconnection.</param> /// <param name="ReconnectInterval">Interval (in seconds) between auto reconnection attemptes. Defaults to 5 seconds.</param> /// <param name="ReconnectTries">Maximum number reconnection attempts. Defaults to 50 attempts.</param> public Ticker(IConfiguration _configuration, IMemoryCache _memoryCache, IHubContext <TickerHub> hubContext, TickCache tickCache) { _debug = false; bool.TryParse(_configuration.GetValue <string>("Debug"), out _debug); _tickCache = tickCache; //_apiKey = configuration.GetValue<string>("kiteApiKey"); //KiteAccessTokenResponseRoot kiteAccessTokenResponseRoot = null; //bool cacheFetchResult = memoryCache.TryGetValue<KiteAccessTokenResponseRoot>("kite_access_token", out kiteAccessTokenResponseRoot); //if (cacheFetchResult) //{ // _accessToken = kiteAccessTokenResponseRoot.data.access_token; //} _hubContext = hubContext; configuration = _configuration; memoryCache = _memoryCache; _subscribedTokens = new Dictionary <UInt32, string>(); _interval = int.MinValue; _timerTick = int.MinValue; _retries = int.MinValue; _isReconnect = false; int.TryParse(configuration.GetValue <string>("ReconnectInterval"), out _interval); int.TryParse(configuration.GetValue <string>("ReconnectInterval"), out _timerTick); int.TryParse(configuration.GetValue <string>("ReconnectTries"), out _retries); bool.TryParse(configuration.GetValue <string>("Reconnect"), out _isReconnect); // initialize websocket _ws = new WebSocket(); _ws.OnConnect += _onConnect; _ws.OnData += _onData; _ws.OnClose += _onClose; _ws.OnError += _onError; // initializing watchdog timer _timer = new System.Timers.Timer(); _timer.Elapsed += _onTimerTick; _timer.Interval = 1000; // checks connection every second }