realtimebars

526 views
Skip to first unread message

Christophe

unread,
Dec 3, 2009, 2:19:52 PM12/3/09
to IbPy Discuss
Hi,

Has anyone managed to receive real time bars?
I've try to get real time bars using the code below which is based on
the fancy_marketdata example but I don't seem to get any update.


#! /usr/bin/env python
# -*- coding: utf-8 -*-

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

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

# show Bid and Ask quotes
def my_BidAsk(msg):
print "msg:", 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 msgHandle(msg):
print msg

def errorHandler(msg):
print msg

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()
con.registerAll(watcher)
con.register(errorHandler, Error)
con.connect()
sleep(1)
tickId = 10
tickId2 = 2

# Note: Option quotes will give an error if they aren't shown in
TWS
contractTuple = ('QQQQ', 'STK', 'SMART', 'USD', '', 0.0, '')
#contractTuple = ('QQQQ', 'OPT', 'SMART', 'USD', '20070921', 47.0,
'CALL')
#contractTuple = ('ES', 'FUT', 'GLOBEX', 'USD', '200912', 0.0, '')
#contractTuple = ('N225M', 'FUT', 'OSE.JPN', 'JPY', '200912', 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.reqRealTimeBars(tickId, stkContract, 5, 'MIDPOINT', False)
#con.reqMktData(tickId2, stkContract, '', False)
sleep(30)
print '* * * * CANCELING MARKET DATA * * * *'
con.cancelRealTimeBars(tickId)
#con.cancelMktData(tickId2)
sleep(1)
con.disconnect()
sleep(1)


Thanks,

Christophe

merlinson

unread,
Dec 3, 2009, 3:10:13 PM12/3/09
to IbPy Discuss
Hi Christophe,

It looks to me like you did it correctly. I got this for an output:

* * * * REQUESTING MARKET DATA * * * *
Watcher: <RealtimeBar reqId=10, time=1259870775, open=44.245,
high=44.245, low=44.245, close=44.245, volume=-1, wap=-1.0, count=-1>
Watcher: <RealtimeBar reqId=10, time=1259870780, open=44.245,
high=44.245, low=44.245, close=44.245, volume=-1, wap=-1.0, count=-1>
Watcher: <RealtimeBar reqId=10, time=1259870785, open=44.245,
high=44.245, low=44.245, close=44.245, volume=-1, wap=-1.0, count=-1>
Watcher: <RealtimeBar reqId=10, time=1259870790, open=44.245,
high=44.245, low=44.245, close=44.245, volume=-1, wap=-1.0, count=-1>
Watcher: <RealtimeBar reqId=10, time=1259870795, open=44.245,
high=44.245, low=44.245, close=44.245, volume=-1, wap=-1.0, count=-1>
Watcher: <RealtimeBar reqId=10, time=1259870800, open=44.245,
high=44.245, low=44.245, close=44.245, volume=-1, wap=-1.0, count=-1>
Watcher: <RealtimeBar reqId=10, time=1259870805, open=44.245,
high=44.245, low=44.245, close=44.245, volume=-1, wap=-1.0, count=-1>
* * * * CANCELING MARKET DATA * * * *

I wonder what's going on?

Best regards,
Merlinson

Christophe

unread,
Dec 3, 2009, 3:47:35 PM12/3/09
to IbPy Discuss
Hi Merlinson,

Thanks for the reply. I wonder what's going on.
I get the following messages in the terminal:
03-Dec-09 20:40:08 DEBUG Server Version: 45
03-Dec-09 20:40:08 DEBUG TWS Time at connection: 20091203
20:40:03 Greenwich Mean Time
Watcher: <NextValidId orderId=1>
Watcher: <OpenOrderEnd >
Watcher: <Error id=-1, errorCode=2104, errorMsg=Market data farm
connection is OK:ibdemo>
<Error id=-1, errorCode=2104, errorMsg=Market data farm connection is
OK:ibdemo>
Watcher: <Error id=-1, errorCode=2106, errorMsg=HMDS data farm
connection is OK:demohmds>
<Error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is
OK:demohmds>
Contract Values:ES,FUT,GLOBEX,USD,200912,0.0,:
* * * * REQUESTING MARKET DATA * * * *
* * * * CANCELING MARKET DATA * * * *

