UKDeveloper99 0 Report post Posted October 20, 2016 Hi I'm finding the API documentation for streaming quite limited. I'm using the LightStreamer .NET client to connect to the streaming server. I've got a couple of questions. 1. Is there a specific port number for the streaming server e.g. https://push.cityindex.com:802. Does the streaming server use the same authentication as the regular HTTP Trading API? Because the LightStreamer client has a username and password for connection info but doesn't have anything for adding a Header to the request.3. Is there any code examples that I can reference creating a client to connect to the streaming service?Regards, Mark Share this post Link to post
Physicsman 25 Report post Posted October 21, 2016 Hello, 1) No port number is necessary. 2) subscribing to the real-time data streams requires authentication information to subscribe (your account user name and the password is the Session ID received when logging into the REST part of the API). 3) http://www.lightstreamer.com/download/#previous (we use version 5 of lightstreamer) Look under client development kits there is API Docs and SDK’s for each client language. Kind Regards, PM! Share this post Link to post
UKDeveloper99 0 Report post Posted October 21, 2016 Hi, yeah I figured out the authentication information after stumbling across this old Github project on google.https://github.com/cityindex-attic/CIAPI.CSWould really benefit people if they added that to the documentation. Save them a lot of time as it's not obvious at all that the session token goes in the password field. I can see the reasoning for it however.I'll figure out the actual data subscription part hopefully. Will post back here if I get stuck.Thanks. Share this post Link to post
Physicsman 25 Report post Posted October 21, 2016 Hi, Thank you for the helpful feedback. The information is currently in the API documentation regarding the Streaming API authentication. Clearly it is not prominent enough from a user perspective so we shall make it clearer during the next documentation refresh. We're always looking to improve the documentation so this is very valuable feedback to spot these problems! For reference, currently the information is in this page: http://docs.labs.cityindex.com/#Getting Started/CIAPI Arky.htm%3FTocPath%3DGetting%2520Started%7C_____1. Open the Streaming API section and it is in point 3. Kind Regards, PM! Share this post Link to post
UKDeveloper99 0 Report post Posted October 21, 2016 My apologies, must have missed that.Yeah it could definitely be more prominent. I would suggest possibly a more clearly defined "streaming" section rather than putting it under headers like CIAPI Architecture.Thanks. Share this post Link to post
UKDeveloper99 0 Report post Posted October 21, 2016 Hi again, despite fiddling around with multiple settings in the Lightstreamer .NET Client I can't seem to get more than one response in the OnUpdate callback in my IHandyTableListener. Here's my logging output: ConnectionListener::OnConnectionEstablished ConnectionListener::OnSessionStarted polling=False Thread started: <Thread Pool> #17 TradingPlatformHandyTableListener::OnUpdate itemPos=1 itemName= update=[ 0, 0, -1, 0, 0, 0, 0, 0, 0, 6, GBP ] ConnectionListener::OnNewBytes bytes=30 So it looks like I'm getting the first data correctly, just nothing after that.Connection info is the following. ConnectionInfo connInfo = new ConnectionInfo(); connInfo.PushServerUrl = serverUrl; connInfo.Adapter = "STREAMINGALL"; connInfo.User = "SENSORED"; // REMOVED THIS FOR DATA PROTECTION PURPOSES connInfo.Password = "SENSORED"; // REMOVED THIS FOR DATA PROTECTION PURPOSES and finally here is my SimpleTableInfo object. var hl = new TradingPlatformHandyTableListener(listener, 0); SimpleTableInfo tableInfo = new SimpleTableInfo("CLIENTACCOUNTMARGIN", "MERGE", "Cash Margin MarginIndicator NetEquity OpenTradeEquity TradeableFunds PendingFunds TradingResource TotalMarginRequirement CurrencyId CurrencyISO", true); tableInfo.DataAdapter = "CLIENTACCOUNTMARGIN"; client.SubscribeTable(tableInfo, hl, false); Is there any settings I could be missing such as polling=true (doesn't make a difference)Or specific timeout settings in milliseconds.Thanks in advance, Mark. Share this post Link to post
Physicsman 25 Report post Posted October 24, 2016 Hi Mark, From the code you posted, you're listening to the CLIENTACCOUNTMARGIN stream. This won't change unless you have open positions, so that updated account margin values will be streamed. If you listen to the PRICES stream and subscribe to a market, then you'll receive live updating prices information in a continuous stream. I think you're trying to get your streaming code to work? Kind Regards, PM! Share this post Link to post
UKDeveloper99 0 Report post Posted October 24, 2016 Hi, that's correct, I'm just trying to get the stream working. Ah I see, that makes sense. Could you possibly supply me with a marketId that is constantly updated so I can use that for testing?Best regards, Mark Share this post Link to post
UKDeveloper99 0 Report post Posted October 24, 2016 Okay just took the Wall Street CFD market information from the main site. Looks like it's all working correctly.Thanks for the help.So am I correct in assuming there are other parts streams dependent on having open positions?Cheers,Mark. Share this post Link to post
Physicsman 25 Report post Posted October 24, 2016 Hi Mark, Sure. I don't know if you have a Spreadbet, CFD or both account so I've supplied the UK100 MarketID for both variants. UK100 DFT: 400616113 UK100 CFD: 99500 To find the MarketID for any other market you are interested in, please follow the directions provided at: http://docs.labs.cityindex.com/#How Do I/Find Market ID.htm%3FTocPath%3DHow%2520Do%2520I...%253F%7C_____1. Kind Regards, PM! Share this post Link to post
Physicsman 25 Report post Posted October 24, 2016 Hi Mark, "So am I correct in assuming there are other parts streams dependent on having open positions?" If I understand the question correctly, you are asking if any other streams are dependent upon having open positions? The TRADEMARGIN stream updates the margin required for each trade (open position), so this stream is also dependent. Kind Regards, PM! Share this post Link to post
UKDeveloper99 0 Report post Posted October 24, 2016 Thanks for that. One final question.Am I able to place a dummy/test trade or a trade that doesn't require having account balance? For the purposes of testing the above streams that require having open positions.I have a contact who set up my test account so it could be done via him if required.Does the API have anything in place for that sort of testing or would it require having actual money to place trades.Best regards, Mark Share this post Link to post
Physicsman 25 Report post Posted October 24, 2016 There are simulate trade commands but they won't help in testing the margin streams. You can use the API with a test/demo account to place trades and then test your streaming code when listening to the margin streams. Please let me know if your test/demo account has expired and I can create a new one for you. Kind Regards, PM! Share this post Link to post
UKDeveloper99 0 Report post Posted October 24, 2016 That will require me to add funds to the test account, to actually place the trade, isn't that correct?My current test account is on the live environment.Best regards, Mark Share this post Link to post
Physicsman 25 Report post Posted October 24, 2016 No - test and demo accounts can have "play" or "fake" money (usually £20,000 by default.) These test and demo accounts can be on the Live environment or on Pre-Production. Your current Live Test account should have some "play" funds in the account? That way, you can place trades using the test account on the Live environment without using real money and any wins/losses are purely for testing purposes. If your test account has a zero balance please inform me and I'll send you a PM with the credentials of a funded Live test account. Kind Regards, PM! Share this post Link to post
UKDeveloper99 0 Report post Posted October 24, 2016 As far as I can tell my current live test account has 0 funds available.If you could send me a funded live test account that would be excellent. Best regards, Mark Share this post Link to post
Physicsman 25 Report post Posted October 24, 2016 I've sent you a PM on this forum with the credentials for a funded Live Test account for API testing. Cordially, PM! Share this post Link to post
UKDeveloper99 0 Report post Posted October 31, 2016 Hi PhysicsMan, another question for you. Currently I'm using the TRADEMARGIN stream to get the margin requirement and unrealized profit and loss for all my open positions. When I compare them with the open positions list in the front end client Advantage Web for city index. I notice that the unrealized profit and loss values are updating at the same rate as the price value for the market.Whereas as the Trade Margin stream updates come in about every 25-30 second (per position). How do I get the unrealized profit and loss values to stream at the same rate as the price updates? var tradeMarginListener = new TradeMarginHandyTableListener(tradeMarginFieldsArray, ref openPositions); SimpleTableInfo tableInfo = new SimpleTableInfo("TRADEMARGIN", "RAW", tradeMarginFields, false); tableInfo.DataAdapter = "TRADEMARGIN"; Share this post Link to post
Physicsman 25 Report post Posted November 1, 2016 Hello, I've checked with our development team and the front end Advantage Web platform listens to the TRADEMARGIN stream. The platform uses the P&L values from that stream in the display of unrealised P&L. Was it the same market that you were comparing the P&L? Cordially, PM! Share this post Link to post
UKDeveloper99 0 Report post Posted November 1, 2016 Hi, yes if you look at the dashboard in advantage web each position has a current price field. Which is the current market price for that field. The P&L values match the updates of the market price, I use the Open Trade Equity value for P&L from the stream. If you look over to the right there is also a Margin Requirement for each position. This updates less often. My updates come in at the same rate as the updates on the Margin Requirement field (about once every 25 seconds). I have about 10 open positions and they all update at the exact same time. When the Margin Requirement updates. Even though all the Market prices are changing during these gaps.Is it possible that I have to subscribe to the prices stream to get the updates to come in at the same rate as the price updates? This obviously won't work, just throwing out ideas.Best regards, Mark Share this post Link to post
Physicsman 25 Report post Posted November 1, 2016 Hello, For accounts under some account operators (brands), the front-end client (Advantage Web in this case), has code to manually calculate and update the Unrealised P&L values with each incoming price. since you are seeing updating P&L with prices your account in in one of the brands where the front end code is applicable. Should you not want to wait for the updated P&L from the TRADEMARGIN stream, then code will have to be written to calculate the Unrealised P&L from the incoming market prices. In this case, you will need to subscibe to the PRICES stream for each market that you have an open position. Cordially, PM! Share this post Link to post
UKDeveloper99 0 Report post Posted November 2, 2016 Morning, So from what I can understand from your previous post. It's not possible without a manual calculation?i.e. Subscribe to the Market Price for all the open positions from the PRICES stream. Calculate the Unrealized Profit and Loss using price bought at and current price etc. Seems like it would be a lot easier to just update the TRADEMARGIN stream at the same rate as the prices.Regards, Mark Share this post Link to post
Physicsman 25 Report post Posted November 2, 2016 Hi, Yes, that is correct. The TRADEMARGIN stream updates the unrealised P&L at the rate you have observed, which is generally not at the same rate as incoming market prices. To see the unrealised P&L update at the same rate as incoming market prices, additional coding to calculate the P&L based on each incoming price tick is required. Sorry that it's not better news! Cordially, PM! Share this post Link to post
bluehorseshoe 0 Report post Posted October 3, 2019 (edited) additional coding to calculate the P&L based on each incoming price tick is required. Is the formula for the above calculation available in some example? Edited October 3, 2019 by bluehorseshoe Share this post Link to post
Physicsman 25 Report post Posted October 4, 2019 Hello, Unfortunately no, we don't have anything written up. Kind Regards, PM Share this post Link to post