Problem using 'execution()' function IB Trading Toolbox.

3 visualizaciones (últimos 30 días)
Gijs van Beek
Gijs van Beek el 3 de Mzo. de 2020
Comentada: Annie Leonhart el 30 de Mzo. de 2020
I have a problem using the 'executions' function for IB. When I call:
f = ib.Handle.createExecutionFilter;
f.side = 'BUY';
f.secType = ibContract.sectype;
f.exchange = ibContract.exchange;
f.symbol = ibContract.symbol;
f.time = char(datetime(now-1/24,'ConvertFrom', 'datenum','Format', 'yyyyMMdd HH:mm:ss')); %WORKS in the request, but only the last execution is displayed.
d = ib.executions(f);
I get only 1 execution returned, although I have made 6 BUY executions in the last hour. I am not that familiair with events in MATLAB so please do not blame me for newby mistakes here below! ;-)
Looking at the callback function MATLAB built, I argue executions() should give me all the requested executions in the last hour ... Not just the last (see the callback code below). The callback function looks at the size of 'ibBuiltInExecutionData' and then adds one... When I request 6 executions 'numEls' is 0 or 1, but never greater then 1. The size of 'ibBuiltInExecutionData' should increase on each event, right...?
function ibBuiltInExecutionEventHandler(varargin)
%IBBUILTINEXECUTIONEVENTHANDLER Interactive Brokers' Trader Workstation built in executions data event handler.
persistent ibBuiltInExecutionData
numEls = size(ibBuiltInExecutionData,1);
% Trap event type
switch varargin{end-1}
case {'execDetailsEx'}
if numEls == 1
ibBuiltInExecutionData.contract = get(varargin{6}.contract);
ibBuiltInExecutionData.execution = get(varargin{6}.execution);
else
ibBuiltInExecutionData(numEls+1).contract = get(varargin{6}.contract);
ibBuiltInExecutionData(numEls+1).execution = get(varargin{6}.execution);
end
assignin('base','ibBuiltInExecutionData',ibBuiltInExecutionData);
case {'execDetailsEnd'}
if numEls == 1
ibBuiltInExecutionData.enddetails = varargin{4};
else
ibBuiltInExecutionData(numEls+1).enddetails = varargin{4};
end
% Return data to base workspace
assignin('base','ibBuiltInExecutionData',ibBuiltInExecutionData);
clear ibBuiltInExecutionData
evtListeners = varargin{1}.eventlisteners;
i = strcmp(evtListeners(:,1),'execDetailsEx');
varargin{1}.unregisterevent([{evtListeners{i,1}}' {evtListeners{i,2}}']);
i = strcmp(evtListeners(:,1),'execDetailsEnd');
varargin{1}.unregisterevent([{evtListeners{i,1}}' {evtListeners{i,2}}']);
varargin{end}.DataRequest = false;
end
The function executions() with this callback gives me:
d =
struct with fields:
contract: [1×1 struct]
execution: [1×1 struct]
enddetails: [1×1 struct]
I argue this should be a 1x6 struct...
When I comment out line 71-74 & 77 and 82-84 & 86 (bypassing the if/else-statements for numEls) I do get more then one execution returned, but it is only the first and the last execution. See the code below:
function ibBuiltInExecutionEventHandler(varargin)
%IBBUILTINEXECUTIONEVENTHANDLER Interactive Brokers' Trader Workstation built in executions data event handler.
persistent ibBuiltInExecutionData
numEls = size(ibBuiltInExecutionData,1);
% Trap event type
switch varargin{end-1}
case {'execDetailsEx'}
% if numEls == 1
% ibBuiltInExecutionData.contract = get(varargin{6}.contract);
% ibBuiltInExecutionData.execution = get(varargin{6}.execution);
% else
ibBuiltInExecutionData(numEls+1).contract = get(varargin{6}.contract);
ibBuiltInExecutionData(numEls+1).execution = get(varargin{6}.execution);
% end
assignin('base','ibBuiltInExecutionData',ibBuiltInExecutionData);
case {'execDetailsEnd'}
% if numEls == 1
% ibBuiltInExecutionData.enddetails = varargin{4};
% else
ibBuiltInExecutionData(numEls+1).enddetails = varargin{4};
% end
% Return data to base workspace
assignin('base','ibBuiltInExecutionData',ibBuiltInExecutionData);
clear ibBuiltInExecutionData
evtListeners = varargin{1}.eventlisteners;
i = strcmp(evtListeners(:,1),'execDetailsEx');
varargin{1}.unregisterevent([{evtListeners{i,1}}' {evtListeners{i,2}}']);
i = strcmp(evtListeners(:,1),'execDetailsEnd');
varargin{1}.unregisterevent([{evtListeners{i,1}}' {evtListeners{i,2}}']);
varargin{end}.DataRequest = false;
end
Using this callback I get:
d =
1×2 struct array with fields:
contract
execution
enddetails
This includes only the first and last execution...
Why does the size of 'ibBuiltInExecutionData' not increase? How can I get all the requested executions in my workspace returned in variable 'd'?
Thank you in advance!
My system setup is:
- The most recent version of the IB API (9.79.01).
- My Matlab version 9.7.0.1296695 (R2019b) Update 4
- The Trading Toolbox is also the most recent (Version 3.6 (R2019b) 18-Jul-2019)
Gijs van Beek
  4 comentarios
Gijs van Beek
Gijs van Beek el 24 de Mzo. de 2020
Once you get it, it is indeed not that hard. I am building myself a pretty nice application using those eventhandlers.
What do you mean by using the IB gateway api? Is there a difference with the IB TWS api (other then the interface)?
Annie Leonhart
Annie Leonhart el 30 de Mzo. de 2020
Yes, there is a huge difference.
  1. Faster
  2. Able to troubleshoot API calls.
With the Gateway, even without an eventhandler, you can run the request, and see the output in the Gateway. You can then build the eventhandler from the output. The output is messy, but it's good enough to know what events you needs to catch with the handler, and the fields.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Transaction Cost Analysis en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by