Skip to content

Instantly share code, notes, and snippets.

@deependersingla
Created November 12, 2016 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deependersingla/40722a6192ef785d30791abc8e5470ba to your computer and use it in GitHub Desktop.
Save deependersingla/40722a6192ef785d30791abc8e5470ba to your computer and use it in GitHub Desktop.
from ib.opt import ibConnection, message
from ib.ext.Contract import Contract
from time import sleep, strftime
from ib.ext.TickType import TickType as tt
import pdb
def error_handler(msg):
print (msg)
def my_callback_handler(msg):
print(msg)
tws = ibConnection()
tws.register(my_callback_handler, message.historicalData)
tws.connect()
c = Contract()
c.m_symbol = "CANFINHOM"
c.m_secType = "STK"
c.m_exchange = "NSE"
c.m_currency = "INR"
endtime = strftime('%Y%m%d %H:%M:%S')
#for reference http://www.inside-r.org/packages/cran/IBrokers/docs/reqHistoricalData
tws.reqHistoricalData(tickerId=1,contract=c,endDateTime=endtime,
durationStr='1 D',
barSizeSetting='2 mins',
whatToShow='TRADES',
useRTH=0,
formatDate=1)
sleep(100)
print 'All done'
tws.disconnect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment