当前位置: 首页>>代码示例>>Python>>正文


Python EPosixClientSocket.cancelMktData方法代码示例

本文整理汇总了Python中swigibpy.EPosixClientSocket.cancelMktData方法的典型用法代码示例。如果您正苦于以下问题:Python EPosixClientSocket.cancelMktData方法的具体用法?Python EPosixClientSocket.cancelMktData怎么用?Python EPosixClientSocket.cancelMktData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在swigibpy.EPosixClientSocket的用法示例。


在下文中一共展示了EPosixClientSocket.cancelMktData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: IBBroker

# 需要导入模块: from swigibpy import EPosixClientSocket [as 别名]
# 或者: from swigibpy.EPosixClientSocket import cancelMktData [as 别名]

#.........这里部分代码省略.........
        order.orderType = 'LMT'
        order.tif = 'DAY'
        order.outsideRth = False
        order.lmtPrice = lmtPrice
        return order

    # send the IB (contract, order) order to TWS
    def place_order(self, contract, order):
        oid = self.get_next_oid()
        self.tws.placeOrder(oid, contract, order)
        return oid
    
    # send order with Zipline style order arguments
    # <TODO> stop_price is not implemented
    def order(self, sid, amt, limit_price=None, stop_price=None):
        contract = self.get_contract_by_sid(sid)
        amt = int(amt)
        if limit_price is None:
            order = self.get_market_order(sid, amt)
        else:
            order = self.get_limit_order(sid, amt, limit_price)
        return self.place_order(contract, order)

    # subscribe to market data ticks
    def subscribe(self, sid):
        tid = self.get_next_tid()
        self.sid_to_tid[sid] = tid
        contract = self.get_contract_by_sid(sid)
        self.tws.reqMktData(tid, contract, '', False)
        return tid

    # subscribe to market data ticks for a list of tickers
    def subscribe_list(self, tickers):
        for tkr in tickers:
            self.subscribe(tkr)

    # cancel a market data subscription
    def unsubscribe(self, sid):
        if sid not in self.sid_to_tid.keys():
            return
        tid = self.sid_to_tid[sid]
        self.tws.cancelMktData(tid)

    # cancel all market data subscriptions
    def unsubscribe_all(self):
        sids = self.sid_to_tid.keys()
        for sid in sids:
            self.unsubscribe(sid)

    # fetch a quote by ticker id tid
    def get_quote_by_tid(self, tid):
        return self.wrapper.tid_to_price[tid]

    # fetch a quote by ticker sid
    def get_quote(self, sid):
        if sid not in self.sid_to_tid:
            self.subscribe(sid)
            return (None, None)
        tid = self.sid_to_tid[sid]
        if tid not in self.wrapper.tid_to_price:
            price = None
        else:
            price = self.wrapper.tid_to_price[tid]
        if tid not in self.wrapper.tid_to_size:
            size = None
        else:
            size = self.wrapper.tid_to_size[tid]
        return (price, size)

    # fetch a price by ticker sid
    def get_price(self, sid):
        if sid not in self.sid_to_tid:
            self.subscribe(sid)
            return None

        tid = self.sid_to_tid[sid]
        if tid not in self.wrapper.tid_to_price:
            return None
        else:
            price_dict = self.wrapper.tid_to_price[tid]
            if 'price' in price_dict:
                return price_dict['price']
        return None

    # get a Pandas DataFrame of current positions
    def get_positions_frame(self):
        ib_dict = {}
        for sid, position in self.wrapper.portfolio.sid_to_position.iteritems():
            # <TODO> don't use vars here
            #ib_dict[sid] = vars(position)
            ib_dict[sid] = {'marketValue': position.marketValue,
                            'realizedPNL': position.realizedPNL,
                            'marketPrice': position.marketPrice,
                            'unrealizedPNL': position.unrealizedPNL,
                            'accountName': position.accountName,
                            'averageCost': position.averageCost,
                            'sid': position.sid,
                            'position': position.position}
            
        return pd.DataFrame.from_dict(ib_dict, orient='index')
开发者ID:Coding4ufn,项目名称:abund.com,代码行数:104,代码来源:broker.py

示例2: timedelta

# 需要导入模块: from swigibpy import EPosixClientSocket [as 别名]
# 或者: from swigibpy.EPosixClientSocket import cancelMktData [as 别名]
#        "1 hour",                                    #barSizeSetting,
#        "BID_ASK",                                   #whatToShow,
#        0,                                          #useRTH,
#        1                                           #formatDate
#    )
#
#while (callback.close is None):
#    pass


#callback.accountEnd = False
#tws.reqAccountUpdates(1, '')
#while not callback.accountEnd:
#    pass

callback.askPrice = None
callback.lastPrice = None
callback.closePrice = None
callback.tickDataEnd = False
tws.reqMktData(2, contract, "", 0)

max_wait = timedelta(seconds=30) + datetime.now()
while callback.askPrice is None:
    time.sleep(0.0001)
    if datetime.now() > max_wait:
       print "max wait giving up"
       break
tws.cancelMktData(2)
print "Here's the ask price: ", callback.askPrice

开发者ID:ts468,项目名称:IBAlgoTrading,代码行数:31,代码来源:example2.py


注:本文中的swigibpy.EPosixClientSocket.cancelMktData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。