コード例 #1
0
ファイル: twsdo.cpp プロジェクト: adamnemecek/twstools
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
ファイル: twsgen.cpp プロジェクト: AlexPetit12/twstools
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;
}
コード例 #3
0
ファイル: tws_meta.cpp プロジェクト: adamnemecek/twstools
int WorkTodo::read_req( const xmlNodePtr xn )
{
	int ret = 1;
	char* tmp = (char*) xmlGetProp( xn, (const xmlChar*) "type" );
	
	if( tmp == NULL ) {
		fprintf(stderr, "Warning, no request type specified.\n");
		ret = 0;
	} else if( strcmp( tmp, "contract_details") == 0 ) {
		PacketContractDetails *pcd = PacketContractDetails::fromXml(xn);
		_contractDetailsTodo->add(pcd->getRequest());
		delete pcd;
	} else if ( strcmp( tmp, "historical_data") == 0 ) {
		PacketHistData *phd = PacketHistData::fromXml(xn);
		_histTodo->add( phd->getRequest() );
		delete phd;
	} else if ( strcmp( tmp, "place_order") == 0 ) {
		PacketPlaceOrder *ppo = PacketPlaceOrder::fromXml(xn);
		_place_order_todo->add( ppo->getRequest() );
		delete ppo;
	} else if ( strcmp( tmp, "market_data") == 0 ) {
		PacketMktData *pmd = PacketMktData::fromXml(xn);
		_market_data_todo->add( pmd->getRequest() );
		delete pmd;
		// HACK always get contractDetails too
		PacketContractDetails *pcd = PacketContractDetails::fromXml(xn);
		_contractDetailsTodo->add(pcd->getRequest());
		delete pcd;
	} else if ( strcmp( tmp, "account") == 0 ) {
		addSimpleRequest(GenericRequest::ACC_STATUS_REQUEST);
	} else if ( strcmp( tmp, "executions") == 0 ) {
		addSimpleRequest(GenericRequest::EXECUTIONS_REQUEST);
	} else if ( strcmp( tmp, "open_orders") == 0 ) {
		addSimpleRequest(GenericRequest::ORDERS_REQUEST);
	} else {
		fprintf(stderr, "Warning, unknown request type '%s' ignored.\n", tmp );
		ret = 0;
	}
	
	free(tmp);
	return ret;
}