Exemple #1
0
void TwsDlWrapper::accountSummary( int reqId, const IBString& account,
	const IBString& tag, const IBString& value,
	const IBString& currency )
{
	DEBUG_PRINTF( "ACCOUNT_SUMMARY: %d %s %s %s %s", reqId, account.c_str(),
		tag.c_str(), value.c_str(), currency.c_str() );
}
void PosixTestClient::reqHistoricalData(const IBString mc) 
{
  printf("Requesting Historical Data for symbol %s...\n", mc.c_str());
  time_t curtime = time(0);
  struct tm * timeinfo = localtime(&curtime);
  char tbuf[80];
  strftime(tbuf, 80, "%Y%m%d", timeinfo);
  IBString endDateTime = tbuf; 
  endDateTime += " 00:00:00";
  IBString subs = endDateTime.substr(0,6);
  const TickerId id = m_orderId;
  Contract contract;
	contract.symbol = mc; 
	contract.secType = "FUT";
	contract.exchange = "ECBOT";
	contract.currency = "USD";
  contract.expiry = "201407";
  const IBString durationStr = "1 W";
  const IBString barSizeSetting = "1 day";
  const IBString whatToShow = "TRADES";
  const int useRTH = 0;
  const int formatDate = 1;

  m_state = ST_REQ_HIST_DATA_PROC;

  m_pClient->reqHistoricalData(id, contract, endDateTime, durationStr, barSizeSetting, whatToShow, useRTH, formatDate);
}
void IBClient::updateAccountValue(const IBString &key, const IBString &val, const IBString &currency, const IBString &accountName)
{
    receiveData("updateAccountValue", knk(4,
                                          kp((S)key.c_str()),
                                          kp((S)val.c_str()),
                                          ks((S)currency.c_str()),
                                          ks((S)accountName.c_str()) ));
}
void IBClient::accountSummary(int reqId, const IBString &account, const IBString &tag, const IBString &value, const IBString &curency)
{
    receiveData("accountSummary", knk(5,
                                      ki(reqId),
                                      ks((S)account.c_str()),
                                      ks((S)tag.c_str()),
                                      kp((S)value.c_str()),
                                      ks((S)curency.c_str())));
}
Exemple #5
0
void TwsDlWrapper::updateAccountValue( const IBString& key,
	const IBString& val, const IBString& currency,
	const IBString& accountName )
{
#if 0
	DEBUG_PRINTF( "ACCT_VALUE: %s %s %s %s",
		key.c_str(), val.c_str(), currency.c_str(), accountName.c_str() );
#endif
	RowAccVal row = { key, val, currency, accountName };
	parentTwsDL->twsUpdateAccountValue( row );
}
void PosixTestClient::historicalData(TickerId reqId, const IBString& date, double open, double high,
									  double low, double close, int volume, int barCount, double WAP, int hasGaps) {
  printf("%ld\t%s\t%f\t%f \n", reqId, date.c_str(), open, close);
  if(date.find("finished-") == 0) {  // check for end of dataset market
    m_state = ST_REQ_HIST_DATA_ACK;
    return;
  }
  vf_t feats;
  feats.push_back(open);
  feats.push_back(high);
  feats.push_back(low);
  feats.push_back(close);
  feats.push_back(volume);
  m_histData.push_back(feats);
}
Exemple #7
0
void TwsDlWrapper::orderStatus ( OrderId orderId,
	const IBString &status, double filled, double remaining, double avgFillPrice,
	int permId, int parentId, double lastFillPrice, int clientId,
	const IBString& whyHeld, double mktCapPrice)
{
#if 1
	DEBUG_PRINTF( "ORDER_STATUS: "
		"orderId:%ld, status:%s, filled:%g, remaining:%g, %d %d %g %g %d, %s",
		orderId, status.c_str(), filled, remaining, permId, parentId,
		avgFillPrice, lastFillPrice, clientId, whyHeld.c_str());
#endif
	RowOrderStatus row = { orderId, status, filled, remaining,
		avgFillPrice, permId, parentId, lastFillPrice, clientId, whyHeld };
	parentTwsDL->twsOrderStatus(row);
}
void IBClient::tickEFP(TickerId tickerId, TickType tickType, double basisPoints, const IBString &formattedBasisPoints, double totalDividends, int holdDays, const IBString &futureExpiry, double dividendImpact, double dividendsToExpiry)
{
    auto dict = createDictionary(std::map<std::string, K> {
        { "tickerId",               kj(tickerId) },
        { "tickType",               ki(tickType) },
        { "basisPoints",            kf(basisPoints) },
        { "formattedBasisPoints",   kp((S)formattedBasisPoints.c_str()) },
        { "totalDividends",         kf(totalDividends) },
        { "holdDays",               ki(holdDays) },
        { "futureExpiry",           kp((S)futureExpiry.c_str()) },
        { "dividendImpact",         kf(dividendImpact) },
        { "dividendsToExpiry",      kf(dividendsToExpiry) }
    });
    receiveData("tickEFP", dict);
}
void IBApiCallback::error(const int id, const int errorCode, const IBString errorString) 
{
    echo("error: %d - %s\n", 
           errorCode,
           errorString.c_str());
    //OutputDebugStringA(errorString.c_str());
}
Exemple #10
0
void PosixTestClient::error(const int id, const int errorCode, const IBString errorString)
{
	printf( "Error id=%d, errorCode=%d, msg=%s\n", id, errorCode, errorString.c_str());

	if( id == -1 && errorCode == 1100) // if "Connectivity between IB and TWS has been lost"
		disconnect();
}
void IBClient::orderStatus(OrderId orderId, const IBString &status, int filled, int remaining, double avgFillPrice, int permId, int parentId, double lastFillPrice, int clientId, const IBString &whyHeld)
{
    auto dict = createDictionary(std::map<std::string, K> {
        { "id",                 ki(orderId) },
        { "status",             kp((S)status.c_str()) },
        { "filled",             ki(filled) },
        { "remaining",          ki(remaining) },
        { "avgFillPrice",       kf(avgFillPrice) },
        { "permId",             ki(permId) },
        { "parentId",           ki(parentId) },
        { "lastFilledPrice",    kf(lastFillPrice) },
        { "clientId",           ki(clientId) },
        { "whyHeld",            kp((S)whyHeld.c_str()) }
    });
    receiveData("orderStatus", dict);
}
Exemple #12
0
///////////////////////////////////////////////////////////////////
// events
void PosixTestClient::orderStatus( OrderId orderId, const IBString &status, int filled,
	   int remaining, double avgFillPrice, int permId, int parentId,
	   double lastFillPrice, int clientId, const IBString& whyHeld)

