我正在使用 IB API 流式传输实时价格数据,我想将其放入数据框中进行分析。我的数据包括一个没有时间戳的实时流媒体价格。
我想我需要使用自动添加的行号创建新行,并将价格插入价格列。
我尝试定义数据框并告诉价格去向如下:
def tick_df(self, reqId,
contract): # this stores price dataframe by creating an empty dataframe and setting the index to the time column
self.bardata[reqId] = pd.DataFrame(columns=['index', 'price'])
self.reqMktData(reqId, contract, "", False, False, [])
self.bardata[reqId].index = [x for x in range(1, len(self.bardata[reqId].values) + 1)]
return self.bardata[reqId]
def tickPrice(self, reqId, tickType, price, attrib): # this function prints the price
if tickType == 2 and reqId == 102:
self.bardata[reqId].loc[self.bardata[reqId].index] = price
我一直在使用类似于这里的方法(https://github.com/PythonForForex/Interactive-brokers-python-api-guide/blob/master/GOOG_five_percent.py)。但是,由于我只是在流式传输价格,因此我无法使用时间戳来创建新行。