///////////////////////////////////////////////////////////////////// // // Function: Execute // // Description: // ///////////////////////////////////////////////////////////////////// UINT BOINCCABase::Execute() { UINT uiReturnValue = 0; OnInitialize(); if ( TRUE == MsiGetMode( m_hMSIHandle, MSIRUNMODE_SCHEDULED ) ) { uiReturnValue = OnInstall(); } else if ( TRUE == MsiGetMode( m_hMSIHandle, MSIRUNMODE_COMMIT ) ) { uiReturnValue = OnCommit(); } else if ( TRUE == MsiGetMode( m_hMSIHandle, MSIRUNMODE_ROLLBACK ) ) { uiReturnValue = OnRollback(); } else { uiReturnValue = OnExecution(); } OnCleanup(); return uiReturnValue; }
// before entry to this method, sanity check: side on execution is same as side on order void Position::HandleExecution( const std::pair<const Order&, const Execution&>& status ) { // should be able to calculate profit/loss & position cost as exections are encountered // should be able to calculate position cost basis as position is updated (with and without commissions) // will need market feed in order to calculate profit/loss -- handled in the OnQuote method const Order& order = status.first; const Execution& exec = status.second; Order::idOrder_t orderId = order.GetOrderId(); double dblOldRealizedPL = m_row.dblRealizedPL; double dblOldUnRealizedPL = m_row.dblUnRealizedPL; //std::cout << "Position Exec: " << exec.GetSize() << "," << exec.GetPrice() << std::endl; // update position, regardless of whether we see order open or closed UpdateRowValues( exec.GetPrice(), exec.GetSize(), exec.GetOrderSide() ); if ( ( 0 == m_row.nPositionActive ) && ( OrderSide::Unknown != m_row.eOrderSideActive ) ) { std::cout << "problems" << std::endl; } // check that we think that the order is still active bool bOrderFound = false; for ( std::vector<pOrder_t>::iterator iter = m_vOpenOrders.begin(); iter != m_vOpenOrders.end(); ++iter ) { if ( orderId == iter->get()->GetOrderId() ) { // update position based upon current position and what is executing // decrease position when execution is opposite position // increase position when execution is same as position m_row.nPositionPending -= exec.GetSize(); if ( 0 == m_row.nPositionPending ) m_row.eOrderSidePending = OrderSide::Unknown; if ( 0 == order.GetQuanRemaining() ) { // move from open to closed on order filled m_vClosedOrders.push_back( *iter ); m_vOpenOrders.erase( iter ); } bOrderFound = true; break; } } if ( !bOrderFound ) { // need to handle the case where order was cancelled, but not in time to prevent execution throw std::runtime_error( "Position::HandleExecution doesn't have an Open Order" ); } OnUnRealizedPL( PositionDelta_delegate_t( *this, dblOldUnRealizedPL, m_row.dblUnRealizedPL ) ); // used by portfolio updates OnExecutionRaw( execution_pair_t( *this, exec ) ); OnUpdateExecutionForPortfolioManager( *this ); OnExecution( PositionDelta_delegate_t( *this, dblOldRealizedPL, m_row.dblRealizedPL ) ); // used by portfolio updates OnPositionChanged( *this ); }