from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from threading import Timer
class TestApp(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
def error(self, reqId, errorCode, errorString):
print("Error: ", reqId, " ", errorCode, " ", errorString)
def nextValidId(self, orderId):
self.start()
def historicalData(self, reqId, bar):
# print("HistoricalData. ", reqId, " Date:", ...., bar.average)
return bar.high
def start(self):
contract = Contract()
contract.symbol = "TSLA"
contract.secType = "STK"
contract.exchange = "SMART"
contract.currency = "USD"
x = self.reqHistoricalData(1, contract, "", "60 s", "1 min", "MIDPOINT", 0, 1, False, [])
print(x)
def stop(self):
self.done = True
self.disconnect()
def main():
app = TestApp()
app.nextOrderId = 0
app.connect("127.0.0.1", 7497, 0)
Timer(4, app.stop).start()
app.run()
if __name__ == "__main__":
main()
在这种情况下,我如何能够返回 bar.high,而不是打印 HistoricalData?
它现在没有给我任何东西。
任何帮助表示赞赏。
我错过了什么?
非常感谢。