Unlocking WebSockets

    Date:

    Interactive Brokers’ Web API delivers real-time access to Interactive Brokers’ trading functionality, including live market data, market scanners, and intra-day portfolio updates. This podcast introduces WebSocket technology.

    Summary – IBKR Podcasts Ep. 151

    The following is a summary of a live audio recording and may contain errors in spelling or grammar. Although IBKR has edited for clarity no material changes have been made.

    Mary MacNamara

    Hello everybody and welcome to today’s IBKR Podcast. And today, we’re going to talk about the Client Portal API and one of its facets, WebSockets. Anyway, joining me is Andrew Wise. He’s the US API Support Supervisor for Interactive Brokers. So, Andrew, thanks for joining. What is a WebSocket?

    Andrew Wise

    Hi Mary, glad to be here. So, a WebSocket is a sort of asynchronous data stream that allows data to flow into the user’s program after requesting it. It’s a very strongly underutilized tool we find in the Web API because it gives clients the ability to get kind of a non-stop stream of let’s say market data or portfolio information, trades data, all of those things that a lot of users tend to kind of request on a loop. It adds that automated update time for you and that’s kind of the general use at least at Interactive Brokers of what a WebSocket is.

    Mary MacNamara

    And once again, you would be using this within the browser itself. You’d be writing some sort of browser application that would be connecting via this WebSocket to get all this continuous data.

    Andrew Wise

    Yeah, so it would be a lot like our other use cases for the endpoints APIs where you can build it into other browser application or if you just wanted to make a fully automated system that doesn’t have a UI and a WebSocket would work just the same and it is completely flexible for both use cases. Obviously, if you want to see the data in real time, it is an excellent tool and I know I’ve even built it to connect into applications like Excel and it works flawlessly there.

    Mary MacNamara

    Love that! Who can use a WebSocket?

    Andrew Wise

    Yeah. So, the nice thing about the WebSocket is that it has all of the same sort of restrictions, if you want to call it that, of the standard Web API. So, anyone that can use the Web API as we discussed in our last podcast together can use the WebSocket suggest as well.  No extra limitations or fees or anything like that.

    Mary MacNamara

    But you do have to have a funded account, right?

    Andrew Wise

    Yes, it has to be a funding account at Interactive Brokers. And to reiterate from before, it is an IBKR Pro account only doesn’t work with Lite accounts.

    Mary MacNamara

    Got it, OK. So how can you use this?

    Andrew Wise

    So WebSocket technology is ever evolving, and Interactive Brokers are really working harder than ever to bring it up to par. WebSockets are a structure that’s kind of a unanimous system, similar to a rest API. And so, it can be used to stream market data, order information and account details like I mentioned before.

    Mary MacNamara

    OK. So, we talked about the how, when should I use it?

    Andrew Wise

    In instances where a value is constantly needed as soon as it’s available. For most users, the essential values in this case are something like live market data or information about order status and execution. So that way the moment a trade does fill or gets partially executed, you’re able to get that data as soon as it’s provided, which can be a great tool in your kind of day-to-day trading.

    Mary MacNamara

    What can be used to build a WebSocket? Are there any special technologies for it? And so forth?

    Andrew Wise

    So, the beauty of the WebSocket like I was saying, similar to a REST standard, is that it is a standard.  Almost any program that can build out like these REST requests can almost always build out a WebSocket structure. Even Curl has access to build the actual structure. However, not all systems are created equal in the sense that while Curl can build the WebSocket, it doesn’t have the information necessary to send topic requests within it. We most often see things like Python, JavaScript and even actually Postman as a new evolving tool in the WebSocket world. So, you can build everything in just the standard Postman script without too much extra work and it is completely functional in that way to facilitate your WebSockets. In our Python tutorial series cover exactly how to use WebSockets through the use of Python and its WebSocket client library.

    Mary MacNamara

    That’s great. So does that mean Interactive Brokers is going to start maybe using Postman, putting out some examples, just a question about that.

    Andrew Wise

    Oh yeah, certainly. And not to get too in depth on the details, but we actually do have a large restructuring of our existing campus documentation that will feature a lot of Swagger code and access for WebSocket kind of in a Open API spec style and so we should expect that in the near future and as some users may be aware most Open API spec you can import directly into Postman and the same should be going for WebSockets as well.

    Mary MacNamara

    Question should I just use endpoints. The extra request system sounds like it could be complicated.

    Andrew Wise

    So luckily, clients are welcome to use endpoints if that’s something of preference. However, the nice thing about a WebSocket structure over an endpoint is that you’re typically going to have to loop through the endpoint every couple of seconds. Or even every second to try and get that data, whereas with a WebSocket it’s going to provide that feedback instantaneously from Interactive Broker’s side.  We also see several scenarios where clients might be looping over this data very quickly and because of that you might also impede on your pacing limitation which can further exacerbate your other requests.

    Mary MacNamara

    Why don’t you talk about this pacing limitation for those who may not know what it is.

    Andrew Wise

    Generally speaking, Interactive Brokers has a 10 requests per second pacing limitation. And what that means is in order to kind of maintain our infrastructure, we require that users send no more than 10 endpoint requests in any given second. This can include anything from requests for market data, request for portfolio information, all the way to trying to place orders. We kind of cap it off at 10 requests per second, but because WebSockets are a different technology and a different structure building these out won’t actually impede your standard workflow.  So, you can get live market data and then still place 10 orders per second without kind of conflicting one another with those pacing limitations.

    Mary MacNamara

    OK, so if I’m new to web environments as a whole, can this be compared to anything this whole WebSocket technology?

    Andrew Wise

    Certainly, so like I said at the top, it is an asynchronous technology and for users not too familiar with web technologies, but have been trading using the TWS API, they seem to be a lot of similarity here.  Both the TWS API and WebSockets function through this asynchronous environment, where outbound requests are not always met 1:1 with the response. Instead, you’ll often open a large stream of data and retrieve every update as it’s available rather than pinging the server and getting a single response back.

    Mary MacNamara

    If this is like the TWS API, specifically with Python, why wouldn’t I just use that?

    Andrew Wise

    And you certainly could. The nice thing about WebSockets and this goes back to even our prior discussion from the other podcast.  It is the perk of the Web API and that you have a lighter environment. You no longer have to build out the IB Gateway or Trader Workstation on your platform. You’re able to get the lightweight work of a REST API to do all of your requesting.

    You can either use the system interchangeably so that way you could use partially TWS and partially the Web API. But you can also kind of build out new technologies like I said before, I was actually importing the WebSocket into Excel using the Python xlwings Library and that way I can kind of replicate a similar structure as the Trader Workstation API. But now I can do it without having the intense resource demand on my machine and also that gives me the opportunity with the Python library to kind of obfuscate around using Visual Basic so that I can kind of dedicate my own work into Python which I’m already familiar with and into WebSockets, which is another familiar technology for me. So, it can help kind of alleviate that extra level of difficulty you might see using these other programming languages.

    Mary MacNamara

    I love this discussion with the Excel because my experience has been that a lot of people use different platforms because they can integrate the market data into their portfolio within Excel, get the real time data and they’re so familiar with using macros and Excel that this is hugely beneficial.

    Andrew Wise

    Hmm.

    Mary MacNamara

    So, my question is, in order to use this component within the Excel library, do you have to pay extra for it, or does it come with Excel?

    Andrew Wise

    That’s entirely free. And like I said, I actually have been using a library called xlwings. We actually have been working on an article on the other side of the IBKR Campus through the API article feed where we already have integrated xlwings with the TWS API if you want to get a look at that. But in the near future we’re going to be putting out a new article referencing actually how to use WebSockets with that same Python library, but there’s no cost, there’s no extra fees, even though library itself is free. So, it’s one of those things we definitely encourage our users to explore.

    Mary MacNamara

    Is this on the Quant blog?

    Andrew Wise

    This is on the Quant blog.

    Mary MacNamara

    Oh, I love that. OK so for people who don’t know about this, if you’re on the Interactive Brokers website, you go under Education. You can see the campus and the campus has a Quant Blog. The Quant Blog has articles, code snippets. Just from not only Interactive Brokers but other parties as well, other contributors. So, it’s really has a lot of information. Anything you want to add about the new documentation, Andrew?

    Andrew Wise

    Uh, the only thing I can really say about it is it’s one of those things that’s ever evolving and improving. Like I said, we are doing our best to kind of bring it up to the industry standard. And so, there’s going to be a lot of pretty major updates coming in the following month. So, we encourage everybody to check it out. We have dedicated Excel pages there if that’s something people are interested in. And of course, we have a full kind of documentation spread for the Client Portal API as a whole, so definitely check it out.

    Mary MacNamara

    All right, so we’re going to keep this short and sweet. Thank you, Andrew for coming on to this podcast and talking to us about WebSockets. We’re going to do this approximately once a once a month, folks. So, we can get a little techie in our podcast, not only talk about market commentary, but also, programmatically how you can access market data and so forth. All right, so Andrew, have a great weekend and thank you so much once again for joining us.

    Andrew Wise

    You as well, Mary, thank you for having me.

    Web API Documentation

    REST Development

    Disclosure: Interactive Brokers

    The analysis in this material is provided for information only and is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad-based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation by IBKR to buy, sell or hold such investments. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

    The views and opinions expressed herein are those of the author and do not necessarily reflect the views of Interactive Brokers, its affiliates, or its employees.

    Disclosure: API Examples Discussed

    Throughout the lesson, please keep in mind that the examples discussed are purely for technical demonstration purposes, and do not constitute trading advice. Also, it is important to remember that placing trades in a paper account is recommended before any live trading.

    Go Source

    Chart

    SignUp For Breaking Alerts

    New Graphic

    We respect your email privacy

    Share post:

    Popular

    More like this
    Related

    Nvidia’s Blackwell Chips Are Extra Toasty, Server Overheating Issues Impact Meta, Microsoft And Elon Musk’s xAI

    Nvidia Corporation’s NVDA new Blackwell AI chips are reportedly grappling...

    Bitcoin, Ethereum, Dogecoin Slip As Fed’s Hawkish Stance Tempers Rally: Analyst Expects BTC To Reach $100K Before New Year

    Leading cryptocurrencies dipped on Sunday as investors reduced their...

    Gary Black Defends Tesla Strategy Amid Clash With Elon Musk Bulls: ‘We Don’t Trade Tesla… We Trim When The Price Goes Higher’

    The Future Fund LLC, Managing Partner Gary Black pushed back against...

    Nikki Haley Says Biden’s Weakness On Iran Is Ending, But Will Trump’s Vow To Stop Iran’s China Oil Windfall Wound The Dollar?

    Former Governor of South Carolina and erstwhile presidential candidate...