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


Python EPosixClientSocket.reqMktData方法代码示例

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


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

示例1: testTWS

# 需要导入模块: from swigibpy import EPosixClientSocket [as 别名]
# 或者: from swigibpy.EPosixClientSocket import reqMktData [as 别名]
class testTWS(object):
    def __init__(self):
        self.callback = ArtemisIBWrapper()
	self.tws = EPosixClientSocket(self.callback)
	self.tws.eConnect("", 7496, 44, poll_interval=1)

    def run(self):
	# Simple contract for GOOG
	contract = Contract()
	#contract.conId = 114376112
	contract.exchange = "SMART"
	contract.symbol = "ATK"
	contract.secType = "STK"
	#contract.right = "PUT"
	contract.currency = "USD"
	#contract.secType = 'OPT'
	#contract.strike = 24
	#contract.expiry = '20121116'
	today = datetime.today()

	order = Order()
	order.orderId = 89
	order.clientId = 44
	order.action = "BUY"
	order.totalQuantity = 1  # may have to calculate a smarter number
	order.orderType = "MKT"
	order.tif = "DAY" 
	order.transmit = True
	order.sweepToFill = True
	order.outsideRth = True

	contract.symbol = "alkjdf"
	self.callback.askPrice = None
	self.tws.reqMktData(2, contract, "", 1)
	max_wait = timedelta(seconds=30) + datetime.now()
	while self.callback.askPrice is None:
	    if datetime.now() > max_wait:
		print "max wait giving up"
		break
	print self.callback.askPrice
开发者ID:ts468,项目名称:IBAlgoTrading,代码行数:42,代码来源:example3.py

示例2: IBBroker

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

#.........这里部分代码省略.........
    # get a default IB limit order
    def get_limit_order(self, sid, amt, lmtPrice):
        order = Order();
        order.action = self.order_action(amt)
        order.totalQuantity = abs(amt)
        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
开发者ID:Coding4ufn,项目名称:abund.com,代码行数:70,代码来源:broker.py

示例3: timedelta

# 需要导入模块: from swigibpy import EPosixClientSocket [as 别名]
# 或者: from swigibpy.EPosixClientSocket import reqMktData [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.reqMktData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。