市场数据:IbPy

时间:2016-12-15 17:02:14

标签: python ibpy

我无法获得市场数据,我一直收到同样的错误,我不知道为什么。这是我的代码:

from ib.ext.Contract import Contract
from ib.opt import ibConnection, message
from time import sleep

# print all messages from TWS
def watcher(msg):
    print msg

# show Bid and Ask quotes
def my_BidAsk(msg):
    if msg.field == 1:
        print ('%s:%s: bid: %s' % (contractTuple[0],
                       contractTuple[6], msg.price))

elif msg.field == 2:
    print ('%s:%s: ask: %s' % (contractTuple[0], contractTuple[6],msg.price))

))

def makeStkContract(contractTuple):
    newContract = Contract()
    newContract.m_symbol = contractTuple[0]
    newContract.m_secType = contractTuple[1]
    newContract.m_exchange = contractTuple[2]
    newContract.m_currency = contractTuple[3]
    newContract.m_expiry = contractTuple[4]
    newContract.m_strike = contractTuple[5]
    newContract.m_right = contractTuple[6]
print ('Contract Values:%s,%s,%s,%s,%s,%s,%s:' % contractTuple)
return newContract

if __name__ == '__main__':
con = ibConnection(port = 7497, clientId = 9615)
con.registerAll(watcher)
showBidAskOnly = True  # set False to see the raw messages
if showBidAskOnly:
    con.unregister(watcher, message.tickSize, message.tickPrice,
                   message.tickString, message.tickOptionComputation)
    con.register(my_BidAsk, message.tickPrice)
con.connect()
sleep(1)
tickId = 321

# Note: Option quotes will give an error if they aren't shown in TWS
contractTuple = ('AAPL', 'STK', 'SMART', 'USD', '', 0.0, 'False')
#contractTuple = ('QQQQ', 'OPT', 'SMART', 'USD', '20070921', 47.0, 'CALL')
#contractTuple = ('ES', 'FUT', 'GLOBEX', 'USD', '200709', 0.0, '')
#contractTuple = ('ES', 'FOP', 'GLOBEX', 'USD', '20070920', 1460.0, 'CALL')
#contractTuple = ('EUR', 'CASH', 'IDEALPRO', 'USD', '', 0.0, '')
stkContract = makeStkContract(contractTuple)
print ('* * * * REQUESTING MARKET DATA * * * *')
con.reqMktData(tickId, stkContract, 'con', False)
sleep(15)
print ('* * * * CANCELING MARKET DATA * * * *')
con.cancelMktData(tickId)
sleep(1)
con.disconnect()
sleep(1)

它返回此错误:

  Server Version: 76
TWS Time at connection:20161215 16:49:25 Greenwich Mean Time
<managedAccounts accountsList=DU226951>
<nextValidId orderId=7>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:usfuture>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:eufarm>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:cashfarm>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:usfarm>
<error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:ushmds>
Contract Values:AAPL,STK,SMART,USD,,0.0,False:
* * * * REQUESTING MARKET DATA * * * *
<error id=321, errorCode=321, errorMsg=Error validating request:-'bi' : cause - Incorrect generic tick list of con.  Legal ones for (STK) are: 100(Option Volume),101(Option Open Interest),105(Average Opt Volume),106(impvolat),107(climpvlt),125(Bond analytic data),165(Misc. Stats),166(CScreen),221/220(Creditman Mark Price),225(Auction),232/221(Pl Price),233(RTVolume),236(inventory),258/47(Fundamentals),291(ivclose),293(TradeCount),294(TradeRate),295(VolumeRate),318(LastRTHTrade),370(ParticipationMonitor),370(ParticipationMonitor),375(RTTrdVolume),377(CttTickTag),377(CttTickTag),381(IB Rate),384(RfqTickRespTag),384(RfqTickRespTag),387(DMM),388(Issuer Fundamentals),391(IBWarrantImpVolCompeteTick),405(Index Capabilities),407(FuturesMargins),411(rthistvol),428(Monetary Close Price),439(MonitorTickTag),439(MonitorTickTag),456/59(IBDividends),459(RTCLOSE),460(Bond Factor Multiplier),499(Fee and Rebate Rate),506(midptiv),511(hvolrt10 (per-underlying)),512(hvolrt30 (per-underlying)),513(hvolrt50 (per-underlying)),514(hvolrt75 (per-underlying)),515(hvolrt100 (per-underlying)),516(hvolrt150 (per-underlying)),517(hvolrt200 (per-underlying)),521(fzmidptiv),545(vsiv),576(EtfNavBidAsk(navbidask)),577(EtfNavLast(navlast)),578(EtfNavClose(navclose)),584(Average Opening Vol.),585(Average Closing Vol.),587(Pl Price Delayed),588(Futures Open Interest),595(Short-Term Volume X Mins),608(EMA N),614(EtfNavMisc(hight/low)),619(Creditman Slow Mark Price),623(EtfFrozenNavLast(fznavlast))>
* * * * CANCELING MARKET DATA * * * *
<error id=321, errorCode=300, errorMsg=Can't find EId with tickerId:321>
>>> 

我认为这与刻度ID有关,我需要为它附加一个不同的数字。关于我出错的地方的任何帮助都会很棒。感谢。

0 个答案:

没有答案