Wrapping Functions

During development of Automated Trading systems, “wrapping” functions (i.e., calling a standard function from a custom function) for the Interactive Brokers Controller (IBc) allows you to add debug statements to your code without making your main code difficult to read. Here is an example where the standard ibc.IsOrderPending() is wrapped by a custom afl function named IsOrderPending():

function IsOrderPending( ORderID )
{
global ibc;
IsPending = ibc.IsOrderPending( ORderID );
TRACE("# Pending Status for OrderID: " + ORderID + " is "+NumToStr(IsPending,1.0));
return IsPending;
}

Instead of calling the IBc function directly, you now call it from a function that is identically named but has the prefix ibc. removed. This allows you to attach debugging statements and utility code (such as managing OrderIDs) to your automated trading (AT) functions without increasing the length of your main code. All you have to do to restore full speed operation is to re-attach the ibc. to the wrapper function names. Other ibc. functions can be wrapped similarly.

Wrapping functions slow down AFL slightly, but the loss in speed is more than offset and justifiable by the lack of clutter in your main code with long _TRACE() statements.

Edited by Al Venosa

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...Loading...

Comments are closed.