szcxdave1988 0 Report post Posted February 11, 2019 HI, I got error: WebSocket is closed before the connection is established. when try to get the live stream data. I download the v5,1,2 for js, but when i open the file it shows version 6.1.4, and the v5 already no supported by lightstreamer.so is the error from the version problem or anything else, please help Share this post Link to post
Physicsman 25 Report post Posted February 13, 2019 Hi, We're still using the older Lightstreamer versoin 5 on our backend servers, so it will have incompatibility problems with the v6.1.4 SKD you are using. You can still download the appropriate LS versoin 5.1.2 SDK for the programming language you are using at: https://lightstreamer.com/download/#ls5. That should help with any incompatibility issues. Kind Regards, PM Share this post Link to post
szcxdave1988 0 Report post Posted February 13, 2019 Thanks, I download this one, but still shows error, is it the file in /DOCS-SDKs/sdk_client_javascript/lib/lightstreamer.js? the comment fort this file also shows Version 6.1.4 not 5.1.2 Share this post Link to post
Physicsman 25 Report post Posted February 15, 2019 Hi, Could you paste in the code you've written where you are logging in/authenticating with lightstreamer and then attempting to subscribe to the live streaming market prices? Presumably you receive OK respones for login/authentication? You only receive the websocket error message when you attempt to subscribe to market price streams? Many thanks, PM Share this post Link to post
szcxdave1988 0 Report post Posted February 16, 2019 const url = 'https://ciapi.cityindex.com/TradingAPI/session'; const data = { 'Password': '****', 'AppVersion': '1', 'AppComments': '', 'UserName': '*****', 'AppKey': '****' }; this.http.post(url, data).subscribe( (info) => { const client = new LightstreamerClient('https://pushpreprod.cityindextest9.co.uk/?UserName=****&Session=' + info['Session'], 'PRICES'); client.connect(); const grid = new StaticGrid('hellogrid', true); const subscription = new Subscription('MERGE', grid.extractItemList(), grid.extractFieldList()); subscription.addListener(grid); client.subscribe(subscription); }, (error) => { console.log(error); }, ); Share this post Link to post
Physicsman 25 Report post Posted February 18, 2019 Hi, I notice that you are attempting to connect to the Lightstreamer on our preproduction environment URL, whereas your login and credentials are from our LIVE environment. Credentials are not compatible between the 2 environments. Please change the Lightstreamer URL to the Live environment at: https://push.cityindex.com/ and hopefully this will resolve the issue. Kind Regards, PM Share this post Link to post
szcxdave1988 0 Report post Posted February 18, 2019 THanks, I have changed the url, but shows CORS errors: Access to XMLHttpRequest at 'https://push.cityindex.com/?UserName=****&Session=*********/lightstreamer/create_session.js' from origin 'http://localhost:4000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Share this post Link to post
Physicsman 25 Report post Posted February 19, 2019 Hi, I checked and verified that CORS is enabled on our servers by using CURL to simulate a preflight request with an origin of "http://example.com" and received back the expected Access-Control-Allow-Origin, Access-Control-Allow-Methods, and Access-Control-Allow-Headers. A similar issue that occurred in the past with another client is described in: http://faq.labs.gaincapital.com/topic/1034-cross-origin-resource-sharing-cors/. It's possible your POST header has a similar typing / syntax error when specifying contentType: 'application/json'? Kind Regards, PM Share this post Link to post
szcxdave1988 0 Report post Posted February 21, 2019 Thanks, but it' s not work. I change to put the username and session in header, and get errors different, I think almost there: Access to XMLHttpRequest at 'https://push.cityindex.com/lightstreamer/create_session.js' from origin 'http://localhost:4200' has been blocked by CORS policy: Request header field headers is not allowed by Access-Control-Allow-Headers in preflight response. this.http.post(url, data).subscribe( (info) => { const headers = new HttpHeaders({ 'Content-Type': 'application/json', 'Session': *****, 'UserName': ****** }); const options = { headers: headers }; const client = new LightstreamerClient('https://push.cityindex.com/', 'PRICES'); client.connectionOptions.setHttpExtraHeaders(options); client.connect(); const grid = new StaticGrid('hellogrid', true); const subscription = new Subscription('MERGE', grid.extractItemList(), grid.extractFieldList()); subscription.addListener(grid); client.subscribe(subscription); }, (error) => { console.log(error); }, ); Share this post Link to post
Physicsman 25 Report post Posted February 22, 2019 Hi, Looking at that error message I found the following thread on Stack Overflow: https://stackoverflow.com/questions/32500073/request-header-field-access-control-allow-headers-is-not-allowed-by-itself-in-pr There are many solutions there that should resolve the error message you have encountered. Kind Regards, PM Share this post Link to post
szcxdave1988 0 Report post Posted February 25, 2019 thanks, I solved the problem by add auth info this way. client.connectionDetails.setPassword(***); client.connectionDetails.setUser(***); but error again with: WebSocket connection to 'wss://push.cityindex.com/lightstreamer' failed: WebSocket is closed before the connection is established. Share this post Link to post
Physicsman 25 Report post Posted February 26, 2019 Hi, I did some searching on the Lightstreamer forum and I found a post from one of their staff: Quote At present, only the JavaScript client libraries (for both web browsers and Node) use WebSockets, in addition to HTTP, while the other libraries use HTTP only. Which client library are you using? A likely reason for the failure message you are receiving is because the LS client library you are using is one that does not support WebSockets but HTTP only. Kind Regards, PM Share this post Link to post
szcxdave1988 0 Report post Posted March 4, 2019 its's wired, I am using the JavaScript client libraries Share this post Link to post
Physicsman 25 Report post Posted March 5, 2019 Hi, According to Lightstreamer: Quote The message reported means that a websocket close was called before the connection was even given a chance to be established.This can happen when the JavaScript library determines that has been too long in an attempt to connect; so it gives up and tries some fallbacks (HTTP streaming, polling, ...).Please could you confirm that despite the error message then the connection eventually succeeds?The most likely reason for the failure of websocket is that between the server and the client there is some intermediary (such as a proxy) that does not support WS protocol, and prevent the client request to reach the Lightstreamer server. It's possible you may have more success by using HTTP instead of WebSockets. Kind Regards, PM Share this post Link to post
szcxdave1988 0 Report post Posted March 11, 2019 how can i get the real time price data steam if i use http instead of subscribe to socket? thansk Share this post Link to post
Physicsman 25 Report post Posted March 13, 2019 Hi, Subscribe to the price stream of the market of interest in a similar manner to when using websockets. Some rough skeleton code is provided below based on the LS documentation - you can find the Lightstreamer documentation in a link next to the development kit you are using from the Lightstreamer site at: https://lightstreamer.com/download/#ls60 var ls = require("lightstreamer-client"); var lsClient = new ls.LightstreamerClient("https://push.cityindex.com", "STREAMINGALL"); lsClient.connectionDetails.setUser("xxxxx"); lsClient.connectionDetails.setPassword("xxxxx"); lsClient.connect(); marketId = "xxxxx"; var testSubscription = new ls.Subscription("MERGE", ["PRICE." + marketId], ["MarketId", "TickDate", "Bid"]); testSubscription.setDataAdapter("PRICES"); testSubscription.setRequestedSnapshot("yes"); lsClient.subscribe(testSubscription); lsClient.addListener({ onStatusChange: function (newStatus) { console.log(newStatus); }, onServerError: function (errorCode, errorMessage) { console.log(errorCode); console.log(errorMessage); } }); Kind Regards, PM Share this post Link to post
szcxdave1988 0 Report post Posted April 10, 2019 Thanks, now, i switch from angular to node js and erverything works fine, would like to know how to get the Maket ID Share this post Link to post
Physicsman 25 Report post Posted April 11, 2019 Hi, To find the Market ID for a market, you make a ListMarketSearch call through the REST API. See the following topic from the API documentation for further information: http://docs.labs.gaincapital.com/#How Do I/Find Market ID.htm%3FTocPath%3DHow%20Do%20I...%3F|_____1 Kind Regards, PM Share this post Link to post
szcxdave1988 0 Report post Posted April 22, 2019 Thanks. is there any api that i can get all the history price for each market ID. Right now i can use GetPriceBarsBeforeDate, but has a 4000 max to show. Share this post Link to post
Physicsman 25 Report post Posted April 30, 2019 Hello, Due to the amount of price history we store for markets, the hard limit of 4000 is enough to retrieve the entirety of the data for a market. As an example, we have GBP/USD daily data going back to 2005, which gives an approximate count of 14 years x 260 bars in a year = 3660 data points. Kind Regards, PM Share this post Link to post