最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Interactive Brokers (IBAPI) exporting a varible out of classes - Stack Overflow

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论