Here is my code that I am trying to run let :
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
import threading
class MyWrapper(EWrapper):
def __init__(self):
EWrapper.__init__(self)
def nextValidId(self, orderId):
print(f"Setting nextValidOrderId: {orderId}")
# Start program here or use threading
# app.reqContractDetails(4444, contract)
def contractDetails(self, reqId, contractDetails):
print(reqId, contractDetails.contract)
def contractDetailsEnd(self, reqId):
print(f"ContractDetailsEnd. {reqId}")
# This is the logical end of your program
def error(self, reqId, errorCode, errorString):
print(f"Error. Id: {reqId}, Code: {errorCode}, Msg: {errorString}")
def tickPrice(self, tickerid, tickType, price, attrib):
global i
i += 1
print(f"{i} Tick type: {tickType}, Price: {price}")
def tickSize(self, tickerid, tickType, size):
global i
i += 1
print(f"{i} Tick type: {tickType}, Size: {size}")
def tickString(self, tickerid, tickType, value):
global i
i += 1
print(f"{i} Tick type: {tickType}, Value: {value}")
def tickGeneric(self, tickerid, tickType, value):
global i
i += 1
print(f"{i} Tick type: {tickType}, Value: {value}")
wrapper = MyWrapper()
app = EClient(wrapper)
app.connect("127.0.0.1", 7497, clientId=1)
print(f"Server Version: {app.serverVersion()}, Connection Time: {app.twsConnectionTime()}")
contract = Contract()
contract.symbol = "EUR"
contract.secType = "CASH"
contract.currency = "USD"
contract.exchange = "IDEALPRO" # Use IDEALPRO for forex
app.reqMktData(1, contract, "", False, False, [])
print(app.isConnected())
i = 0 # Initialize i for tick counts
app.run()
I see this as the output in visual studio code when I run the above python program:
Server Version: 157, Connection Time: b'20231027 13:34:45 EST' True
How do I fixed this code so I can see live data printed? Thanks in advance. what do you think is the problem? Can anyone help me get live data from interactive brokers' ibapi