JNIEXPORT void JNICALL Java_nativeinterfaces_DefaultNativeInterface_sendQuoteRequest (JNIEnv *, jobject, jobjectArray){ // create a CThostFtdcMdApi instance CThostFtdcMdApi *pUserApi = CThostFtdcMdApi::CreateFtdcMdApi(); CThostFtdcTraderApi *pTraderApi = CThostFtdcTraderApi::CreateFtdcTraderApi(); // create an event handler instance quotationeventhandler sh(pUserApi); TraderEventHandler th(pTraderApi); // register an event handler instance pTraderApi->RegisterSpi(&th); // register the CTP front address and port //pTraderApi ->RegisterFront("tcp://218.1.96.8:41205"); pTraderApi->SubscribePrivateTopic(THOST_TERT_RESUME); pTraderApi->SubscribePublicTopic(THOST_TERT_RESUME); // start the connection between client and CTP server //pTraderApi->Init(); // waiting for the quotation data //WaitForSingleObject(g_hEvent, INFINITE); // release API instance //pTraderApi -> Release(); pUserApi->RegisterSpi(&sh); pUserApi->RegisterFront("tcp://218.1.96.8:41213"); pUserApi->Init(); WaitForSingleObject(g_hEvent, INFINITE); pUserApi->Release(); }
int main(int argc, char* argv[]) { // 创建实例 CThostFtdcMdApi* pUserApi = CThostFtdcMdApi::CreateFtdcMdApi(""); // 创建spi实例 CMdUserApiSample* pSpi = new CMdUserApiSample(pUserApi, "", "80002", "123456"); // 注册spi实例 pUserApi->RegisterSpi(pSpi); // 注册前置机 pUserApi->RegisterFront("tcp://10.253.117.107:13163"); //pUserApi->RegisterFront("udp://10.253.117.107:20518"); //CThostFtdcFensUserInfoField FensUserInfo = {0}; //strncpy(FensUserInfo.UserID, "201301", sizeof(FensUserInfo.UserID)-1); //FensUserInfo.LoginMode = 'E'; //pUserApi->RegisterFensUserInfo(&FensUserInfo); // 初始化 pUserApi->Init(); // 等待信号 //WaitForSingleObject(g_hEvent, INFINITE); printf ("\npress return to quit...\n"); getchar(); // 初始化 pUserApi->Release(); return 0; }
int main(int argc, char *argv[]) { signal(SIGABRT, &sighandler); signal(SIGTERM, &sighandler); signal(SIGINT, &sighandler); ILog4zManager::GetInstance()->Start(); LOGI("MD Application Start..."); LOGI("Read params from config file"); Config cfg("trader.config",0); g_strFlowPath = cfg.pString("MD_FLOW_PATH"); g_strBrokerID = cfg.pString("BROKER_ID"); g_strUserID = cfg.pString("USER_ID"); g_strPassword = cfg.pString("PASSWORD"); g_strLogPath = cfg.pString("LOG_PATH"); g_strFrontURL = cfg.pString("MD_URL"); // create a CThostFtdcMdApi instance CThostFtdcMdApi *pUserApi = CThostFtdcMdApi::CreateFtdcMdApi(g_strFlowPath.c_str()); // create an event handler instance CSimpleHandler sh(pUserApi); try{ LOGI("register an event handler instance"); pUserApi->RegisterSpi(&sh); LOGI("register the CTP front address and port"); char ch_URL[100]; strcpy(ch_URL, g_strFrontURL.c_str()); pUserApi->RegisterFront(ch_URL); LOGFMTI("start to connect CTP server : %s", ch_URL); pUserApi->Init(); LOGI("waiting for the quotation data"); pthread_cond_wait(&cond, &mutex); LOGI("release API & SPI instance"); } catch(exception& e) { LOGE("exception caught:"<< e.what()); } if (pUserApi){ pUserApi->RegisterSpi(NULL); pUserApi->Release(); pUserApi = NULL; } if (&sh) { // delete &sh; sh = NULL; } LOGI("MD Application quit!"); return 0; }
void reciveData(){ cout << "(线程用来订阅合约号接受数据)reciveData!!!!!!!: "<< endl; CThostFtdcMdApi* pUserApiMd = CThostFtdcMdApi::CreateFtdcMdApi("./outfile/",true); MyCTPMdSpi sh(pUserApiMd); pUserApiMd->RegisterSpi(&sh); pUserApiMd->RegisterFront(front_ip_md); pUserApiMd->Init(); sleep(2); sh.ReqUserLogin(broker_id,user_id,p_w); sleep(20); sh.dataRecive(); sleep(10); pUserApiMd->Join(); }