So you are a thinkorswim customer and you want real time data in a python environment? No problem.
First, install the xlwings module. Load up your python IDE of choice.
from xlwings import Workbook, Sheet, Range, Chart import time wb = Workbook()
You need to have thinkorswim open and running. A blank excel spreadsheet should open up after you execute the last command above.
def getQuote(ticker, type): Range('B1').value = '=RTD("tos.rtd", ,"%s", "%s")' % (type, ticker) time.sleep(2.5) return Range('B1').value
So we create a getQuote function above that takes in two variables, both strings. We utilize the Write value feature in python to input the DDE/RTD function into the Excel cell. After about a second, this will return a value where we can use the return feature to read it back.
Really, this is just a work-around. Unfortunately, I could not find a way to get RTD data working into the python environment directly. If anyone does, please feel free to drop a note in the comments.
So now we can call the getQuote function a ticker and input type of our choice:
getQuote("/ESU5", "LAST")
Out[447]: 2101.0
Pretty awesome! You can experiment with options as well:
def quoteOption(type, ticker, cp, exp, strike): Range('B1').value = '=RTD("tos.rtd", ,"%s", ".%s%s%s%s")' % (type, ticker, exp, cp, strike) time.sleep(2.5) #wait for excel to update the cell, usually a couple of seconds. return Range('B1').value
quoteOption('LAST', 'VXX', 'C', 150731, 17)Out[446]: 1.23
Cheers.
Yeah, I was wondering about a way of directly getting quotes as well. Real time is a funny word. A 2 second delay is huge in the world of finance these days...
ReplyDeleteI understand. I was referencing accessing the RTD (real time data) via excel, not necessarily implying that it was going to be received in real time. Indeed, a two second delay for traders operating on that time frame is a big deal. Then again, if you are trying to gather any sort of serious quantifiable data for trading tick to tick strategies - you are probably going to find this post irrelevant.
ReplyDeletethis is nice, was looking to get real time data to feed personal algos.
ReplyDeleteAnyway i think there is a package for this RTD thing. here is the link https://pypi.python.org/pypi/pyrtd
i have not try this one yet
Unfortunately xlwings is only available for MS and Apple operating systems.
ReplyDeleteThe Le_Meridian Funding Service went above and beyond their requirements to assist me with my loan which i used expand my pharmacy business,They were friendly, professional, and absolute gems to work with.I will recommend anyone looking for loan to contact. Email..lfdsloans@lemeridianfds.com Or lfdsloans@outlook.com.WhatsApp ... + 19893943740.
ReplyDelete