我想请求合同详细信息,它在我第一次运行代码时工作,但是当我再次按运行时,它不会返回任何内容。如果我退出 TWS 和 pycharm 并重试,它将起作用。我是 python 新手,不了解它的整体工作原理,请帮忙。
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.common import *
from ibapi.contract import *
from ContractSamples import ContractSamples
class TestApp(EClient, EWrapper):
def __init__(self):
EClient.__init__(self, self)
def error(self, reqId:TickerId, errorCode:int, errorString:str):
print("Error: ", reqId, "", errorCode, "", errorString)
def contractDetails(self, reqId:int, contractDetails:ContractDetails):
print("contractDetail: ", reqId, " ", contractDetails)
def main():
app = TestApp()
app.connect("127.0.0.1", 7496, 0)
contract = Contract()
contract.symbol = "AAPL"
contract.secType = "STK"
contract.exchange = "SMART"
contract.currency = "USD"
contract.primaryExchange = "NASDAQ"
app.reqContractDetails(10, contract)
app.run()
if __name__ == "__main__":
main()
没有错误消息,只是没有结果:“进程以退出代码 0 完成”。