{
	//if( orderId == m_orderId) {
		//if( m_state == ST_PLACEORDER_ACK && (status == "PreSubmitted" || status == "Submitted"))
			//m_state = ST_CANCELORDER;

		//if( m_state == ST_CANCELORDER_ACK && status == "Cancelled")
		//	m_state = ST_PING;
	//}

	printf( "Order: id=%ld, status=%s\n", orderId, status.c_str());

	if ( (orderId == m_orderId) || (orderId == m_orderId+1) || (orderId == m_orderId+2) ) {
		if (status == "Filled") {
			m_marketData->setOrderReceived(orderId);
		}
	
		if (m_marketData->allOrdersExecuted()) {
			printf( "All orders placed\n" );
			m_state = ST_IDLE;
		}
	}
	
}
Exemple #13
0
void TwsDlWrapper::accountDownloadEnd( const IBString& accountName )
{
#if 1
	DEBUG_PRINTF( "ACCT_DOWNLOAD_END: %s", accountName.c_str() );
#endif
	parentTwsDL->twsAccountDownloadEnd( accountName );
}
Exemple #14
0
void TwsDlWrapper::updateAccountTime( const IBString& timeStamp )
{
#if 0
	DEBUG_PRINTF( "ACCT_UPDATE_TIME: %s", timeStamp.c_str() );
#endif
	parentTwsDL->twsUpdateAccountTime( timeStamp );
}
void IBClient::position(const IBString &account, const Contract &contract, int position, double avgCost)
{
    receiveData("position", knk(4,
                                ks((S)account.c_str()),
                                kj(contract.conId),
                                ki(position),
                                kf(avgCost)));
}
Exemple #16
0
void TwsDlWrapper::error(int id, int errorCode, const IBString& errorString)
{
#if 0
	DEBUG_PRINTF( "ERR_MSG: %d %d %s", id, errorCode, errorString.c_str() );
#endif
	RowError row = { id, errorCode, errorString };
	parentTwsDL->twsError( row );
}
void IBClient::updateMktDepthL2(TickerId id, int position, IBString marketMaker, int operation, int side, double price, int size)
{
    receiveData("updateMktDepthL2", knk(7,
                                        kj(id),
                                        ki(position),
                                        ks((S)marketMaker.c_str()),
                                        ki(operation),
                                        ki(side),
                                        kf(price),
                                        ki(size)));
}
Exemple #18
0
void TwsDlWrapper::tickString( TickerId tickerId, TickType tickType,
	const IBString& value )
{
#if 0
	if( tickType == LAST_TIMESTAMP ) {
		// here we format unix timestamp value
	}
	DEBUG_PRINTF( "TICK_STRING: %ld %s %s",
		tickerId, ibToString(tickType).c_str(), value.c_str() );
#endif
	parentTwsDL->twsTickString( tickerId, tickType, value);
}
void IBClient::updatePortfolio(const Contract &contract, int position, double marketPrice, double marketValue, double averageCost, double unrealizedPNL, double realizedPNL, const IBString &accountName)
{
    auto dict = createDictionary(std::map<std::string, K> {
        { "contract",       kj(contract.conId) },
        { "position",       ki(position) },
        { "marketPrice",    kf(marketPrice) },
        { "marketValue",    kf(marketValue) },
        { "averageCost",    kf(averageCost) },
        { "unrealizedPNL",  kf(unrealizedPNL) },
        { "realizedPNL",    kf(realizedPNL) },
        { "accountName",    kp((S)accountName.c_str()) }
    });
    receiveData("updatePortfolio", dict);
}
Exemple #20
0
void TwsDlWrapper::updatePortfolio( const Contract& contract,
	double position, double marketPrice, double marketValue, double averageCost,
	double unrealizedPNL, double realizedPNL, const IBString& accountName)
{
#if 0
	DEBUG_PRINTF( "PORTFOLIO_VALUE: %s %s %g %g %g %g %g %g %s",
		contract.symbol.c_str(), contract.localSymbol.c_str(), position,
		marketPrice, marketValue, averageCost, unrealizedPNL, realizedPNL,
		accountName.c_str() );
#endif
	RowPrtfl row = { contract, position, marketPrice, marketValue,
		averageCost, unrealizedPNL, realizedPNL, accountName};
	parentTwsDL->twsUpdatePortfolio( row );
}
///////////////////////////////////////////////////////////////////
// events
void PosixTestClient::orderStatus( OrderId orderId, const IBString &status, int filled,
	   int remaining, double avgFillPrice, int permId, int parentId,
	   double lastFillPrice, int clientId, const IBString& whyHeld)

