Пример #1
0
bool TwsDL::finContracts()
{
	PacketContractDetails* p = (PacketContractDetails*)packet;
	switch( packet->getError() ) {
	case REQ_ERR_NONE:
		DEBUG_PRINTF( "Contracts received: %zu",
		p->constList().size() );
		packet->dumpXml();
	case REQ_ERR_NODATA:
	case REQ_ERR_NAV:
	case REQ_ERR_REQUEST:
		break;
	case REQ_ERR_TWSCON:
	case REQ_ERR_TIMEOUT:
		return false;
	}

	if( strat != NULL ) {
		// HACK we want exactly one ContractDetails for each mkt data contract
		assert( p->constList().size() == 1 );
		const IB::ContractDetails &cd = p->constList().at(0);
		con_details[cd.summary.conId] =  new IB::ContractDetails(cd);

		// HACK add conId to mkt data contracts
		int mi = con_details.size() - 1;
		const MktDataTodo &mtodo = workTodo->getMktDataTodo();
		IB::Contract &contract = mtodo.mktDataRequests[mi].ibContract;
		assert( contract.conId == 0 || contract.conId == cd.summary.conId );
		contract.conId = cd.summary.conId;
	}

	return true;
}
Пример #2
0
bool gen_hist_job()
{
	TwsXml file;
	if( ! file.openFile(filep) ) {
		return false;
	}

	time_t t_begin = min_begin_date( endDateTimep, durationStrp );
	DEBUG_PRINTF("skipping expiries before: '%s'",
		time_t_local(t_begin).c_str() );

	xmlNodePtr xn;
	int count_docs = 0;
	/* NOTE We are dumping single HistRequests but we should build and dump
	   a HistTodo object */
	while( (xn = file.nextXmlNode()) != NULL ) {
		count_docs++;
		PacketContractDetails *pcd = PacketContractDetails::fromXml( xn );

		int myProp_reqMaxContractsPerSpec = -1;
		for( size_t i = 0; i < pcd->constList().size(); i++ ) {

			const IB::ContractDetails &cd = pcd->constList()[i];
			IB::Contract c = cd.summary;
// 			DEBUG_PRINTF("contract, %s %s", c.symbol.c_str(), c.expiry.c_str());

			if( exp_mode != EXP_KEEP ) {
				c.includeExpired = get_inc_exp(c.secType.c_str());
			}
			if( myProp_reqMaxContractsPerSpec > 0 && (size_t)myProp_reqMaxContractsPerSpec <= i ) {
				break;
			}

			if( skip_expiry(c.expiry, t_begin) ) {
// 				DEBUG_PRINTF("skipping expiry: '%s'", c.expiry.c_str());
				continue;
			}

			for( char **wts = wts_list; *wts != NULL; wts++ ) {
				HistRequest hR;
				hR.initialize( c, endDateTimep, durationStrp, barSizeSettingp,
				               *wts, useRTHp, formatDate() );

				PacketHistData phd;
				phd.record( 0, hR );
				phd.dumpXml();
			}
		}
		delete pcd;
	}
	fprintf( stderr, "notice, %d xml docs parsed from file '%s'\n",
		count_docs, filep );

	return true;
}