Пример #1
0
  @Override
  public void OnFrontConnected() {

    CThostFtdcReqUserLoginField pReqUserLoginField = new CThostFtdcReqUserLoginField();
    pReqUserLoginField.setBrokerID(MyAPI.brokerId);
    pReqUserLoginField.setUserID(userId);
    pReqUserLoginField.setPassword(password);
    nRequestId++;
    mdApi.ReqUserLogin(pReqUserLoginField, nRequestId);

    // 构建Message对象
    // 第一个参数:是自己指定的message代号,方便在handler选择性地接收
    // 第二三个参数没有什么意义
    // 第四个参数需要封装的对象
  }
Пример #2
0
  @Override
  public void OnRspUserLogin(
      CThostFtdcRspUserLoginField pRspUserLogin,
      CThostFtdcRspInfoField pRspInfo,
      int nRequestID,
      boolean bIsLast) {
    // 行情登录成功后,就开始请求订阅行情
    //        ArrayList<String> instrumentArray = myhandler.instrumentArray;
    //        int nCount = instrumentArray.size();
    //        String[] ppInstrumentID = new String[nCount];
    //        Iterator iter = instrumentArray.iterator();
    //        int index = 0;
    //        while (iter.hasNext()) {
    //            ppInstrumentID[index] = iter.next().toString();
    //            index++;
    //        }
    //
    //        mdApi.SubscribeMarketData(ppInstrumentID, nCount);

    //        HashMap<String,Integer> instrumentArray = myhandler.getInstrumentIndex();
    //        int nCount = instrumentArray.size();
    //        String[] ppInstrumentID = new String[nCount];
    //        Iterator iter = instrumentArray.entrySet().iterator();
    //        int index = 0;
    //        while (iter.hasNext()) {
    //            Map.Entry entry = (Map.Entry) iter.next();
    //            ppInstrumentID[index] = entry.getKey().toString();
    //            index++;
    //        }
    //
    //        mdApi.SubscribeMarketData(ppInstrumentID, nCount);

    // 把每一个合约单独请求
    HashMap<String, Integer> instrumentMap = myhandler.getInstrumentMap();
    String[] ppInstrumentID = new String[1];
    Iterator iter = instrumentMap.entrySet().iterator();
    while (iter.hasNext()) {
      Map.Entry entry = (Map.Entry) iter.next();
      ppInstrumentID[0] = entry.getKey().toString();
      mdApi.SubscribeMarketData(ppInstrumentID, 1);
    }
  }