0

I am new to java though I have some experience with R.

I have taken part of a java course and have read a book or two as well as the API guides published by interactive brokers. This API is higher level than anything I have worked with before, obviously.

The very first thing I want to do is simply connect to the software. I have been able to do this with the test GUI that Interactive Brokers provides. However, when writing my own script, I am getting an error: Uncompilable source code - Erroneous sym type. I have imported the javaclient/com directory into my new project.

The line that is causing the error is econnect(port=7496, clientid=0);

Reading the documentation, this should work, but obviously does not.

Below is the full code. All of the import calls were copied from a sample file that IB provided. onHowToDetermineStock() is copied from another part of the documentation. Before I can do anything, I obviously need to to connect.

Any ideas?

Thank you.

package ibapp;


import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.util.ArrayList;

import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;

import com.ib.controller.ApiConnection.ILogger;
import com.ib.controller.ApiController;
import com.ib.controller.ApiController.IBulletinHandler;
import com.ib.controller.ApiController.IConnectionHandler;
import com.ib.controller.ApiController.ITimeHandler;
import com.ib.controller.Formats;
import com.ib.controller.Types.NewsType;

import com.ib.client.EClientSocket;


/**
 *
 * @author
 */

void onHowToDetermineStock(){

       Contract contract = new Contract();
       Order order = new Order();

       contract.m_symbol = "IBKR";
       contract.m_secType = "STK";
       contract.m_exchange = "SMART";
       contract.m_currency = "USD";

       order.m_action = "BUY";
       order.m_totalQuantity = 100;
       order.m_orderType = "LMT";
       order.m_lmtPrice = enteredLmtPrice;

       m_client.placeOrder(GlobalOrderId, contract, order);

}

public class IBApp {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        econnect(port=7496, clientid=0);
        onHowToDetermineStock();
    }

}
sashkello
  • 17,306
  • 24
  • 81
  • 109
mks212
  • 901
  • 1
  • 18
  • 40
  • FYI, there is also a python api called IBPy. It is not officially from IB, but I was able to code my project quickly because I was already fluent in python. – Donn Lee Aug 31 '14 at 19:35

1 Answers1

2

There are a number of problems with your code that make it an invalid Java program.

In Java, all methods must be contained within a class, unlike your onHowToDetermineStock method. Also, unlike R, Java doesn't use named parameters (i.e. port=7496 is not valid except to assign a variable named port). There are other problems.

Java is an object-oriented language and is very different from R. I would suggest forgetting the IB API for the time being, and spending some time learning how to code a basic Java application. There are many free tutorials on the web.

E.g.: https://docs.oracle.com/javase/tutorial/

hendalst
  • 2,957
  • 1
  • 24
  • 25