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
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
def createOrderBuy(self): order = Order() order.orderId = self.orderIdCount self.orderIdCount += 1 order.clientId = self.socketnum order.action = "BUY" order.orderType = "MKT" order.tif = "DAY" order.transmit = True order.sweepToFill = True order.outsideRth = True return order
def createOrderBuy(self): order = Order() order.orderId = self.orderIdCount self.orderIdCount += 1 order.clientId = self.socketnum order.action = "BUY" order.orderType = "MKT" order.tif = "DAY" order.transmit = True order.sweepToFill = True order.outsideRth = True return order
#tws.reqContractDetails(1, contract) #while not callback.contractDataEnd: # pass #for i in range(0, len(sorted(callback.Strikes))): # if sorted(callback.Strikes)[i] > askPrice: # callStrikePrice = sorted(callback.Strikes)[i-1] # callConId = callback.StrikesHash[callStrikePrice][0] # callMultiplier = callback.StrikesHash[callStrikePrice][1] # putStrikePrice = sorted(callback.Strikes)[i] # putConId = callback.StrikesHash[putStrikePrice][0] # putMultiplier = callback.StrikesHash[putStrikePrice][1] # break order = Order() order.orderId = 7 order.clientId = 46 order.action = "SELL" order.totalQuantity = 78 # may have to calculate a smarter number order.orderType = "MKT" order.tif = "DAY" order.transmit = True order.sweepToFill = False order.outsideRth = True callback.accountEnd = False portfolioList = [] callback.portfolioContract = None callback.portfolioPosition = None tws.reqAccountUpdates(1, accountNumber)