¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Marketdata Options Python


 

¿ªÔÆÌåÓý

?

Hello,

?

I simply want to get Marketdata for Options from the tws.

I tryed this code, but it always gives me the errorcode ?200¡° and says:

200

The contract description specified for VIAC is ambiguous.

?

Do you know what is wrong?

?

?

Thanks, Philipp

?

Code:

?

import ibapi

from ibapi.client import EClient

from ibapi.wrapper import EWrapper

#

from ibapi.contract import Contract

from ibapi.order import *

import threading

import time

?

#class for Interacite Vrokers Conneciton

class IBApi(EWrapper, EClient):

??? def __init__(self):

??????? EClient.__init__(self, self)

???? #Listen for Realtime Bars

??? def realtimeBar(self, reqID, time, open_, high, low, close, volume, wap, count):

??????? super().realtimeBar(self, reqID, time, open_, high, low, close, volume, wap, count)

??????? try:

??????????? bot.on_bar_update( reqID, time, open_, high, low, close, volume, wap, count)

??????? except Exception as e:

??????????? print(e)

??? def error(self, id, errorCode, errorMsg):

??????? print(errorCode)

??????? print(errorMsg)

???????

#Bot Logic

class Bot:

??? ib=None

??? def __init__(self):

??????? #connect to IB on init

??????? self.ib=IBApi()

??????? self.ib.connect("127.0.0.1", 7496,13)

??????? ib_thread=threading.Thread(target=self.run_loop, daemon=True)

??????? ib_thread.start()

??????? time.sleep(1)

??????? #get symbol info

??????? symbol=input("Enter the symbol you want to trade:")

??????? #create our IB Contract Object

??????? contract=Contract()

??????? contract.symbol=symbol.upper()

??????? contract.secType="OPT"

??????? contract.exchange="SMART"

??????? contract.currency="USD"

??????? contract.LastTradeDateOrContractMonth="20210618"

??????? contract.strike=38.5

??????? contract.right = "PUT"

??????? contract.multiplier="100"

??????? contract.tradingClass="VIAC"

??????? # Reqeust Market Data

??????? self.ib.reqRealTimeBars(0, contract,5, "TRADES", 1, [])

????

???????

????#listen to secket in sepreate thread

???????

????def run_loop(self):

??????? self.ib.run()

???

????#Pass realtime bar daata back to our obt object

??? def on_bar_update(self, reqID, time, open_, high, low, close, volume, wap, count):

??????? print(close)

???????

#Start Bot

bot=Bot()

?

?

Join [email protected] to automatically receive all group messages.