Create "Adaptive Algo" Order - Interactive Broker API

I'm trying to determine the matlab method of creating an "Adaptive Algo" order in the Interactive Broker api. The c# method is stated here: https://interactivebrokers.github.io/tws-api/ibalgos.html#adaptive however, I can't figure out its matlab equivalent
C#:
Order baseOrder = OrderSamples.LimitOrder("BUY", 1000, 1);
...
AvailableAlgoParams.FillAdaptiveParams(baseOrder, "Normal");
client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder);
...
public static void FillAdaptiveParams(Order baseOrder, string priority)
{
baseOrder.AlgoStrategy = "Adaptive";
baseOrder.AlgoParams = new List<TagValue>();
baseOrder.AlgoParams.Add(new TagValue("adaptivePriority", priority));
}
What I've done so far in Matlab:
% Create TWS connection and Create Order
ib = ibtws('',7496);
ibOrder = ib.Handle.createOrder;
ibOrder.action = 'BUY';
ibOrder.totalQuantity = 1000;
ibOrder.orderType = 'LMT';
% Specifying Adaptive Algo Order
ibOrder.algoStrategy = "Adaptive";

 채택된 답변

Annie Leonhart
Annie Leonhart 2019년 12월 21일
편집: Annie Leonhart 2019년 12월 23일
I have not tested this, but it should work. I'm about 99.75% sure. Let me know how it goes. If you want to change the algo, the same concept will apply. Create the algo properties, then set the value. Easy.
% Connect to IBTWS or GATEWAY
ib = ibtws('',4001,0);
% Create Contract
contract = ib.Handle.createContract;
contract.symbol = 'AAPL';
contract.secType = 'STK';
contract.exchange = 'SMART';
contract.primaryExchange = 'SMART';
contract.currency = 'USD';
% Create Order
order = ib.Handle.createOrder;
order.action = 'BUY';
order.totalQuantity = 1000;
order.orderType = 'LMT';
order.lmtPrice = '274.25';
% Add properties for Algo order
order.algoStrategy = 'Adaptive';
addproperty(order.algoParams,'adaptivePriority');
order.algoParams.adaptivePriority = 'Normal';
% Place the order
id = orderid(ib);
exec = createOrder(ib,contract,order,id);
% Check order status after 5 seconds
pause(5);
exec(1,1).STATUS

댓글 수: 4

Hi, thanks for the reply.
I tried what you suggested but received the error mssg:
Unrecognized property 'adaptivePriority' for class 'Interface.CC48E64E_.......
Found the solution. I needed to use createtagvalue.
%% Connect to IBTWS or GATEWAY
ib = ibtws('',4001,0);
%% Create Contract
contract = ib.Handle.createContract;
contract.symbol = 'AAPL';
contract.secType = 'STK';
contract.exchange = 'SMART';
contract.primaryExchange = 'SMART';
contract.currency = 'USD';
%% Create Order
order = ib.Handle.createOrder;
order.account = 'XXXXXXX'
order.action = 'BUY';
order.totalQuantity = 1;
order.orderType = 'LMT';
order.lmtPrice = 100;
%% Add properties for Algo order
order.algoStrategy = 'Adaptive';
algo = ib.Handle.createTagValueList;
addproperty(algo,'adaptivePriority');
algo.adaptivePriority = 'Normal';
order.algoParams = algo;
%% Place the order
id = orderid(ib);
exec = createOrder(ib,contract,order,id);
%% Check order status after 5 seconds
exec(1,1).STATUS
I have tested the solution live. I can confirm the order is submitted and live.
tx5U9gC.png
Hi,
The updated solution worked perfectly!
Thanks!
Very good.
You can use the same concept to build out all the other Algos following the API.
For example. Here's the Accumulate/Distribute algo in python converted to MATLAB
Screenshot_9.jpg
@staticmethod
def FillAccumulateDistributeParams(baseOrder: Order, componentSize: int,
timeBetweenOrders: int, randomizeTime20: bool, randomizeSize55: bool,
giveUp: int, catchUp: bool, waitForFill: bool, startTime: str,
endTime: str):
baseOrder.algoStrategy = "AD"
baseOrder.algoParams = []
baseOrder.algoParams.append(TagValue("componentSize", componentSize))
baseOrder.algoParams.append(TagValue("timeBetweenOrders", timeBetweenOrders))
baseOrder.algoParams.append(TagValue("randomizeTime20",
int(randomizeTime20)))
baseOrder.algoParams.append(TagValue("randomizeSize55",
int(randomizeSize55)))
baseOrder.algoParams.append(TagValue("giveUp", giveUp))
baseOrder.algoParams.append(TagValue("catchUp", int(catchUp)))
baseOrder.algoParams.append(TagValue("waitForFill", int(waitForFill)))
baseOrder.algoParams.append(TagValue("activeTimeStart", startTime))
baseOrder.algoParams.append(TagValue("activeTimeEnd", endTime))
Converted Matlab code
%% Connect to IBTWS or GATEWAY
ib = ibtws('',4001,0);
%% Create Contract
contract = ib.Handle.createContract;
contract.symbol = 'AAPL';
contract.secType = 'STK';
contract.exchange = 'SMART';
contract.primaryExchange = 'SMART';
contract.currency = 'USD';
%% Create Order
order = ib.Handle.createOrder;
%order.account = 'XXXXXXX'
order.action = 'BUY';
order.totalQuantity = 1;
order.orderType = 'LMT';
order.lmtPrice = 100;
%% Add properties for Algo order
FillAccumulateDistrubuteParams(ib, order, 10, 60, 1, 1, 1, 1, 1, '20191231-12:00:00',...
'20191231-16:00:00')
%% Place the order
id = orderid(ib);
exec = createOrder(ib,contract,order,id);
%% Check order status after 5 seconds
exec(1,1).STATUS
% IB Accumulate/Distribute Algo Function
function FillAccumulateDistrubuteParams(c, order, componentSize, timeBetweenOrders,...
randomTime20, randomSize55, giveUp, catchUp, waitForFill, startTime, endTime)
startTime = datestr(startTime,'yyyymmdd HH:MM:SS');
endTime = datestr(endTime,'yyyymmdd HH:MM:SS');
order.algoStrategy = "AD";
algo = c.Handle.createTagValueList;
addproperty(algo, 'componentSize'); algo.componentSize = componentSize;
addproperty(algo, 'timeBetweenOrders');algo.timeBetweenOrders = timeBetweenOrders;
addproperty(algo, 'randomTime20');algo.randomTime20 = randomTime20;
addproperty(algo, 'randomSize55');algo.randomSize55 = randomSize55;
addproperty(algo, 'giveUp');algo.giveUp = giveUp;
addproperty(algo, 'catchUp');algo.catchUp = catchUp;
addproperty(algo, 'waitForFill');algo.waitForFill = waitForFill;
addproperty(algo, 'startTime');algo.startTime = startTime;
addproperty(algo, 'endTime');algo.endTime = endTime;
disp('Algo configured.')
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Transaction Cost Analysis에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2019년 12월 3일

편집:

2019년 12월 30일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by