Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Interactive Brokers TWS API - send commands directly.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Interactive Brokers TWS API - send commands directly.

    Unsupported I know but. . .

    If anyone has sample code for talking directly to the TWS API from within a Ninjascript indicator/strategy/addon I would appreciate seeing it.

    Looking to take advantage of some of the more complex order types.

    Thanks!

    #2
    Hello,

    Thank you for the post.

    I just wanted to post a quick message to describe the supported connections. NT8 has the ability to interface with both the TWS client or the IB Gateway, outside of these two options we would not have any other connection options for Interactive Brokers.

    If any forum members have experience with using the IB API directly, they can post that information here.

    The supported connections are listed at the following address: http://ninjatrader.com/ConnectionGui...nnection-Guide

    If you can describe the specific orders you are trying to take advantage of, that may help members recommend ideas in case what you are asking is not possible.

    Please let me know if I may be of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      If you can describe the specific orders you are trying to take advantage of, that may help members recommend ideas in case what you are asking is not possible.
      I would like to make use of the adaptive algo order type:
      https://www.youtube.com/watch?v=rKlGKpk68rY

      Comment


        #4
        I would also like details on how to call the TWS API directly from within a ninjascript indicator.

        I don't understand why the staff from ninjatrader cannot provide these details when obviously you are calling the TWS API in your code when placing orders when connected to either TWS or the gateway.

        I want to know which "using" declaration at the start of a script is needed to be able to access the api?

        I want to include this code in an indicator that will allow me to place orders exactly where I want them:
        https://interactivebrokers.github.io...ket_order.html

        I want to be able to place bracket orders directly with IB on the IB servers, as ninjatrader is not capable of custom coding different stop and targets for every order placed in an ATM strategy directly in a ninjascript (it has to be done manually by hand!!). A side note is that ninjatrader is also too slow in placing the bracket orders in a fast moving market, as it requires a fill response before the oco orders are placed and the price could be past your stop by this time. So much for being fast like a ninja .

        Very surprised you are so unwilling to provide these details when obviously you have them as you use them.

        Comment


          #5
          Hello petermb,

          API's are interfaced through the Connection Adapter used to connect you with your broker's feed. Connection Adapters are internal to the platform and closed source. There is not any exposed NinjaScript access to directly interface with the broker's API.

          Initiating ATM strategies from NinjaSript strategies are meant to do just that: if you have an ATM strategy you like using, you can initiate it from your NinjaScript strategy. If you are looking for more custom functionality, that functionality would be best programmed in the NinjaScript strategy rather than trying to build a custom ATM strategy on the fly. If you would like to build an ATM strategy on the fly, you could do so by getting familiar with the format of the ATM strategy template and using a StreamWriter to create the ATM strategy template XML file.

          An indicator that incorporates a StreamWriter can be found here - https://ninjatrader.com/support/help...o_write_to.htm

          Please let us know if you have any questions.
          JimNinjaTrader Customer Service

          Comment


            #6
            Hi Jim,

            Thanks for your comments, but I don't think that you understand the use-case.

            I want to trade off the chart where I make the manual decisions of when to enter the market myself.
            However I have an indicator on the chart which gives me the value to enter at and it also gives me the values for the stop and target. As this is a fast moving market and I enter on 1 minute bars, I do not have the time to find all three values and enter them manually into a custom ATM strategy and then place the order. Whether this is through a StreamWriter XL template or not.

            I do not want to use a ninjascript strategy as this is fully automated and does not give me the option to choose on the chart when I want to enter the market. Unless there is a way to have manual inputs into a strategy while it is running. I may also want to slightly modify the stop and target orders manually after entering, like I can do with an ATM Strategy.

            I assume none of what you have suggested is able to achieve this, and it's crazy because I assume a lot of traders trade this way.

            However.....
            It seems that I can reference the TWS API in a ninjascript, if I install the API in the bin\custom folder.
            https://ninjatrader.com/support/foru...or?postcount=4

            I can then compile the code by prefixing any calls like Order() with IBApi.Order().
            Does this mean that I would also have to make a connection to TWS or the gateway from inside the ninjascript indicator, or would I be able to route these orders through the existing ninjatrader connection?
            I could have the indicator (ninjascript) connect to the IB Gateway and have Ninjatrader connected to IB TWS (both on the same account with different users). This way the initial entry order could be placed through the gateway and the management of the subsequent stop and target orders could occur on the screen using chart trader. Would this work?

            Comment


              #7
              Hello petermb,

              It is possible to write a NinjaScript strategy that adds button controls for manual entry, and it is also possible to collect some information on the chart like a price level which is clicked. You could implement buttons that allow market entries, or you could have a button that puts the strategy in a state where it will place a limit order at a price clicked. I have linked and attached some scripts that can help shed some light on how you can work in manual order entry in your strategy.

              Long Short Toolbar (implementing buttons for manual entry) - https://ninjatraderecosystem.com/use...bar-buttons-2/

              The attached script is an indicator which uses AddOn Framework code to place limit orders on mouse clicks. Instead of using the AddOn Framework code, NinjaScript strategy code can be used for order submission and the functionality can be worked into a strategy instead of an indicator.

              The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

              You could add a DLL and interface with that within your own script, and the thread you linked can help shed some light on adding external DLL's but using that code would be outside the context of what we could support. I am not sure if TWS' API could be used for multiple API connections using the same account, so I could not say if that would work or not. If you want to try it out, I am sure other community members would like to hear your findings.

              I'll be happy to answer any other questions if you need further insight to add manual entry functionality to a NinjaScript strategy, just let me know.
              Attached Files
              JimNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by WaveAtElliot, Today, 05:11 PM
              1 response
              7 views
              1 like
              Last Post hdge4u
              by hdge4u
               
              Started by bosajin, Yesterday, 09:15 AM
              5 responses
              36 views
              0 likes
              Last Post NinjaTrader_Jim  
              Started by Dolfan, Today, 12:24 PM
              4 responses
              23 views
              0 likes
              Last Post NinjaTrader_Jim  
              Started by WeyldFalcon, Today, 11:09 AM
              7 responses
              26 views
              0 likes
              Last Post WeyldFalcon  
              Started by DTSSTS, 08-10-2020, 09:48 AM
              12 responses
              67 views
              0 likes
              Last Post DTSSTS
              by DTSSTS
               
              Working...
              X