function IBMatlab_ArrivalPriceAlgo(ibConnectionObject)
% Arrival Price algo example based on: 
% http://www.interactivebrokers.com/php/apiUsersGuide/apiguide.htm#apiguide/tables/ibalgo_parameters.htm

%{
// This is the original Java source code:
import com.ib.client.TagValue;

Contract m_contract = new Contract();
Order m_order = new Order();
Vector<TagValue> m_algoParams = new Vector<TagValue>();

/** Stocks */
m_contract.m_symbol = "MSFT";
m_contract.m_secType = "STK";
m_contract.m_exchange = "SMART";
m_contract.m_currency = "USD";

/** Arrival Price */
m_algoParams.add( new TagValue("maxPctVol","0.01") );
m_algoParams.add( new TagValue("riskAversion","Passive") );
m_algoParams.add( new TagValue("startTime","9:00:00 EST") );
m_algoParams.add( new TagValue("endTime","15:00:00 EST") );
m_algoParams.add( new TagValue("forceCompletion","0") );
m_algoParams.add( new TagValue("allowPastEndTime","1") );

m_order.m_action = "BUY";
m_order.m_totalQuantity = 1;
m_order.m_orderType = "LMT";
m_order.m_lmtPrice = 0.14
m_order.m_algoStrategy = "ArrivalPx";
m_order.m_algoParams = m_algoParams;
m_order.m_transmit = false;
m_client.placeOrder(40, m_contract, m_order);
%}

import com.ib.client.TagValue;

% First create the contract
m_contract = ibConnectionObject.createContract('MSFT','STK','',0,'','SMART','USD','MSFT');

% Alternately, we could have done as follows:
m_contract = ibConnectionObject.createContract('','','',0,'','','','');
m_contract.m_symbol   = 'MSFT';
m_contract.m_secType  = 'STK';
m_contract.m_exchange = 'SMART';
m_contract.m_currency = 'USD';

% Now set the Arrival Price algoParams
m_algoParams = java.util.Vector;
m_algoParams.add( TagValue('maxPctVol','0.01') );
m_algoParams.add( TagValue('riskAversion','Passive') );
m_algoParams.add( TagValue('startTime','9:00:00 EST') );
m_algoParams.add( TagValue('endTime','15:00:00 EST') );
m_algoParams.add( TagValue('forceCompletion','0') );
m_algoParams.add( TagValue('allowPastEndTime','1') );

% Now create the order, using algoParams
m_order = ibConnectionObject.createOrder('BUY', 1, 'LMT', 0.14, 0, '', '', 0, '', '', realmax, 0, false);
m_order.m_algoStrategy = 'ArrivalPx';
m_order.m_algoParams = m_algoParams;
m_order.m_transmit = false;

% Finally, send the order to the IB server
ibConnectionObject.placeOrder(40, m_contract, m_order);
