Example #1
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);
  }
Example #2
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();
  }
Example #3
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;
  }