def __init__(self):
"""Initialize parameters of the Interactive Brokers price handler
object.
"""
super(InteractiveBrokersPriceHandler, self).__init__()
self.conn = ibConnection(
clientId=IB.data_handler_id.value, port=IB.port.value
)
self.conn.register(self.__tick_price_handler, message.tickPrice)
if not self.conn.connect():
raise ValueError(
"Odin was unable to connect to the Trader Workstation."
)
# Set the target field to download data from.
today = dt.datetime.today()
open_t, close_t = dt.time(9, 30), dt.time(16)
cur_t = today.time()
# If today is a weekday and the timing is correct, then we use the most
# recently observed price. Otherwise we use the close price.
if today.weekday() < 5 and cur_t >= open_t and cur_t <= close_t:
self.field = TickType.LAST
else:
self.field = TickType.CLOSE
# Initialize a pandas panel to store the price data.
self.bar = pd.Panel(items=[PriceFields.current_price.value])
interactive_brokers_price_handler.py 文件源码
python
阅读 28
收藏 0
点赞 0
评论 0
评论列表
文章目录