Package com.ib.client

Examples of com.ib.client.Contract


        return isSuccess;
    }

    private Contract filterContracts(String right) {
        Contract c = null;

        // First by price
        double priceDiff = 0.0;
       
        for (Contract contract : optionContracts) {
View Full Code Here


            // Make connection
            connectToTWS();

            // Create a contract, with defaults...
            Contract contract = createContract(symbol, "STK", "SMART", "USD");

            // Requests snapshot market data
            eClientSocket.reqMktData(requestId++, contract, null, true);

            while (!isSuccess && waitCount < MAX_WAIT_COUNT) {
View Full Code Here

    protected Contract createContract(String symbol, String securityType, String exchange, String currency) {
        return createContract(symbol, securityType, exchange, currency, null, null, 0.0);
    }

    protected Contract createContract(String symbol, String securityType, String exchange, String currency, String expiry, String right, double strike) {
        Contract contract = new Contract();

        contract.m_symbol = symbol;
        contract.m_secType = securityType;
        contract.m_exchange = exchange;
        contract.m_currency = currency;
View Full Code Here

  private final Contract iBContract;
  private ContractDetails details;
  private final IBConstantTranslator constantTranslator;
 
  public IBContract(IBConstantTranslator constantTranslator) {
    this(new Contract(), constantTranslator);
  }
View Full Code Here

    return trades;
  }

  @Override
  public List<IContract> searchContracts(IContract criteria, ITaskMonitor taskMonitor) throws ConnectException, RequestFailedException {
    final Contract iBCriteria = IBContract.toIBContract(criteria, constantTranslator);
    final List<IContract> result = new ArrayList<IContract>();
   
    if (taskMonitor != null) {
      taskMonitor.beginTask(1);
    }
View Full Code Here

    return result;
  }

  private List<IOHLCPoint> doGetHistoricalData(IContract contract, final Date endDateTime, final TimePeriod period,
      final BarSize barSize, DataType dataType, final boolean includeAfterHours) throws ConnectException, RequestFailedException {
    final Contract iBContract = IBContract.toIBContract(contract, constantTranslator);
    final String iBDurationUnit = constantTranslator.getCode(period.getUnitOfTime());
    final String iBBarSize = constantTranslator.getCode(barSize);
    final String iBDataType = dataType == DataType.BID_ASK ? "MIDPOINT" : constantTranslator.getCode(dataType); // BID_ASK does not return OHLC bars: open = WAVG(BID), close = WAVG(ASK)
    final List<IOHLCPoint> result = new ArrayList<IOHLCPoint>();
    final SimpleDateFormat timestampDateFormat = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
View Full Code Here

  @Override
  public void startRealTimeBars(IContract contract, final BarSize barSize, DataType dataType, final boolean includeAfterHours, IRealTimeDataListener listener)
      throws ConnectException, RequestFailedException {
   
    final int barSizeConst = 5;
    final Contract iBContract = IBContract.toIBContract(contract, constantTranslator);
    final String iBDataType = dataType == DataType.BID_ASK ? "MIDPOINT" : constantTranslator.getCode(dataType); // BID_ASK does not return OHLC bars: open = WAVG(BID), close = WAVG(ASK)
   
    final String realTimeSeriesRequestCode = buildRealTimeSeriesRequestCode(contract, barSize, dataType, includeAfterHours);
   
    Set<IRealTimeDataListener> setOfListeners = realTimeDataListeners.get(realTimeSeriesRequestCode);
View Full Code Here

    return buffer.toString();
  }

  @Override
  public void startTicks(IContract contract, ITickListener listener) throws ConnectException, RequestFailedException {
    final Contract iBContract = IBContract.toIBContract(contract, constantTranslator);
   
    final String tickRequestCode = buildTickRequestCode(contract);
   
    Set<ITickListener> setOfListeners = tickListeners.get(tickRequestCode);
   
View Full Code Here

  }

  @Override
  public String sendOrder(IOrder order) throws ConnectException, RequestFailedException {
    Order iBOrder = IBOrder.toIBOrder(order, constantTranslator);
    Contract iBContract = IBContract.toIBContract(order.getContract(), constantTranslator);
    int id = sendOrder(iBOrder, iBContract);
    iBOrder.m_orderId = id;
    sentOrders.put(id, new IBOrder(order.getContract(), iBOrder, constantTranslator));
    logger.log(Level.INFO, "Sent order: " + id);
    return Integer.toString(id);
View Full Code Here

  }
 
  @Override
  public String[] sendBracketOrders(IOrder parent, IOrder[] children) throws ConnectException, RequestFailedException {
    Order iBParentOrder = IBOrder.toIBOrder(parent, constantTranslator);
    Contract iBParentContract = IBContract.toIBContract(parent.getContract(), constantTranslator);
   
    int parentId = sendOrder(iBParentOrder, iBParentContract);
   
    String[] ids = new String[1 + children.length];
    ids[0] = Integer.toString(parentId);
   
    for (int i = 0; i < children.length; i++) {
      Order iBChildOrder = IBOrder.toIBOrder(children[i], constantTranslator);
      iBChildOrder.m_parentId = parentId;
      Contract iBChildContract = IBContract.toIBContract(children[i].getContract(), constantTranslator);
      int childId = sendOrder(iBChildOrder, iBChildContract);
      ids[i + 1] = Integer.toString(childId);
    }
    return ids;
  }
View Full Code Here

TOP

Related Classes of com.ib.client.Contract

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.