/// <summary> /// Sends a request to Questrade to push quote data to this Websocket client. Data is recieved through the OnMessageCallback. /// </summary> /// <param name="ids">Comma seperated symbol id</param> /// <returns></returns> public void StreamQuoteAsync(string ids, CancellationTokenSource cancellationTokenSource) { CancellationToken ct = cancellationTokenSource.Token; Task.Run(() => { var resp = ApiGet <StreamPort>(apiClient, string.Format("v1/markets/quotes?ids={0}&stream=true&mode={1}", ids, streamType.WebSocket.ToString()));//Requests server to send notification to port if (resp.isSuccess) { //Setup Websocket to recieve data from var api_base = new Uri(_auth.api_server); var uri = new Uri(string.Format("{0}{1}:{2}/", @"wss://", api_base.Host, resp.q_obj.streamPort)); quoteStreamClient = new QuestradeWebsocket(); var cancelToken = new System.Threading.CancellationToken(); quoteStreamClient.OnReceive += quoteStreamClient_OnReceive; quoteStreamClient.OnConnect += quoteStreamClient_OnConnect; quoteStreamClient.OnClose += QuoteStreamClient_OnClose; quoteStreamClient.ConnectAsync(uri, cancelToken); quoteStreamClient.SendAsync(_auth.access_token, uri, cancelToken, System.Text.Encoding.ASCII); } }, ct); }
/// <summary> /// Sends a request to Questrade to push notifcations to this Websocket client. Data is recieved through the OnMessageCallback. /// </summary> /// <returns></returns> public void SubToOrderNotifAsync(CancellationTokenSource cancellationTokenSource) { CancellationToken ct = cancellationTokenSource.Token; Task.Run(() => { var resp = ApiGet <StreamPort>(apiClient, string.Format("v1/notifications?mode={0}", streamType.WebSocket.ToString()));//Requests server to send notification to port if (resp.isSuccess) { var api_base = new Uri(_auth.api_server); var uri = new Uri(string.Format("{0}{1}:{2}/", @"wss://", api_base.Host, resp.q_obj.streamPort)); notificationClient = new QuestradeWebsocket(); var cancelToken = new System.Threading.CancellationToken(); notificationClient.OnReceive += NotificationClient_OnReceive; notificationClient.OnConnect += NotificationClient_OnConnect; notificationClient.OnClose += NotificationClient_OnClose; notificationClient.ConnectAsync(uri, cancelToken); notificationClient.SendAsync(_auth.access_token, uri, cancelToken, System.Text.Encoding.ASCII); } }, ct); }