Beispiel #1
0
QuoteInterface_TDF::QuoteInterface_TDF(const SubscribeContracts* subscribe_contracts, const ConfigData& cfg)
    : cfg_(cfg), p_stock_md_save_(NULL), p_stock_idx_save_(NULL)
{
    if (subscribe_contracts)
    {
        subscribe_contracts_ = *subscribe_contracts;
    }

    InitErrorMap();

    sprintf(qtm_name_, "tdf_%s_%u", cfg.Logon_config().account.c_str(), getpid());
    QuoteUpdateState(qtm_name_, QtmState::INIT);

    // create save object
    p_stock_md_save_ = new QuoteDataSave<TDF_MARKET_DATA_MY>(cfg_, qtm_name_, "tdf_market_data", TDF_STOCK_QUOTE_TYPE);
    p_stock_idx_save_ = new QuoteDataSave<TDF_INDEX_DATA_MY>(cfg_, qtm_name_, "tdf_index_data", TDF_INDEX_QUOTE_TYPE);
    p_stock_oq_save_ = new QuoteDataSave<T_OrderQueue>(cfg_, qtm_name_, "order_queue_data", KMDS_ORDER_QUEUE_TYPE);
    p_stock_pe_save_ = new QuoteDataSave<T_PerEntrust>(cfg_, qtm_name_, "per_entrust_data", KMDS_PER_ENTRUST_TYPE);
    p_stock_pb_save_ = new QuoteDataSave<T_PerBargain>(cfg_, qtm_name_, "per_bargain_data", KMDS_PER_BARGAIN_TYPE);
    s_p_stock_md_save = p_stock_md_save_;
    s_p_stock_idx_save = p_stock_idx_save_;
    s_p_stock_oq_save = p_stock_oq_save_;
    s_p_stock_pe_save = p_stock_pe_save_;
    s_p_stock_pb_save = p_stock_pb_save_;

    // environment settings
    //TDF_SetEnv(TDF_ENVIRON_HEART_BEAT_INTERVAL, 10);
    //TDF_SetEnv(TDF_ENVIRON_MISSED_BEART_COUNT, 2);
    //TDF_SetEnv(TDF_ENVIRON_OPEN_TIME_OUT, 30);

    // quote connection settings
    open_settings = new TDF_OPEN_SETTING();
    InitOpenSetting(open_settings, cfg);

    TDF_ERR nErr = TDF_ERR_SUCCESS;
    g_hTDF = TDF_Open(open_settings, &nErr);

    // try till open success
    while (nErr == TDF_ERR_NETWORK_ERROR || g_hTDF == NULL)
    {
        MY_LOG_ERROR("TDF_Open returned: %s; try again.", GetErrStr(nErr));
        QuoteUpdateState(qtm_name_, QtmState::CONNECT_FAIL);
        sleep(3);

        g_hTDF = TDF_Open(open_settings, &nErr);
    }
    MY_LOG_INFO("TDF_Open success.");
    QuoteUpdateState(qtm_name_, QtmState::CONNECT_SUCCESS);
    QuoteUpdateState(qtm_name_, QtmState::API_READY);
}
Beispiel #2
0
PGPError
PGPSocketsInit()
{
	PGPError	err = kPGPError_NoErr;

#if PGP_WIN32
	WSADATA	wsaData;
	EnterCriticalSection(&gSocketsInitMutex);
#endif
	
	if (sNumberOfInits == 0) {

#if PGP_WIN32	
		InitializePGPRMWOLock(&sIdleEventHandlerLock);
#endif	
		InitializePGPRMWOLock(&sTLSMapLock);
		err = PGPNewMemoryMgr(0, &sMemoryMgr);
		if (err != kPGPError_NoErr) {
			goto done;
		}
		err = PGPNewBinaryTree(sMemoryMgr, &sErrorMap);
		if (err != kPGPError_NoErr) {
			goto done;
		}
		err = PGPNewBinaryTree(sMemoryMgr, &sTLSMap);
		if (err != kPGPError_NoErr) {
			goto done;
		}
	
#if PGP_WIN32	
		(void) PGPThreadKeyCreate(&sIdleEventHandlerIndex, NULL);
		if (PGPThreadSetSpecific(sIdleEventHandlerIndex, NULL)) {
			err = kPGPError_UnknownError;
			goto done;
		}
		(void) PGPThreadKeyCreate(&sIdleEventHandlerDataIndex, NULL);
		if (PGPThreadSetSpecific(sIdleEventHandlerDataIndex, NULL)) {
			err = kPGPError_UnknownError;
			goto done;
		}
#endif
	
	InitErrorMap();
	
#if PGP_WIN32	
	err = WSAStartup(MAKEWORD(1,1), &wsaData);
	if (err != 0) {
		err = MapPGPSocketsError(err);
		goto done;
	}
#endif
	
	}
	sNumberOfInits++;
	
 done:
#if PGP_WIN32
	LeaveCriticalSection(&gSocketsInitMutex);
#endif	
	return err;
}