contractPrice(CONTRACT*) crashing script

Posted By: mhdus

contractPrice(CONTRACT*) crashing script - 08/27/18 21:31

Hi,
I'm using the simple test script below which is working almost as expected unless I'm commenting-in the contractPrice(C1); row which is causing the script to crash.
"Almost" because contractDays() is returning numbers such as 43369.50 - I assume this happens because I'm using it within a main() function so there is no current bar time, correct?
However, what's wrong with contractPrice()?? The futures chain seems loading just fine as the outputs are looking good.
I'm have been testing with Zorro 1.87 and 1.88.1, same issue.

Test Script:

#include <contract.c>
void main()
{
contractUpdate("GC",0,FUTURE);
printf("nLoaded %d contracts.",NumContracts);
CONTRACT* C1 =contract(FUTURE,5,0);
CONTRACT* C2 =contract(FUTURE,50,0);
// contractPrice(C1);
printf("ncontractDays C1 = %.2f",contractDays(C1));
contractPrint (C1);
printf("ncontractDays C2 = %.2f",contractDays(C2));
contractPrint (C2);
contractPrint ();
}
Posted By: Petra

Re: contractPrice(CONTRACT*) crashing script - 08/28/18 06:15

Better test with if(C1) that the pointer is not 0 before you do something with it.
Posted By: mhdus

Re: contractPrice(CONTRACT*) crashing script - 08/28/18 07:29

Fully agreed, as a general rule this should always be tested first.

However, for this small test script I thought the call to contractDays(C1) is a sufficient indirect confirmation that C1 is valid. Anyway, the script is still crashing, even after changing this line to

if(C1) contractPrice(C1);

Meanwhile I also changed the asset (to something trading at this time of day):

contractUpdate("DAX-IDX-SMART-EUR",0,FUTURE);

Here is the output:

MH_Fut_Chk01
Login 0 IB..
!IB Socket connected
!Account Unnnnnnn at UTC 08-28 07:13
!Get Future Chain DAX-FUT--0----EUR
Chain of 6 DAX-IDX-SMART-EUR contracts
Loaded 6 contracts.
Error 111: Crash in function: main() at bar 0
Logout.. ok

here is the output if the contractPrice() line is commented out:

MH_Fut_Chk01
Login 0 IB..
!IB Socket connected
!Account Unnnnnnn at UTC 08-28 07:23
!Get Future Chain DAX-FUT--0----EUR
Chain of 6 DAX-IDX-SMART-EUR contracts
Loaded 6 contracts.
contractDays C1 = 43364.50
FDXM,Future,20180921,0.0000,0.0000,0.0000,0.0000,5,0
contractDays C2 = 43455.50
FDXM,Future,20181221,0.0000,0.0000,0.0000,0.0000,5,0
Logout.. ok

The script is creating the following CSV:

Class,Type,Expiry,Strike,Underlying,Ask,Bid,Multiplier,Vol
FDXM,Future,20180921,0.0000,0.0000,0.0000,0.0000,5,0
FDAX,Future,20180921,0.0000,0.0000,0.0000,0.0000,25,0
FDXM,Future,20181221,0.0000,0.0000,0.0000,0.0000,5,0
FDAX,Future,20181221,0.0000,0.0000,0.0000,0.0000,25,0
FDAX,Future,20190315,0.0000,0.0000,0.0000,0.0000,25,0
FDXM,Future,20190315,0.0000,0.0000,0.0000,0.0000,5,0

Could this be a bug related to futures chains?
Posted By: jcl

Re: contractPrice(CONTRACT*) crashing script - 08/28/18 13:29

No, but it is in fact a bug related to contractPrice. This will be fixed in the final 1.88 release.
Posted By: mhdus

Re: contractPrice(CONTRACT*) crashing script - 08/28/18 13:47

Great, thanks for the feedback.
© 2024 lite-C Forums