Node.js library for Interactive Brokers TWS API - Custom order builder

Currently utilizing the node-ib npm package, I am aiming to execute a Combination Order.

Here are the steps I followed:

  1. Obtaining the contract IDs for both leg definitions.

  2. Once the program successfully obtains the conId value for each leg, it is then included in the ComboLeg object.

  3. Subsequently, the placeOrder() method is invoked with the contract and order objects.

    var leg1 = {
        conId: c1,
        ratio: 1,
        action: "SELL",
        exchange: "SMART",
        openClose: 0,
        shortSaleSlot: 0,
        designatedLocation: ""
    }
    
    var leg2 = {
        conId: c2,
        ratio: 1,
        action: "BUY",
        exchange: "SMART",
        openClose: 0,
        shortSaleSlot: 0,
        designatedLocation: ""
    }
    
    var legs = [leg1, leg2];
    
    ib.placeOrder(
        6,
        ib.contract.combo("USD", "USD", "SMART", legs),
        ib.order.limit("BUY", 1, 1)
    );
    
    ib.reqOpenOrders();
    

The values of c1 and c2 represent the conIds.

I encountered difficulty in adding comboLegs to the contract, hence I modified /node_modules/ib/lib/contract/combo.js by introducing a new argument into the function.

function combo(symbol, currency, exchange, comboLegs) {
   assert(_.isString(symbol), 'Symbol must be a string.');

  return {
     currency: currency || 'USD',
     exchange: exchange || 'SMART',
     secType: 'BAG',
     symbol: symbol,
     comboLegs: comboLegs || []
 };
}

The last argument signifies my modification.

Although no errors were reported, the combo order failed to appear on the Trader WorkStation.

In contrast, regular orders were successfully added to the Trader WorkStation without any issues.

If anyone has insights on how to include a combo order on the Trader WorkStation using API through this npm, your assistance would be greatly appreciated.

Thank you all:)

Answer №1

Although it may seem belated, for those who stumble upon this seeking a solution, here is what worked for me. You don't have to modify any library files. Simply ensure that you obtain your c1 and c2 using reqContractDetails() for each.

  var leg1 = {
      conId: c1,
      ratio: 1,
      action: "BUY",
      exchange: "SMART",
  }
  var leg2 = {
      conId: c2,
      ratio: 1,
      action: "SELL",
      exchange: "SMART",
  }

  var contract = ib.contract.combo(symbol);
  contract.comboLegs = [leg1, leg2];

  console.log(`contract = `, contract);

  ib.placeOrder(
      601,
      contract,
      ib.order.limit("BUY", 1, 1)
  );

For reference, here is an illustration of how to acquire c1 and c2:

ib.reqContractDetails(0, ib.contract.option('AAPL', '20210115', 130, 'C'));
ib.reqContractDetails(1, ib.contract.option('AAPL', '20210115', 145, 'C'));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Convert incorrectly formatted XML content into an HTML bulleted list

Currently, I am tackling a project that involves parsing an XML tree with less-than-ideal formatting. The task at hand is to create a UL structure from this XML data, but the challenge lies in all nodes having the same name with varying attributes. To achi ...

Regular expression in JavaScript that specifically matches numbers formatted in the style of JavaScript

My goal is to develop a javascript regular expression that specifically identifies valid Javascript-style numbers. The requirements entail accommodating an optional minus or plus sign before the number, recognizing the decimal dot, and supporting exponent ...

Pattern of using MongoDB with Node.js

After doing some research, I've come across a design related to MongoDB driver that caught my attention. As mentioned here, it seems there is no need to constantly open and close connections. To streamline my code and avoid boilerplate, I decided to ...

Can links be integrated into Bootstrap 4 nav-pills tab-panel from another webpage?

I've managed to set up a service page with bootstrap 4's pills .nav-pills navigation, and it's functioning quite well. However, my current challenge involves allowing users to click on a link from the home page that will direct them to a spe ...

The dynamic routing feature in React fails to function properly after the application is built or deployed

I'm facing an issue with getting a React route to function properly in the build version of my app or when deployed on Render. Here are the routes I have: <Route path="/" element={userID ? <Home /> : <Login />} /> <Route ...

