IB Options - Issue with multiple Assets

Posted By: vinsom

IB Options - Issue with multiple Assets - 11/03/17 20:36


Hi,
I just slightly modified the SellRandom script from FinancialHacker to be able to trade multiple options assets.

In test works fine.
But when I go in Demo account on IB, in the second loop for the second asset (AAPL) the contract is always invalid.
First Asset (is always fine).
I did another test Still in IB demo account, removing the first asset(SPY), leaving only AAPL, and then the contract is valid and the trade is entered.

Is there anything I'm missing ?
Thanks for your help



// Options Test //////////////////////////

#include <contract.c>
static int LastExpiry[2];

void run()
{
int Handle=0;
BarPeriod = 1440;
BarZone = ET;
BarOffset = 15*60;
StartDate = 20140101;
EndDate = 20171001;
set(PRELOAD|LOGFILE);
PlotWidth = 1000;
PlotHeight1 = 400;

while(asset(loop("SPY","AAPL")))
{
Handle++;
assetHistory(Asset,FROM_AV|UNADJUSTED);
if(is(INITRUN))
{
char FileName[100];
sprintf(FileName, "%s_SimOptions.t8",Asset );
dataLoad(Handle,FileName,9);
}

contractUpdate(Asset,Handle,CALL|PUT);
Multiplier = 100;
int Type = ifelse(random() > 0,CALL,PUT);
CONTRACT *c=contract(Type,30,priceClose());

if(c && ContractType && LastExpiry[Handle-1] != ContractExpiry && !is(LOOKBACK))
{
contractPrint(c);
printf("n %s %s ContractType:%d ContractExpiry:%d Strike:%f LastExpiry:%d",Asset,strdate("%Y-%m-%d %H:%M:%S"), ContractType, ContractExpiry, priceClose(), LastExpiry[Handle-1]);
enterShort();
printf("n SOLD!");
LastExpiry[Handle-1] = ContractExpiry;
}
else if(!is(LOOKBACK))
{
printf("n %s %s ContractType:%d ContractExpiry:%d Strike:%f LastExpiry:%d",Asset,strdate("%Y-%m-%d %H:%M:%S"), ContractType, ContractExpiry, priceClose(), LastExpiry[Handle-1]);
printf("n INVALID!");
}
}
}
Posted By: jcl

Re: IB Options - Issue with multiple Assets - 11/06/17 09:09

The script looks ok at first glance. Maybe it is an issue with the IB plugin. I've forwarded this to the developers for looking into the problem.
Posted By: jcl

Re: IB Options - Issue with multiple Assets - 11/07/17 09:35

I was told that this is really a bug, but it cannot be fixed on the Zorro side. It must be accounted for in the script. The IB API can sometimes not deliver two option chains directly in sequence. It needs a couple seconds between the SPY and the AAPL options chain. That's why you did not get the chain for the second asset.

Solution: use Sleep() or wait() in your loop for waiting 10-30 seconds before the second contractUpdate call. This behavior is apparently dependent on the market situation, in the past we observed no problem to get several options chains in sequence.

This will be mentioned in the manual.
Posted By: vinsom

Re: IB Options - Issue with multiple Assets - 11/10/17 20:41

Thanks, looks like the wait is fixing the issue
© 2024 lite-C Forums