And in the terminal where I've started TWS, I see:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at jextend.pe.a(pe.java:169)
at hmdscore.xml.f.run(f.java:235)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters
(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter
(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy
(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:
169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:
161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
20:40:21:092 JTS-EServerSocket-90: [0:45:45:1:0:0:0:SYS] Client{0}
terminated conversation.

Regards,

Christophe

merlinson

unread,
Dec 3, 2009, 4:30:09 PM12/3/09
to IbPy Discuss
Holy cow, a Java error. That is beyond my pay grade. For all my
great skill in generating errors, I haven't seen many of those. Hmm,
does the standard fancy_marketdata in the demo run normally? Are you
using the latest versions of everything? My last dumb suggestion:
reinstall?

Wish I had a clue.

Christophe

unread,
Dec 3, 2009, 4:59:09 PM12/3/09
to IbPy Discuss
I'm running Ubuntu on 2 machines which have recently been installed so
it's fairly clean.

I've got:
Python 2.6.4
IBPy from svn
TWS Build 899.8
Java version 1.6.0_15 (package sun-java6-jre )

What java do you run?

Thanks,

Christophe

merlinson

unread,
Dec 3, 2009, 5:18:26 PM12/3/09
to IbPy Discuss
I'm using Ubuntu (Karmic 64-bit) also:

python 2.6.4
IbPy-0.7.6.9.51 (the download)
TWS Build 899.8
Java version from sun-java6-jre is 6-15-1

I think it would be really weird if the fancy_marketdata example in
the demo directory didn't fail in the same way because those two are
so similar.

Christophe

unread,
Dec 3, 2009, 7:15:37 PM12/3/09
to IbPy Discuss
We have a very similar setup. The differences are Ibpy and that I'm on
a 32 bit machine.
I've tried IbPy-0.7.6.9.51 and I get the same error. I've also tried
other version of java, and I still get the same error.

I've searched the IB forum, and some people suggest that realtimebars
do not work with a demo account. I do not have an account yet so I
cannot confirm that. Is that something you can test?

merlinson

unread,
Dec 3, 2009, 7:34:03 PM12/3/09
to IbPy Discuss
Well, I'll be a monkey's uncle! The fancy_marketdata example works in
the demo system but the realtimebars example fails. At least it
doesn't return any data. I seem to have started the demo system
directly without a terminal so I can't see any errors. But it doesn't
crash the demo system anyway. I was running in the paper trading
account and I think you found the problem.

Best regards

Christophe

unread,
Dec 4, 2009, 12:51:09 PM12/4/09
to IbPy Discuss
Thanks for your help. We both learned something there. :-)

Janus Cheng

unread,
Sep 27, 2015, 10:36:00 PM9/27/15
to IbPy Discuss
hi ,
i am a newbie, i  have copied the most code and run in my computer, but reqRealtimeBars can't appear anything, does anyone know why?
i use win 7, updated java version, python 2.7, API 9.7
The result showed as below, thanks.

Server Version: 76
TWS Time at connection:20150927 16:32:33 CST
Watcher:  <managedAccounts accountsList=DU20034>
Watcher:  <nextValidId orderId=1>
Watcher:  <error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:ibdemo>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:ibdemo>
Watcher:  <error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:demohmds>
<error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:demohmds>
Contract Values:GOOGL,STK,SMART,USD,,0.0,:

* * * * REQUESTING MARKET DATA * * * *
* * * * CANCELING MARKET DATA * * * *

Process finished with exit code 0

Patrick Actor

unread,
Sep 27, 2015, 10:55:04 PM9/27/15
to ibpy-d...@googlegroups.com

Janus, not all symbols are available from ibdemo account. Open TWS and use quote tab. It may state googl is not available.

--
You received this message because you are subscribed to the Google Groups "IbPy Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ibpy-discuss...@googlegroups.com.
To post to this group, send email to ibpy-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/ibpy-discuss.
For more options, visit https://groups.google.com/d/optout.

Janus Cheng

unread,
Sep 28, 2015, 6:36:38 AM9/28/15
to IbPy Discuss
Thanks Gunsn. I found "GOOGL" exist in the quote tab and try others like "AAPL", "IBM", but result same to before. If I back to use "QQQQ", it apear error msg, like that:
"
 Contract Values:QQQQ,STK,SMART,USD,,0.0,:

* * * * REQUESTING MARKET DATA * * * *
Watcher:  <error id=10, errorCode=200, errorMsg=No security definition has been found for the request>
<error id=10, errorCode=200, errorMsg=No security definition has been found for the request>

* * * * CANCELING MARKET DATA * * * *
Watcher:  <error id=10, errorCode=300, errorMsg=Can't find EId with tickerId:10>
<error id=10, errorCode=300, errorMsg=Can't find EId with tickerId:10>


Process finished with exit code 0
"
Thanks.

GunsnMoney於 2015年9月28日星期一 UTC+8上午10時55分04秒寫道:
Reply all
Reply to author
Forward
0 new messages