Issue with Browserify's transform in package.json not functioning correctly on symlinked modules in npm3

Setting: [email protected] [email protected] [email protected] [email protected] Struggling to create an application compatible with npm@2 and babelify@6, facing difficulties when trying to upgrade to npm@3 and babelify@7. Let me elabo ...

Python code allowing users to navigate back to the previous page while retaining elements

After my script scrapes the page, it automatically clicks a button if a new element meeting certain criteria is found. Everything works perfectly when there is only one element, but an issue arises when the button click leads to a new page opening. If ther ...

Unable to cache new entry at the specified location (/Users/android/.gradle/7.5.1/checksums/sha1-checksums.bin) due to a java.io.IOException with the message "Bad file descriptor"

I encountered two errors when trying to run my React Native project. Issue 1: Failed to add entry '/Users/saadafridi/.gradle/.tmp/gradle_download14928641310389655157bin' to cache sha1-checksums.bin (/Users/saadafridi/Desktop/mobileapp/android/.g ...

Error in parsing JSON: An unexpected token < was encountered at the beginning of the JSON input, causing a SyntaxError at position 0 when parsing with

I need to transfer an array from a PHP file to JavaScript and save it in a JavaScript array. Below is the snippet of JavaScript code: xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 ...

Refresh the page when the parameter in the URL changes

I'm encountering a small issue that I can't seem to resolve. Currently, I am on the following page: http://example.com:8080/#/user/5ad142e8063ebb0537c5343e There is a link on this page that points to the URL below: http://example.com:8080/#/u ...

Issue with Saving Query Loop Results in Prisma MySQL with NextJS/ReactJS

I'm struggling with a Prisma query that is giving me grief. Despite my best efforts, I can't figure out why it's not functioning properly. The getImages() method below is intended to retrieve all the images associated with a product. Query ...

Strategies for sending data to child components in Vue

Within my parent component, I am making an API call and receiving a response. My goal is to pass this response as a prop to a child component in Vue. Below is the snippet of the parent component and the API call: <button class="btn button col-2&quo ...

Troubleshooting a Safari bug with element.click()

When the 'subButton2' button is clicked, the 'uploadBtn'(display:none;) should also be clicked. This functionality needs to work across different browsers: http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_html_click The cod ...

Can you explain the meaning of EPS in the THREE.OrbitControl function?

The this.update method within the THREE.OrbitControl script contains a private variable called EPS, which is used to adjust the phi angle. The following code snippet demonstrates how it restricts phi to be between EPS and PI-EPS: // restrict phi to be bet ...

Exploring the Power of Ajax with JQuery on the Django Development Server

I am currently setting up an Ajax request using JQuery (version 1.5) on a Django website running version 1.2.5. I am testing this on the Development Server as I intend to demonstrate it before deploying to production. Below is the javascript code snippet ...

Error Encountered: Issue loading Chunks in Next.js due to Runtime Error not being

I am currently working on a website that processes payments using Stripe and subsequently redirects users to another page via Stripe. For example: https://localhost:3000/payment -> https://localhost:3000/limit-status?payment_intent=ABCD&clien ...

Error in Form Validation: inconsistent positioning of relative jump and sticky header

I have a webpage with a web form and a sticky header. When a user attempts to submit the form without filling in required fields using a modern-ish browser, an error message pops up as expected. The issue arises when the sticky header hides the input field ...

Error encountered: "When attempting to utilize onEnter within react-router, a TypeError occurred stating that hook.apply is not a

Take a look at the following code snippet: function checkAuth(nextState, transition, callback) { console.log('hello'); callback(); } export const AdminList = { 'path': 'admin-area/admin-list', getComponent(location ...

Troubleshooting PHP webpage with dysfunctional Python AJAX functionality

I have been working on developing a website that integrates with a python script to control GPIO pins on my Raspberry Pi. Unfortunately, I've encountered some issues with the code and need some assistance in troubleshooting. Could someone please revi ...

Searching for a cake in CakePHP with autocomplete functionality

$( "#skills" ).autocomplete({source: function(request, response) { $.getJSON("http://server/current/indrealestates.com/properties/autosuggesthome/",{ term:request.term ,extraParams:$('#property_id').val()}, response ); }, ...