I want to have my objects that retrieve the price of a stock separate from the rest of the code so I can run the code, pull the data when asked, and compare the prices against each other. However, i cannot get my price variable to export out of the class. Effectively the idea is to pull data one tick at a time and then chart it againt another stock.
I am probably just missing something. Here is my code.
from ibapi.client import *
from ibapi.wrapper import *
import datetime
import time
import threading
From ibapi.ticktype import TickTypeEnum
port = 7497
class Stock_LQQ3(EClient, EWrapper):
def __init__(self):
EClient.__init__(self, self)
self.orderId = 1
def nextValidId(self, orderId: OrderId):
self.orderId = orderId
def nextId(self):
self.orderId += 1
return self.orderId
def tickPrice(self, reqId, tickType, price, attrib):
if price != -100.0:
price= float(price)
print(price)
else:
pass
app = Stock_LQQ3()
app.connect("127.0.0.1", port, 0)
threading.Thread(target=app.run).start()
time.sleep(1)
mycontract = Contract()
mycontract.symbol = "APPL"
mycontract.secType = "STK"
mycontract.exchange = "SMART"
mycontract.currency = "USD"
app.reqMarketDataType(3)
app.reqMktData(app.nextId(), mycontract, "232", False, False, [])e here
i have tried adding using return amonugst other things i just cant seem to get it todo what i want.