{
	if( orderId == m_orderId) {
		if( m_state == ST_PLACEORDER_ACK && (status == "PreSubmitted" || status == "Submitted"))
			m_state = ST_CANCELORDER;

		if( m_state == ST_CANCELORDER_ACK && status == "Cancelled")
			m_state = ST_PING;

		printf( "Order: id=%ld, status=%s\n", orderId, status.c_str());
	}
}
void IBClient::error(const int id, const int errorCode, const IBString errorString)
{
    std::string type;
    
    if (1100 <= errorCode && errorCode <= 1300) {
        type = "system";
    } else if (2100 <= errorCode && errorCode <= 2110) {
        type = "warning";
    } else {
        type = "error";
    }
    
    receiveData(type.c_str(), knk(3, kj(id), kj(errorCode), kp((S)errorString.c_str())));
    
    // "Connectivity between IB and TWS has been lost"
    if (id == -1 && errorCode == 1100) {
        disconnect();
    }
    
    // Exception caught while reading socket - Connection reset by peer
    if (id == -1 && errorCode == 509) {
        disconnect();
    }
}
Exemple #23
0
void TwsDlWrapper::verifyCompleted( bool isSuccessful, const IBString& errorText)
{
	DEBUG_PRINTF( "VERIFY_COMPLETED: %s %s", isSuccessful ? "true" : "false",
		errorText.c_str() );
}
Exemple #24
0
void TwsDlWrapper::position( const IBString& account,
	const Contract& c, double pos, double avgCost )
{
	DEBUG_PRINTF( "POSITION: %s %s %s %g %g", account.c_str(),
		c.symbol.c_str(), c.localSymbol.c_str(), pos, avgCost );
}
Exemple #25
0
void TwsDlWrapper::fundamentalData( TickerId reqId,
	const IBString& data )
{
	DEBUG_PRINTF( "FUNDAMENTAL_DATA: %ld %s", reqId, data.c_str() );
}
Exemple #26
0
void TwsDlWrapper::verifyMessageAPI( const IBString& apiData)
{
	DEBUG_PRINTF( "VERIFY_MESSAGE_API: %s", apiData.c_str() );
}
Exemple #27
0
void TwsDlWrapper::displayGroupList( int reqId, const IBString& groups)
{
	DEBUG_PRINTF( "DISPLAY_GROUP_LIST: %d %s", reqId, groups.c_str() );
}
Exemple #28
0
void TwsDlWrapper::verifyAndAuthCompleted( bool isSuccessful,
	const IBString& errorText)
{
	DEBUG_PRINTF("VERIFY_AND_AUTH_COMPLETED: %d '%s'",
		isSuccessful, errorText.c_str());
}
Exemple #29
0
void TwsDlWrapper::verifyAndAuthMessageAPI( const IBString& apiData,
	const IBString& xyzChallange)
{
	DEBUG_PRINTF("VERIFY_AND_AUTH_MESSAGE_API: %s", apiData.c_str());
}
Exemple #30
0
void TwsDlWrapper::displayGroupUpdated( int reqId, const IBString& contractInfo)
{
	DEBUG_PRINTF( "DISPLAY_GROUP_UPDATED: %d %s", reqId, contractInfo.c_str() );
}