Exemple #1
0
  protected void connect() {
    client.eConnect(ip_add, return_port, return_clientId);

    try {
      while (!client.isConnected()) ;
      q.offer(
          "Connected to TWS server version "
              + client.serverVersion()
              + " at "
              + client.TwsConnectionTime());
    } catch (Exception e) {
      q.offer("EXCEPTION while connecting: " + e.getMessage());
    }
  }
Exemple #2
0
  public DataSet request_histData(Company company, int long_short_volatility) {

    Contract contract = company.create_contract();

    Vector<TagValue> mkt_data_options = new Vector<TagValue>();

    sem_oid.acquireUninterruptibly();
    OpenRequest or = new OpenRequest(company, long_short_volatility);
    open_request_map.put(next_orderId, or);

    this.date = Calendar.getInstance().getTime();
    if (long_short_volatility == 0)
      client.reqHistoricalData(
          next_orderId,
          contract,
          df_ib.format(this.date),
          "1800 S",
          "30 mins",
          "TRADES",
          1,
          1,
          mkt_data_options);
    else if (long_short_volatility == 1)
      client.reqHistoricalData(
          next_orderId,
          contract,
          df_ib.format(this.date),
          parent.data_period,
          parent.data_granularity,
          "TRADES",
          1,
          1,
          mkt_data_options);
    else
      client.reqHistoricalData(
          next_orderId,
          contract,
          df_ib.format(calendar.getTime()),
          "1 D",
          "1 hour",
          "TRADES",
          1,
          1,
          mkt_data_options);

    next_orderId++;
    sem_oid.release();
    return null;
  }
Exemple #3
0
  public void place_order(Company company, int quantity, String buy_sell, byte user_system) {
    Contract contract = company.create_contract();
    Order order = company.create_order(buy_sell, quantity);

    sem_oid.acquireUninterruptibly();

    OpenOrder oo = new OpenOrder(order, company, user_system);
    open_order_map.put(next_orderId, oo);
    client.placeOrder(next_orderId, contract, order);

    String message =
        df_user.format(Calendar.getInstance().getTime())
            + buy_sell
            + " ORDER placed: "
            + company.name()
            + "x"
            + quantity;

    message = (user_system == 0) ? message + " BY USER" : message;

    next_orderId++;
    sem_oid.release();

    q.offer(message);
  }
Exemple #4
0
  protected void cancel_mktData(Company company) {

    int oid = 0;
    client.cancelMktData(oid);
    // req_id_mapping.remove(company);

    System.out.println("MktDataCanceled for oid " + oid);
  }
Exemple #5
0
  protected void request_mktData(Company company) {
    Contract contract = company.create_contract();

    Vector<TagValue> mkt_data_options = new Vector<TagValue>();

    sem_oid.acquireUninterruptibly();

    OpenRequest or = new OpenRequest(company, -1);
    open_request_map.put(next_orderId, or);
    client.reqMktData(next_orderId, contract, null, true, mkt_data_options);
    next_orderId++;

    sem_oid.release();
  }
Exemple #6
0
 protected boolean check_connection() {
   return client.isConnected();
 }
Exemple #7
0
 protected void startConnection() {
   if (!connected) {
     connected = true;
     clientSocket.eConnect(connection.getHost(), connection.getPort(), connection.getClientId());
   }
 }
Exemple #8
0
 public void disconnect() {
   if (clientSocket.isConnected()) {
     clientSocket.eDisconnect();
     connected = false;
   }
 }