Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IBapi Python-从reqHistoricalData获取最后一个价格作为变量?_Python_Algorithmic Trading_Interactive Brokers_Ibpy_Ib Api - Fatal编程技术网

IBapi Python-从reqHistoricalData获取最后一个价格作为变量?

IBapi Python-从reqHistoricalData获取最后一个价格作为变量?,python,algorithmic-trading,interactive-brokers,ibpy,ib-api,Python,Algorithmic Trading,Interactive Brokers,Ibpy,Ib Api,我试图从HistoricalData回调中获取价格,以便在算法的其他部分中使用。这是我的代码: def historicalData(self, reqId, bar): print("HISTORICAL DATA REQUEST: {}, reqId: {}".format(contract.symbol, reqId)) print("***************************************************

我试图从HistoricalData回调中获取价格,以便在算法的其他部分中使用。这是我的代码:

    def historicalData(self, reqId, bar):
    print("HISTORICAL DATA REQUEST: {}, reqId: {}".format(contract.symbol, reqId))
    print("****************************************************")
    print("Date:", bar.date, "Open:", bar.open, "High:", bar.high, "Low:", bar.low,
          "Close:", bar.close, "Volume:", bar.volume, "Count:", bar.barCount, "WAP:", bar.average, "\n")
    self.close = bar.close

app = IBapi()
app.connect('127.0.0.1', 7497, 123)

api_thread = threading.Thread(target=run_loop, daemon=True)
api_thread.start()

app.reqHistoricalData(1, con, "", "1 D", "1 day", "MIDPOINT", 1, 1, False, [])
print(app.close)
我希望价格作为一个变量,我可以使用它为我的主订单设置子限额/停止订单等

根据历史数据要求,输出良好

Date: 20210507 Open: 0.868075 High: 0.87009 Low: 0.86654 Close: 0.86875 Volume: 
-1 Count: -1 WAP: -1.0
但是,当我试图打印变量本身时,就不行了

AttributeError: 'IBapi' object has no attribute 'close'
有人能告诉我如何获取这个值并在代码的其余部分使用它吗?这个过程适用于其他事情,比如我是否需要账户中的资金或我的订单ID,但不是这个

谢谢