• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overloading question

 
Ron Hinchley
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, this is probably very basic but I am new to Java.

I am working with a broker API and they have split the request and response. The response comes in a module which I overload. Then I put code into this module. The problem is I need to pass the symbol name to this code to put the data into my SQL database.


How do I pass something to historicalData?



/*
* IbIntra.java
*
* Created on April 1, 2008, 10:20 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package database_connect;

/**
*
* @author Owner
*
* This is called with a stock argument
* It fetched specified minute data bars
*/

import com.ib.client.*;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.Date;
import java.sql.SQLException;
import java.io.*;
import java.util.*;
import java.lang.String.*;
import java.net.*;
import java.text.*;


public class IbIntra implements EWrapper{

EClientSocket m_client = new EClientSocket(this);


/** Creates a new instance of IbIntra */
public IbIntra(
String tws_host,
String tws_port,
String tws_user,
String StockSymbolDa[],
int StockSymbolDaCnt,
String tws_unit, //unit <min>
String tws_qty, //sample every <1> units
String tws_del_after, // months old 48
Connection con) throws SQLException {


String host;
if(tws_host.equals(null))
host = "";
else
host = tws_host;

int port = new Integer(tws_port).intValue();
int pid = new Integer(tws_user).intValue();

System.out.printf("%h", pid);

if(m_client.isConnected() == false) { // not already connected then connect
//m_client.eDisconnect();
//System.out.printf("\nWarning: %d is already connected to tws on port %d of host %s\n", tws_user, tws_port, tws_host);
//} else {
m_client.eConnect(host,port, pid);
System.out.println(" Trying to connect...");
if (m_client.isConnected()) {
System.out.println("Connected to Tws server version " +
m_client.serverVersion() + " at " +
m_client.TwsConnectionTime());
}
}



try {

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




//int orderId = nextValidId.orderId;


contract.m_secType = "STK";
contract.m_expiry = "";
contract.m_right = "";
contract.m_multiplier = "";
contract.m_exchange = "SMART";
contract.m_primaryExch = "";
contract.m_currency = "USD";
contract.m_localSymbol = "";

for(int orderId = 0; orderId < StockSymbolDaCnt; orderId++) { // for each symbol
contract.m_symbol = StockSymbolDa[orderId];
System.out.println(StockSymbolDa+", "+ tws_unit+ ", "+ tws_qty+", "+tws_del_after );

//m_client.reqHistoricalData(orderId,contract, "20071115 09:30:00 GMT-05:00", "25166 S", "60 mins", "TRADES", 1, 2);
//m_client.reqHistoricalData(orderId,contract, "20071115 10:30:00 GMT-05:00", "3600 S", "1 min", "TRADES", 1, 2);


m_client.reqHistoricalData(orderId,contract, "20071115 09:31:00 GMT-05:00", "60 S", "1 min", "TRADES", 1, 2);
//System.out.printf("%s",StockSymbolDa);
}





}
// lower level error catches maybe...
catch (Throwable t) {
t.printStackTrace(); // at least
}
// optional finally


}

public void historicalData(int reqId, String date, double open, double high, double low,
double close, int volume, int other, double WAP, boolean hasGaps){

int cnt = 0;
if(date.matches(".*\\bfinished\\b.*")) {
System.out.println("all done");
//System.exit(1);
} else {
long ldate = Long.parseLong(date.trim());
Date cdate = new Date(ldate*1000);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
FieldPosition pos = new FieldPosition(0);
StringBuffer empty = new StringBuffer();
StringBuffer datec = sdf.format(cdate, empty, pos);
String mysqlDateTime = datec.toString();



System.out.println(mysqlDateTime);




//System.out.println(msqlDformat.parse(cdate));
System.out.println("reqId="+reqId+","+date+","+open+","+high+","+low+","+close+","+volume+","+other+","+WAP+","+hasGaps+"\r\n");

}
}


public void error(int id, int errorCode, String errorMsg) {
//System.out.println("Error: "+errorMsg);
System.out.printf("Error: %d, ID %d, Message %s\n", errorCode, id, errorMsg);
}


public void tickPrice( int tickerId, int field, double price, int canAutoExecute) {}
public void openOrder( int orderId, Contract contract, Order order, OrderState orderState) {}
public void scannerDataEnd(int reqId){}
public synchronized void reqMktData(int tickerId, Contract contract, String genericTickList, boolean snapshot) {}
public void tickSize(int tickerId, int field, int size) {}
public void orderStatus( int orderId, String status, int filled, int remaining,
double avgFillPrice, int permId, int parentId, double lastFillPrice, int clientId){}
public void openOrder(int orderId, Contract contract, Order order) {}
public void error(String str) {}
public void connectionClosed() {}
public void updateAccountValue(String key, String value, String currency, String accountName){}
public void updatePortfolio(Contract contract, int position, double marketPrice, double marketValue) {}
public void updateAccountTime(String timeStamp) {}
public void nextValidId(int orderId) {}
public void contractDetails(ContractDetails contractDetails) {}
public void execDetails(int orderId, Contract contract, Execution execution) {}
public void updateMktDepth(int tickerId, int position, int operation, int side, double price, int size) {}
public void updateMktDepthL2(int tickerId, int position, String marketMaker, int operation, int side, double price, int size) {}
public void updateNewsBulletin( int msgId, int msgType, String message, String origExchange){}
public void managedAccounts( String accountsList){}
public void receiveFA(int faDataType, String xml){}
public void intradayData(int reqId, String date, double open, double high, double low, double close, int volume, double WAP, boolean hasGaps){}
public void updatePortfolio(Contract contract, int position, double marketPrice, double marketValue, double averageCost, double unrealizedPNL, double realizedPNL, String accountName){}
public void tickGeneric(int tickerId, int tickType, double value) {}
public void scannerParameters(String xml) {}
public void error(Exception e) {}
public void tickOptionComputation( int tickerId, int field, double impliedVol,
double delta, double modelPrice, double pvDividend) {}
public void tickEFP(int tickerId, int tickType, double basisPoints,
String formattedBasisPoints, double impliedFuture, int holdDays,
String futureExpiry, double dividendImpact, double dividendsToExpiry) {}
public void tickString(int tickerId, int tickType, String value) {}
public void bondContractDetails(ContractDetails contractDetails) {}
public void scannerData(int reqId, int rank, ContractDetails contractDetails, String distance,
String benchmark, String projection, String legsStr) {}
public void realtimeBar(int reqId, long time, double open, double high, double low, double close, long volume, double wap, int count){ }
public void orderStatus(int orderId, String status, int filled, int remaining, double avgFillPrice, int permId, int parentId, double lastFillPrice, int clientId, String whyHeld){}
public void currentTime(long time){}
public EReader createReader(EClientSocket socket, DataInputStream dis) {
return new EReader(socket, dis);
}




}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic