folgendes Script hab ich erstellt:
Code: Alles auswählen
def exp(stock):
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.common import SetOfString
from ibapi.common import SetOfFloat
from ibapi.contract import Contract
from threading import Timer
from datetime import datetime
class TestApp(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
self.exp = []
self.conid = 0
def error(self, reqId, errorCode, errorString):
print("Error: ", reqId, " ", errorCode, " ", errorString)
def nextValidId(self, orderId):
self.start()
def contractDetails(self, reqId, contractDetails):
self.conid = contractDetails.underConId
print(contractDetails.underConId)
def securityDefinitionOptionParameter(self, reqId:int, exchange:str,
underlyingConId:int, tradingClass:str,
multiplier:str, expirations:SetOfString,
strikes:SetOfFloat):
if exchange == 'SMART':
s = list(expirations)
s.sort(key=lambda date: datetime.strptime(date, "%Y%m%d"))
self.exp = list(s)
def start(self):
# 265598 is the conId (contract ID) for AAPL Nasdaq stock
contract = Contract()
contract.symbol = stock
contract.secType = "OPT"
contract.exchange = "SMART"
contract.currency = "USD"
contract.strike = 150
contract.right = "C"
contract.multiplier = "100"
contract.lastTradeDateOrContractMonth = "20211119"
self.reqContractDetails(1, contract)
self.reqSecDefOptParams(1, stock, "", "STK", 265598)
#sollte so aussehen: self.reqSecDefOptParams(1, stock, "", "STK", conid)
def stop(self):
self.done = True
self.disconnect()
app = TestApp()
app.nextOrderId = 0
app.connect("127.0.0.1", 7496, 60)
Timer(1, app.stop).start()
app.run()
return app.exp
stock = 'AAPL'
x=exp(stock)
print(x)
Wie stelle ich es an, dass ich statt "265598" die Variable "conid" an "reqSecDefOptParams" übergeben kann?
Danke
Mirko