Skip to content

Instantly share code, notes, and snippets.

@Goldtean
Created June 18, 2017 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Goldtean/0f5bf70d5d2e2efb9a7061e39396c6be to your computer and use it in GitHub Desktop.
Save Goldtean/0f5bf70d5d2e2efb9a7061e39396c6be to your computer and use it in GitHub Desktop.
Request IB Data in Python
from ibapi.wrapper import EWrapper
from ibapi.client import EClient
from ibapi.utils import iswrapper
from ibapi.common import *
from ibapi.contract import *
from ibapi.ticktype import *
# Request IB Data in less than 50 lines of code
class BasicApp(EWrapper, EClient):
def __init__(self):
EClient.__init__(self,self)
def error(self, reqId: TickerId, errorCode:int, errorString:str):
print('Error:', reqId, " ", errorCode, " ", errorString)
@iswrapper
def tickPrice(self, reqId: TickerId, tickType: TickType, price: float, attrib: TickAttrib):
super().tickPrice(reqId, tickType, price, attrib)
print("Tick Price. Ticker Id:", reqId, "tickType:", tickType, "Price:", price, "CanAutoExecute:", attrib.canAutoExecute, "PastLimit", attrib.pastLimit)
@iswrapper
def tickSize(self, reqId: TickerId, tickType: TickType, size: int):
super().tickSize(reqId, tickType, size)
print("Tick Size. Ticker Id:", reqId, "tickType:", tickType, "Size:", size)
@iswrapper
def tickString(self, reqId: TickerId, tickType: TickType, value: str):
super().tickString(reqId, tickType, value)
print("Tick string. Ticker Id:", reqId, "Type:", tickType, "Value:", value)
@iswrapper
def tickGeneric(self, reqId: TickerId, tickType: TickType, value: float):
super().tickGeneric(reqId, tickType, value)
print("Tick Generic. Ticker Id:", reqId, "tickType:", tickType, "Value:", value)
def main():
app = BasicApp()
app.connect("127.0.0.1", 4001, 0)
contract = Contract();
contract.symbol = "VIX";
contract.secType = "FUT";
contract.exchange = "CFE";
contract.currency = "USD";
contract.lastTradeDateOrContractMonth = "20170621";
app.reqMktData(1001, contract, "", False, False, [])
app.run()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment