For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

"Ambiguous contract: non/multiple answers received" error



  • Got a strange error in today's live trading session (still paper IB account) upon requesting contract details for some of my subscriptions (It happened just today, however the strategy is already running for few days without any changes in its code)

    The error:

    Ambiguous contract: none/multiple answers received
    

    is reported after 'reqContractDetails' request is issued. At first I suspected that something is wrong with the contract definition, however it was not the case (the same contract info is used for more than a month already without any change).

    after a short investigation it seems that it is a bug in IBStore.getContractDetails code:

        def getContractDetails(self, contract, maxcount=None):
            cds = list()
            q = self.reqContractDetails(contract)
            while True:
                msg = q.get()
                if msg is None:
                    break
                cds.append(msg)
    
            if not cds or (maxcount and len(cds) > maxcount):
                err = 'Ambiguous contract: none/multiple answers received'
                self.notifs.put((err, cds, {}))
                return None
    
            return cds
    

    The problem is that the above code assumes that after requesting the contract details ('reqContractDetails' call), the only messages that are going to be returned are the replies with the contract details. However this appears not always to be the case. Here the logs:

    14:01:11:754 <- 9-7-16777220-0-MU-STK--0---SMART-USD---0---
    
    14:01:12:035 -> 4-2--1-2106-HMDS data farm connection is OK:ushmds-
    
    14:01:12:151 -> 10-8-16777220-MU-STK--0--SMART-USD-MU-NMS-NMS-9939-0.01--ACTIVETIM,AD,ADJUST,ALERT,ALGO,ALLOC,AVGCOST,BASKET,BENCHPX,COND,CONDORDER,DARKONLY,DARKPOLL,DAY,DEACT,DEACTDIS,DEACTEOD,DIS,GAT,GTC,GTD,GTT,HID,IBKRATS,ICE,IMB,IOC,LIT,LMT,LOC,MIDPX,MIT,MKT,MOC,MTL,NGCOMB,NODARK,NONALGO,OCA,OPG,OPGREROUT,PEGBENCH,POSTONLY,PREOPGRTH,REL,RPI,RTH,SCALE,SCALEODD,SCALERST,SMARTSTG,SNAPMID,SNAPMKT,SNAPREL,STP,STPLMT,SWEEP,TRAIL,TRAILLIT,TRAILLMT,TRAILMIT,WHATIF-SMART,AMEX,NYSE,CBOE,PHLX,ISE,CHX,ARCA,ISLAND,DRCTEDGE,BEX,BATS,EDGEA,CSFBALGO,JEFFALGO,BYX,IEX,EDGX,FOXRIVER,TPLUS1,NYSENAT,PSX-1-0-MICRON TECHNOLOGY INC-NASDAQ--Technology-Semiconductors-Electronic Compo-Semicon-EST (Eastern Standard Time)-20200214:0400-20200214:2000;20200215:CLOSED;20200216:CLOSED;20200217:CLOSED;20200218:0400-20200218:2000;20200219:0400-20200219:2000;20200220:0400-20200220:2000;20200221:0400-20200221:2000;20200222:CLOSED;20200223:CLOSED;20200224:0400-20200224:2000;20200225:0400-20200225:2000;20200226:0400-20200226:2000;20200227:0400-20200227:2000;20200228:0400-20200228:2000;20200229:CLOSED;20200301:CLOSED;20200302:0400-20200302:2000;20200303:0400-20200303:2000;20200304:0400-20200304:2000;20200305:0400-20200305:2000;20200306:0400-20200306:2000;20200307:CLOSED;20200308:CLOSED;20200309:0400-20200309:2000;20200310:0400-20200310:2000;20200311:0400-20200311:2000;20200312:0400-20200312:2000;20200313:0400-20200313:2000;20200314:CLOSED;20200315:CLOSED;20200316:0400-20200316:2000;20200317:0400-20200317:2000;20200318:0400-20200318:2000;20200319:0400-20200319:2000-20200214:0930-20200214:1600;20200215:CLOSED;20200216:CLOSED;20200217:CLOSED;20200218:0930-20200218:1600;20200219:0930-20200219:1600;20200220:0930-20200220:1600;20200221:0930-20200221:1600;20200222:CLOSED;20200223:CLOSED;20200224:0930-20200224:1600;20200225:0930-20200225:1600;20200226:0930-20200226:1600;20200227:0930-20200227:1600;20200228:0930-20200228:1600;20200229:CLOSED;20200301:CLOSED;20200302:0930-20200302:1600;20200303:0930-20200303:1600;20200304:0930-20200304:1600;20200305:0930-20200305:1600;20200306:0930-20200306:1600;20200307:CLOSED;20200308:CLOSED;20200309:0930-20200309:1600;20200310:0930-20200310:1600;20200311:0930-20200311:1600;20200312:0930-20200312:1600;20200313:0930-20200313:1600;20200314:CLOSED;20200315:CLOSED;20200316:0930-20200316:1600;20200317:0930-20200317:1600;20200318:0930-20200318:1600;20200319:0930-20200319:1600---0-
    
    14:01:12:151 -> 52-1-16777220-
    

    As could be seen, an additional warning message (code 2106) was received before the contract details reply. However the code in 'reqContractDetails' doesn't check the expected message type and counts the warning (2106) message as yet another contract details message - resulting in "multiple answers" conclusion.

    After restarting the strategy few times, the error was reproduced at least three more times today - so it is not as rare and it may seem at first.

    Will try to fix it by checking the expected message type and upload the PR.

    BTW it seems there are quite a few PRs from multiple contributors already pending and nobody are reviewing/integrating them - would be interested to know what is the policy here, as I'm quite new to the game.

    Thanks
    Vlad



  • After further check - it seems the problem was caused by my own changes. The warning messages were pushed by mistake to the same message queue that was used by 'reqContractDetails'.

    My apologies. Please ignore this topic.


Log in to reply
 

});