def create_order(self, account, orderType, totalQuantity, action): order = Order() order.m_account = account order.m_orderType = orderType order.m_totalQuantity = totalQuantity order.m_action = action return order
def create_order(self, order_type, quantity, action): """ Create an Order object (Market/Limit) to go Long/Short. This methos creates that second component of the pair, namely the Order instance. Parameters ---------- order_type : 'str' 'MKT', 'LMT' for Market or Limit orders. quantity : 'int' Integral number of assets to order. action : 'str' 'BUY' or 'SELL'. Returns ------- 'Order' Returns an IbPy Order instance. """ order = Order() order.m_orderType = order_type order.m_totalQuantity = quantity order.m_action = action return order
def mkOrder(id,shares, limit=None, account='',transmit=0, tif = 'DAY'): ''' create order object Parameters ----------- orderId : The order Id. You must specify a unique value. When the order status returns, it will be identified by this tag. This tag is also used when canceling the order. shares: number of shares to buy or sell. Negative for sell order. limit : price limit, None for MKT order transmit: transmit immideatelly from tws ''' action = {-1:'SELL',1:'BUY'} o = Order() o.m_orderId = id o.m_account=account o.m_action = action[cmp(shares,0)] o.m_totalQuantity = abs(shares) o.m_transmit = transmit if limit is not None: o.m_orderType = 'LMT' o.m_lmtPrice = limit else: o.m_orderType = 'MKT' return o
def create_order(order_type, quantity, action): order = Order() order.m_orderType = order_type order.m_totalQuantity = quantity order.m_action = action return order
def create_order(self, order_type, quantity, action): """ Create an Order Object to pair with the Contract Object """ order = Order() order.m_orderType = order_type # 'MKT'/'LMT' order.m_totalQuantity = quantity # Integer order.m_action = action # 'BUY'/'SELL' return order
def create_order(self, order_type, quantity, action): # creates an Order object (market or limit) to go long or short order = Order() order.m_orderType = order_type # 'MKT' or 'LMT' for market or limit order.m_totalQuantity = quantity # number of assets to order order.m_action = action # 'BUY' or 'SELL' return order
def create_order(self, order_type, quantity, action): """ Create an order object (market/limit) to go long/short. """ order = Order() order.m_orderType = order_type order.m_totalQuantity = quantity order.m_action = action return order
def create_stock_order(self, quantity, is_buy, is_market_order=True): order = Order() order.m_totalQuantity = quantity order.m_orderType = \ DataType.ORDER_TYPE_MARKET if is_market_order else \ DataType.ORDER_TYPE_LIMIT order.m_action = \ DataType.ORDER_ACTION_BUY if is_buy else \ DataType.ORDER_ACTION_SELL return order
def create_stock_order(self, quantity, is_buy, is_market_order=False): order = Order() order.m_totalQuantity = quantity order.m_orderType = \ DataType.ORDER_TYPE_MARKET if is_market_order else \ DataType.ORDER_TYPE_LIMIT order.m_action = \ DataType.ORDER_ACTION_BUY if is_buy else \ DataType.ORDER_ACTION_SELL return order
def create_order(self, order_type, quantity, action): """Create an Order object (Market/Limit) to go long/short. order_type - 'MKT', 'LMT' for Market or Limit orders quantity - Integral number of assets to order action - 'BUY' or 'SELL'""" order = Order() order.m_orderType = order_type order.m_totalQuantity = quantity order.m_action = action return order
def create_order(self, action, quantity): """Create an Interactive Brokers order object. This specifies whether or not we are selling or buying the asset, the quantity to exchange, and the order type of the trade (which is assumed to be a market order). """ o = Order() o.m_orderType = "MKT" o.m_totalQuantity = quantity o.m_action = action return o
def placeOrder(self, symbol, shares, limit=None, account='U8830832', exchange='SMART', transmit=0): ''' place an order on already subscribed contract ''' if symbol not in self.contracts.keys(): self.log.error("Can't place order, not subscribed to %s" % symbol) return action = {-1: 'SELL', 1: 'BUY'} o = Order() o.m_orderId = self.getOrderId() o.m_action = action[cmp(shares, 0)] o.m_totalQuantity = abs(shares) o.m_account = account o.m_transmit = transmit if limit is not None: o.m_orderType = 'LMT' o.m_lmtPrice = limit self.log.debug('Placing %s order for %i %s (id=%i)' % (o.m_action, o.m_totalQuantity, symbol, o.m_orderId)) self.tws.placeOrder(o.m_orderId, self.contracts[symbol], o)
def createOrder(orderId, shares, limit=None, transmit=0): """ create order object Parameters ----------- orderId : The order Id. You must specify a unique value. When the order status returns, it will be identified by this tag. This tag is also used when canceling the order. shares: number of shares to buy or sell. Negative for sell order. limit : price limit, None for MKT order transmit: transmit immideatelly from tws """ action = {-1: "SELL", 1: "BUY"} o = Order() o.m_orderId = orderId o.m_action = action[sign(shares)] o.m_totalQuantity = abs(shares) o.m_transmit = transmit if limit is not None: o.m_orderType = "LMT" o.m_lmtPrice = limit else: o.m_orderType = "MKT" return o
def close(orderty = "MKT", price = None, timeout = None): position = self["position"] order = Order() if position > 0: order.m_action = "SELL" else: order.m_action = "BUY" order.m_tif = "DAY" order.m_orderType = orderty order.m_totalQuantity = abs(position) order.m_openClose = "C" if price <> None: order.m_lmtPrice = price if price == None and orderty <> "MKT": order.m_lmtPrice = self.best_price(position) if timeout == None: oid = self.con.placeOrder(self.contract, order, None) self.oids.append(oid) return oid else: oid = self.con.placeOrder(self.contract, order, timedelta(seconds=timeout)) if oid == None: return None else: self.oids.append(oid) return oid
def create_order(order_type, quantity, action): "Create an Order Object (Market/Limit) to go long/short" "order type- 'MKT', 'LMT', etc - MIT, LIT, TLT, all order types we have learned " "quantity- how many you want to buy or sell, remember than options are 1 (for each 100 shares of stocks/ multiply price by 100 of the option)" order = Order() order.m_orderType = order_type order.m_totalQuantity = quantity order.m_action = action return order
def makeOrder(action, qty, price): newOrder = Order() newOrder.m_action = action newOrder.m_totalQuantity = qty newOrder.m_orderType = 'LMT' newOrder.m_lmtPrice = price newOrder.m_tif = '' newOrder.m_parentId = 0 newOrder.m_discretionaryAmt = 0 newOrder.m_transmit = True return newOrder
def test_handle_exec_details(self): # Create an order and send it contract = create_ib_futures_contract('GC', exp_month=5, exp_year=2016) order = create_order('MKT', 1, limit_price=None) order = Order() order.m_action = 'BUY' order.m_totalQuantity = 1 order.m_orderType = 'MKT' self.ib_connection.place_order(contract, order) time.sleep(3)
def create_order(self, order_type, quantity, action): ''' Create an Order object (Market/Limit) to go long/short. order_type - 'MKT', 'LMT' for market or limit orders quantity - integer number of units to order action - 'BUY' or 'SELL' ''' order = Order() order.m_orderType = order_type order.m_totalQuantity = quantity order.m_action = action return order
def create_order(self, order_type, quantity, action): ''' Create an Order object (Market/Limit) to go Long/Short :param order_type: 'MKT', 'LMT' for Market or Limit orders :param quantity: integer, number of assets to order :param action: 'BUY' or 'SELL' ''' order = Order() order.m_orderType = order_type order.m_totalQuantity = quantity order.m_action = action return order
def create_order(data): if isinstance(data, dict): try: order = Order() order.m_orderType = data['type'] order.m_totalQuantity = data['quantity'] order.m_action = data['action'] return order except: raise ValueError else: raise TypeError
def create_order(order_type, quantity, action): """ :param order_type: type of the order e.g. Market or Limit order. Also see OrderType.java :param quantity: quantity required :param action: buy or sell. See Types.java :return: order """ order = Order() order.m_orderType = order_type order.m_totalQuantity = quantity order.m_action = action return order
def create_order(self, order_type, quantity, action): """ Crea un oggetto Ordine (Market/Limit) per andare long/short. order_type - "MKT", "LMT" per ordini a mercato o limite quantity - Numero intero di asset dell'ordine action - 'BUY' o 'SELL' """ order = Order() order.m_orderType = order_type order.m_totalQuantity = quantity order.m_action = action return order
def combo_order_amount(self, contract, amount, style=MarketOrder()): ''' Place an order :param contract: A security object. :param amount: The integer amount of shares. Positive means buy, negative means sell. :param style: :return: ''' if not self.connected: raise RuntimeError('IB client is not connected to TWS') if amount == 0: return -1 elif amount > 0: action = 'BUY' else: action = 'SELL' if isinstance(contract, Contract): if len(contract.m_comboLegs) == 0: raise TypeError("contract must contains combo legs") else: raise TypeError("contract must be a contract object") # request next valid order ID from IB host; this request will update self.order_id self.connection.reqIds(-1) # note: input param is always ignored; sleep(0.05) order = Order() order.m_orderId = self.order_id order.m_client_id = self.client_id order.m_action = action order.m_totalQuantity = abs(amount) order.m_orderType = style.order_type if style.limit_price is not None: order.m_lmtPrice = style.limit_price if style.stop_price is not None: order.m_auxPrice = style.stop_price order.m_overridePercentageConstraints = True # override TWS order size constraints ''' # Advanced configuration. Not tested yet. if style.is_combo_order: if style.non_guaranteed: tag = TagValue() tag.m_tag = "NonGuaranteed" tag.m_value = "1" order.m_smartComboRoutingParams = [tag] ''' self.connection.placeOrder(self.order_id, contract, order) return self.order_id
def make_order(qty, limit_price, action): order = Order() order.m_minQty = qty order.m_lmtPrice = limit_price order.m_orderType = 'LMT' order.m_totalQuantity = qty order.m_action = action order.m_tif = 'GTC' order.m_outsideRth = True return order
def placeOrder(self,symbol,shares,limit=None,account='U8830832',exchange='SMART', transmit=0): ''' place an order on already subscribed contract ''' if symbol not in self.contracts.keys(): self.log.error("Can't place order, not subscribed to %s" % symbol) return action = {-1:'SELL',1:'BUY'} o= Order() o.m_orderId = self.getOrderId() o.m_action = action[cmp(shares,0)] o.m_totalQuantity = abs(shares) o.m_account = account o.m_transmit = transmit if limit is not None: o.m_orderType = 'LMT' o.m_lmtPrice = limit self.log.debug('Placing %s order for %i %s (id=%i)' % (o.m_action,o.m_totalQuantity,symbol,o.m_orderId)) self.tws.placeOrder(o.m_orderId,self.contracts[symbol],o)
def create_order(self, order_type, quantity, action): """ Create an Order object (Market/Limit) to go long/short :param order_type: 'MKT', 'LMT' for market or limit order :param quantity: Integral numbers of assets to order :param action: 'BUY' or 'SELL' :return: order object """ order = Order() order.m_orderType = order_type order.m_totalQuantity = quantity order.m_action = action return order
def sendOrder(self, orderReq): """发单""" # 增加报单号1,最后再次进行查询 # 这里双重设计的目的是为了防止某些情况下,连续发单时,nextOrderId的回调推送速度慢导致没有更新 self.orderId += 1 # 创建合约对象 contract = Contract() contract.m_symbol = str(orderReq.symbol) contract.m_exchange = exchangeMap.get(orderReq.exchange, '') contract.m_secType = productClassMap.get(orderReq.productClass, '') contract.m_currency = currencyMap.get(orderReq.currency, '') contract.m_expiry = orderReq.expiry contract.m_strike = orderReq.strikePrice contract.m_right = optionTypeMap.get(orderReq.optionType, '') # 创建委托对象 order = Order() order.m_orderId = self.orderId order.m_clientId = self.clientId order.m_action = directionMap.get(orderReq.direction, '') order.m_lmtPrice = orderReq.price order.m_totalQuantity = orderReq.volume order.m_orderType = priceTypeMap.get(orderReq.priceType, '') # 发送委托 self.connection.placeOrder(self.orderId, contract, order) # 查询下一个有效编号 self.connection.reqIds(1)
def create_order(order_type, quantity, limit_price=None): """ Creates an (ib.ext.Order) object to send to IB :param order_type: (string) "MARKET" or "LIMIT" :param quantity: (int) :return: (ib.ext.Order) """ order = Order() if order_type is "MARKET": order.m_orderType = "MKT" elif order_type is "LIMIT": order.m_orderType = "LMT" order.m_lmtPrice = limit_price assert (order.m_orderType is not None), "Invalid order_type!" if quantity == 0: raise Exception('Order quantity is 0!') elif quantity > 0: order.m_action = "BUY" elif quantity < 0: order.m_action = "SELL" assert (order.m_action is not None), "Invalid order action!" order.m_totalQuantity = abs(quantity) assert (abs(order.m_totalQuantity) > 0), "Invalid order quantity!" return order
def placeOrder(self, symbol, shares, limit=None, exchange="SMART", transmit=0): """place an order on already subscribed contract""" if symbol not in list(self.contracts.keys()): self.log.error("Can't place order, not subscribed to %s" % symbol) return action = {-1: "SELL", 1: "BUY"} o = Order() o.m_orderId = self.getOrderId() o.m_action = action[cmp(shares, 0)] o.m_totalQuantity = abs(shares) o.m_transmit = transmit if limit is not None: o.m_orderType = "LMT" o.m_lmtPrice = limit self.log.debug( "Placing %s order for %i %s (id=%i)" % (o.m_action, o.m_totalQuantity, symbol, o.m_orderId) ) self.tws.placeOrder(o.m_orderId, self.contracts[symbol], o)
def make_order(orderId, quantity, action, fa_profile, transmit=0): ''' create order object Parameters ----------- orderId : The order Id. You must specify a unique value. When the order status returns, it will be identified by this tag. This tag is also used when canceling the order. quantity: number of shares to buy or sell. Negative for sell order. action: buy or sell fa_profile: the name of the allocation profile transmit: transmit immideatelly from tws ''' logger.info('Placing order with id %s' % orderId) order_info = ['TRADELINE', action, quantity, fa_profile] logger.info(' | '.join(order_info)) o = Order() o.m_orderId = orderId o.m_action = action o.m_totalQuantity = quantity o.m_transmit = transmit o.m_orderType = 'MKT' o.m_faProfile = fa_profile return o
def createOrder(orderId, shares, limit=None, transmit=0): """ create order object Parameters ----------- orderId : The order Id. You must specify a unique value. When the order status returns, it will be identified by this tag. This tag is also used when canceling the order. shares: number of shares to buy or sell. Negative for sell order. limit : price limit, None for MKT order transmit: transmit immideatelly from tws """ action = {-1: "SELL", 1: "BUY"} o = Order() o.m_orderId = orderId o.m_action = action[cmp(shares, 0)] o.m_totalQuantity = abs(shares) o.m_transmit = transmit if limit is not None: o.m_orderType = "LMT" o.m_lmtPrice = limit else: o.m_orderType = "MKT" return o
def create_order(order_type, quantity, action, limitprice, transmitf, auxprice, stopprice, rptype): order = Order() order.m_action = action order.m_totalQuantity = quantity order.m_transmit = transmitf order.m_orderType = order_type if order_type == 'LMT': order.m_lmtPrice = limitprice pass elif order_type == 'STP': order.m_stpPrice = stopprice pass else: print 'failing on price...need one' return order ##################### ##if ordernumx == 'filled': ## launch profittake and stopbracket with ocaGroup ##reqIds() ##orderStatus() ##ParentID ##ocaType ##ocaGroup ############################### ##datahandler for snapshots ##reqmktdata live data ##req live recent bars ##PlaceOrder(entryorder) ##if entryorder filled: ## PlaceOrder(profitorder) ## get orderid ## PlaceOrder(profitorder by number, transmit) ## PlaceOrder(stopbracket) # with transmit true '''
def order(position = "BUY", orderty = "MKT", quantity = 100, price = None, timeout = None, openClose = "O"): order = Order() order.m_action = position order.m_tif = "DAY" order.m_orderType = orderty order.m_totalQuantity = quantity order.m_openClose = openClose if price <> None: order.m_lmtPrice = price if position == "BUY": pos = quantity else: pos = -quantity if price == None and orderty <> "MKT": order.m_lmtPrice = self.best_price(pos) if timeout == None: oid = self.con.placeOrder(self.contract, order, None) self.oids.append(oid) return oid else: oid = self.con.placeOrder(self.contract, order, timedelta(seconds=timeout)) if oid == None: return None else: self.oids.append(oid) return oid
def make_order(action, quantity, price=None): if price is not None: order = Order() order.m_orderType = 'LMT' order.m_totalQuantity = quantity order.m_action = action order.m_lmtPrice else: order = Order() order.m_orderType = 'LMT' order.m_totalQuantity = quantity order.m_action = action return order
def make_order(o_Id, c_Id, action, qty, Price=None): order = Order() order.m_orderId = o_Id order.m_clientId = c_Id order.m_action = action order.m_totalQuantity = qty if Price == None: order.m_orderType = "MKT" else: order.m_orderType = "LMT" order.m_lmtPrice = float(Price) return order
def make_order(self, **kwargs): """ This method helps to build an order object * m_orderId = The id for the order m_clientId the id of the client m_permid unique TWS id for orders, remains the same as long as TWS is connected ----- * m_action: BUY, SELL m_auxPrice: * m_lmtPrice: Limit price for limit orders * m_orderType: order types that are supported, STP STP LMT, LMT, MKT, ... * m_totalQuantity: order quantity ------ * m_ocaGroup: The OneCancelsAll group * m_ocaType: 1 = calcel all remaining orders m_outsideRth: true, false - trading outside regular tradinhg hours * m_tif : DAY, GTC, IOC, GTD. time in force * The necessary fields """ order = Order() for name, value in kwargs.items(): if not isinstance(name, basestring) or not isinstance( value, basestring): raise ( 'Contract keywords are not set right! They should both be strings.' ) setattr(order, 'm_' + name, value) return order
def create_order(self, order_type, quantity, action): """ Creates the second component of the pair, the Order object (Market/Limit) to go long/short. Parameters order_type - 'MKT' or 'LMT' for Market or Limit orders respectively quantity - An integral number of assets to order action - 'BUY' or 'SELL' """ order = Order() order.m_orderType = order_type order.m_totalQuantity = quantity order.m_action = action return order
def make_order(action, quantity, price = None): if price is not None: order = Order() order.m_orderType = 'LMT' order.m_totalQuantity = quantity order.m_action = action order.m_lmtPrice = price else: order = Order() order.m_orderType = 'MKT' order.m_totalQuantity = quantity order.m_action = action return order
def create_order(self, order_type, quantity, action): """ Create an Order object (Market/Limit) to go long/short. Parameters: order_type = "MKT", "LMT" for Market or Limit orders quantity - Integral number of assets to order action - "BUY" or "SELL" Note: This method generates the second component of the Contract/Order pair. It expects an order type (e.g., market or limit), a quantity to trade and an "action" (buy or sell). """ order = Order() order.m_orderType = order_type order.m_totalQuantity = quantity order.m_action = action return order
def makeOrder(self, **kwds): order = Order() attrs = [k for k in dir(order) if k.startswith('m_')] for attr in attrs: kwd = attr[2:] if kwd in kwds: setattr(order, attr, kwds[kwd]) return order
def create_order(order_type, quantity, action, limitprice, transmitf, auxprice, stopprice, rptype): order = Order() order.m_action = action order.m_totalQuantity = quantity order.m_transmit = transmitf order.m_orderType = order_type if order_type == 'LMT': order.m_lmtPrice = limitprice pass elif order_type == 'STP': order.m_stpPrice = stopprice pass else: print'failing on price...need one' return order ##################### ##if ordernumx == 'filled': ## launch profittake and stopbracket with ocaGroup ##reqIds() ##orderStatus() ##ParentID ##ocaType ##ocaGroup ############################### ##datahandler for snapshots ##reqmktdata live data ##req live recent bars ##PlaceOrder(entryorder) ##if entryorder filled: ## PlaceOrder(profitorder) ## get orderid ## PlaceOrder(profitorder by number, transmit) ## PlaceOrder(stopbracket) # with transmit true '''
def create_order(order_type, quantity, limit_price=None): """ Creates an (ib.ext.Order) object to send to IB :param order_type: (string) "MARKET" or "LIMIT" :param quantity: (int) :return: (ib.ext.Order) """ order = Order() if order_type is "MARKET": order.m_orderType = "MKT" elif order_type is "LIMIT": order.m_orderType = "LMT" order.m_lmtPrice = limit_price assert(order.m_orderType is not None), "Invalid order_type!" if quantity == 0: raise Exception('Order quantity is 0!') elif quantity > 0: order.m_action = "BUY" elif quantity < 0: order.m_action = "SELL" assert(order.m_action is not None), "Invalid order action!" order.m_totalQuantity = abs(quantity) assert(abs(order.m_totalQuantity) > 0), "Invalid order quantity!" return order
def addOrder( self, symbol, lmtPrice=0, minQty=100, action="BUY", orderType="LMT", tif="DAY", outsideRTH=False, totalQuantity=False, ): """Generate and store an order for the given symbol""" validAction = ["BUY", "SELL", "SSHORT"] if action not in validAction: raise Exception( "{0} is not a valid order action. " + "Valid actions are: {1}.".format(action, ", ".join(validAction)) ) validType = [ "LMT", "MKT", "MKTCLS", "LMTCLS", "PEGMKT", "SCALE", "STP", "STPLMT", "TRAIL", "REL", "VWAP", "TRAILLIMIT", ] if orderType not in validType: raise Exception( "{0} is not a valid order type. " + "Valid types are: {1}.".format(orderType, ", ".join(validType)) ) validTIF = ["DAY", "GTC", "IOC", "GTD"] if tif not in validTIF: raise Exception("{0} is not a valid TIF." + "Valid TIFs are: {1}.".format(tif, ", ".join(validTIF))) o = Order() o.m_minQty = minQty o.m_totalQuantity = totalQuantity if totalQuantity else minQty o.m_lmtPrice = lmtPrice o.m_action = action o.m_tif = tif o.m_orderType = orderType o.m_outsideRth = outsideRTH self._orders[symbol] = self._next_valid_id, o self._next_valid_id += 1 return self._next_valid_id - 1
def create_bracket_order(order_type, quantity, action, limitprice, transmitf, auxprice, stopprice, rptype, parentid): order = Order() order.m_orderType = order_type ## STP,LIM order.m_totalQuantity = quantity order.m_action = action order.m_lmtPrice = limitprice order.m_transmit = transmitf order.m_faGroup = 'rpacct' order.m_parentId = parentid ## order.m_faProfile = 'allocateALL' order.m_faMethod = 'AvailableEquity' if order_type == 'LMT': pass ## order.m_lmtPrice = limitprice elif order_type == 'STP': order.m_auxPrice = stopprice else: print'failing on price in ibutiles..bad order type...need one' return order
def create_order(self,order_type,price,qty,action): order = Order() ''' main fields: m_orderId = 0 m_clientId = 0 m_permId = 0 m_action = "" m_totalQuantity = 0 m_orderType = "" m_lmtPrice = float() m_auxPrice = float() ''' order.m_lmtPrice = price order.m_orderType = order_type order.m_totalQuantity = qty order.m_action = action # more functionalities.... return order
def create_stock_order(order_id, quantity, is_buy, price=None, stop_price=None): order = Order() order.m_outsideRth = True order.m_orderId = order_id order.m_totalQuantity = quantity order.m_action = DataType.ORDER_ACTION_BUY if is_buy else DataType.ORDER_ACTION_SELL if price is None: order.m_orderType = DataType.ORDER_TYPE_MARKET else: order.m_lmtPrice = price order.m_orderType = DataType.ORDER_TYPE_LIMIT if stop_price is not None: order.m_auxPrice = stop_price order.m_orderType = DataType.ORDER_TYPE_STOP_LIMIT return order
def addlmtorder(self, action, qty, oc, price, cid, tif = "DAY", date = ""): o = Order() o.m_action = action #print tif o.m_tif = tif o.m_orderType = 'LMT' o.m_totalQuantity = qty o.m_openClose = oc o.m_lmtPrice = float(round(price,2)) o.m_goodTillDate = date res = self.placeOrder(cid, o) return(res)
def makeFutOrder(type, action, orderId=-99, price=None): order = Order() order.m_orderId = orderId order.m_clientId = 0 order.m_permid = 0 order.m_orderType = type order.m_action = action order.m_minQty = 1 order.m_totalQuantity = 1 # order.m_transmit = False if type == 'LMT': order.m_lmtPrice = price if action == 'SELL': pass return order
def newOrder_GUI(action, orderID, quantity,startTime): global trade_params newStkOrder = Order() print orderID, action, trade_params['OrderTIF'],trade_params['OrderType'],quantity,trade_params['Account'],startTime newStkOrder.m_orderId = orderID newStkOrder.m_action = action newStkOrder.m_tif = 'DAY' newStkOrder.m_transmit = True newStkOrder.m_orderType = 'MKT' newStkOrder.m_totalQuantity = quantity newStkOrder.m_account = 'DU164541' newStkOrder.m_goodAfterTime = startTime #newStkOrder.m_goodAfterTime=endTime return newStkOrder
def makeStkOrder(shares,action,account,ordertype='MKT'): order = Order() order.m_minQty = shares order.m_orderType = ordertype order.m_totalQuantity = shares order.m_action = str(action).upper() order.m_outsideRth = True #allow order to be filled ourside regular trading hours order.m_account = account return order
def addlmtorder(cid, action, price, qty): id = len(orders) o = Order() o.m_orderId = id o.m_action = action o.m_orderType = 'LMT' o.m_tif = 'DAY' o.m_totalQuantity = qty o.m_clientId = 0 o.m_permId = 0 o.m_lmtPrice = float(round(price,2)) #o.m_auxPrice = float(price) orders.append([o, cid, qty, id]) con.placeOrder(id, contracts[cid], o) position(cid) pending(cid)
def make_order(limit_price): order = Order() order.m_minQty = 100 order.m_lmtPrice = limit_price order.m_orderType = 'MKT' order.m_totalQuantity = 100 order.m_action = 'BUY' return order
def _create_order(action, qty, order_type, limit_price, stop_price): order = Order() order.m_action = action order.m_totalQuantity = qty order.m_auxPrice = stop_price order.m_lmtPrice = limit_price order.m_orderType = order_type return order
def place_order(self, instrument, expiry, quantity, acc=None): """ Send API request to place an order on the exchange. :param instrument: core.instrument.Instrument object :param expiry: contract label :param quantity: order size as a signed integer (quantity > 0 means 'BUY' and quantity < 0 means 'SELL') :param acc: IB account to place order from, if None - the default account will be used """ contract = Contract() contract.m_symbol = instrument.ib_code contract.m_secType = 'FUT' # place_order expects the contract label here, not the actual expiration date contract.m_expiry = expiry contract.m_exchange = instrument.exchange contract.m_currency = instrument.denomination if hasattr(instrument, 'ib_trading_class'): contract.m_tradingClass = instrument.ib_trading_class if hasattr(instrument, 'ib_multiplier'): contract.m_multiplier = instrument.ib_multiplier order = Order() order.m_orderType = 'MKT' order.m_algoStrategy = 'Adaptive' order.m_algoParams = [TagValue('adaptivePriority', 'Patient')] order.m_totalQuantity = int(abs(quantity)) order.m_action = quantity > 0 and 'BUY' or 'SELL' if acc is not None: order.m_account = acc.name self.last_account = acc logger.warning( ' '.join(['Order:', str(self.order_id), contract.m_symbol, contract.m_expiry, \ order.m_action, str(order.m_totalQuantity)])) self.connection.placeOrder(self.order_id, contract, order) self.orders_cache[self.order_id] = {'contract': contract, 'order': order} # order_id may not update just after the order is submitted so we save the previous one and # keep requesting until it's updated or we hit the time/iterations limit prev_id = self.order_id i = 0 while prev_id >= self.order_id: sleep(self.api_delay) i += 1 logger.debug('Requesting next order_id..') self.connection.reqIds(1) self.next_id_event.wait(timeout=(self.api_delay * 30)) self.next_id_event.clear() if i > 60: logger.warning("Couldn't obtain next valid order id. Next orders may not be" "submitted correctly!") return