开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

twsapi: How to make the Java API work?


Michel
 

开云体育

I dont know of Java, but something looks strange: you connect to "gw4.ibllc.com:4000" which is the IB server on the Internet.
Dont have you to connect to the local server (as in VB): "127.0.0.1:7496"?
?
Michel.

[Michel]??-----Mensaje original-----
De: philipyeh [mailto:philipyeh@...]
Enviado el: lunes, 01 de julio de 2002 4:53
Para: twsapi@...
Asunto: twsapi: How to make the Java API work?

I am a new user of the TWS Java API.
I wrote a test program to test the reqMktData() method.
But I can not get any ticks data. What's problem in my
program? Could anybody help me?
Below is my test java program:

import com.ib.client.*;

public class ATMClient implements EWrapper
{
??? static final int BID_SIZE?? = 0;
??? static final int BID??????? = 1;
??? static final int ASK??????? = 2;
??? static final int ASK_SIZE?? = 3;
??? static final int LAST?????? = 4;
??? static final int LAST_SIZE? = 5;
??? EClientSocket m_client = new EClientSocket(this);
??? int m_id = 100000;
??? int o_id = 200000;


????? public static void main (String[] args)
????? {
????? ????? ATMClient myapp = new ATMClient();
????? ????? myapp.start("gw4.ibllc.com", "4000");
????? }

????? public void start(String host, String port)
????? {
??????? m_client.eConnect(host, Integer.parseInt(port));
System.out.println("connect ok!");
??????? Contract m_contract = new Contract();
??????? m_contract.symbol = "ESU2";
??????? m_contract.secType = "FUT";
??????? m_contract.expiry = "200209";
??????? m_contract.strike = 0.0;
??????? m_contract.right = "C";
??????? m_contract.exchange = "GLOBEX";
??????? m_contract.currency = "USD";
??????? m_client.reqMktData(m_id, m_contract);
????? }


??? public void tickPrice( int tickerId, int field, double price) {
??????? // received price tick
??????? System.out.println("id=" + tickerId + "? " + getField(field)
+ "=" + price);
??? }

??? public void tickSize( int tickerId, int field, int size) {
??????? // received size tick
??????? System.out.println("id=" + tickerId + "? " + getField(field)
+ "=" + size);
??? }

??? public void orderStatus(int orderId, String status, int filled,
int remaining, double price, int permId) {
??????? // received order status
??????? System.out.println("id=" + orderId + "? status=" + status
+ "? filled=" + filled + "? remaining=" + remaining + "? price=" +
price + "? permId=" + permId);
???????
??????? // make sure id for next order is at least orderId+1
??????? ++o_id;
??? }

??? public void openOrder( int orderId, Contract contract, Order
order) {
??????? // received open order
??????? System.out.println( "id=" + orderId + "? " + order.action
+ "? " + order.quantity + "? " + contract.symbol);
??? }
???
??? public void nextValidId(int orderId) {
??????? // received next valid order id
??????? o_id = orderId;
??? }
???
??? public void error(String str) {
??????? // received error
??????? System.out.println("*** Error: " + str);
??? }

??? public void connectionClosed() {
??????? System.out.println("Connection Closed");
??? }
???
??? private String getField(int tickType) {
??????? switch (tickType) {
??????????? case BID_SIZE:????? return "bidSize";
??????????? case BID:????? return "bidPrice";
??????????? case ASK:????? return "askPrice";
??????????? case ASK_SIZE:????? return "askSize";
??????????? case LAST:????? return "lastPrice";
??????????? case LAST_SIZE:????? return "lastSize";
??????????? default:????? return "unknown";
??????? }
??? }
???
??? public void updateAccountValue(String key,String value,String
currency) {
??????? System.out.println("key=" + key + ", value=" + value + ",
currency=" + currency);
??? }
???
??? public void updatePortfolio(Contract contract, int position,
double marketPrice, double marketValue) {
??????? System.out.println("position=" + position + ", marketPrice="
+ marketPrice + ", marketValue=" + marketValue);
??? }
???
??? public void updateAccountTime(String timeStamp) {
??????? System.out.println("timeStamp=" + timeStamp);
??? }???

}

Thanks.
Philip Yeh.




To unsubscribe from this group, send an email to:
twsapi-unsubscribe@...



Your use of Yahoo! Groups is subject to the .