本文整理汇总了Python中ib.ext.Order.Order.m_tif方法的典型用法代码示例。如果您正苦于以下问题:Python Order.m_tif方法的具体用法?Python Order.m_tif怎么用?Python Order.m_tif使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ib.ext.Order.Order
的用法示例。
在下文中一共展示了Order.m_tif方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: close
# 需要导入模块: from ib.ext.Order import Order [as 别名]
# 或者: from ib.ext.Order.Order import m_tif [as 别名]
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
示例2: order
# 需要导入模块: from ib.ext.Order import Order [as 别名]
# 或者: from ib.ext.Order.Order import m_tif [as 别名]
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
示例3: make_order
# 需要导入模块: from ib.ext.Order import Order [as 别名]
# 或者: from ib.ext.Order.Order import m_tif [as 别名]
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
示例4: addmktorder
# 需要导入模块: from ib.ext.Order import Order [as 别名]
# 或者: from ib.ext.Order.Order import m_tif [as 别名]
def addmktorder(self, action, qty, oc, cid, tif = "DAY"):
o = Order()
o.m_action = action
print tif
o.m_tif = tif
o.m_orderType = 'MKT'
o.m_totalQuantity = qty
o.m_openClose = oc
res = self.placeOrder(cid, o)
return(res)
示例5: addOrder
# 需要导入模块: from ib.ext.Order import Order [as 别名]
# 或者: from ib.ext.Order.Order import m_tif [as 别名]
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
示例6: addlmtorder
# 需要导入模块: from ib.ext.Order import Order [as 别名]
# 或者: from ib.ext.Order.Order import m_tif [as 别名]
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)
示例7: makeOptOrder
# 需要导入模块: from ib.ext.Order import Order [as 别名]
# 或者: from ib.ext.Order.Order import m_tif [as 别名]
def makeOptOrder(action, orderID, tif, orderType):
newOptOrder = Order()
newOptOrder.m_orderId = orderID
newOptOrder.m_clientId = 0
newOptOrder.m_permid = 0
newOptOrder.m_action = action
newOptOrder.m_lmtPrice = 0
newOptOrder.m_auxPrice = 0
newOptOrder.m_tif = tif
newOptOrder.m_transmit = False
newOptOrder.m_orderType = orderType
newOptOrder.m_totalQuantity = 1
return newOptOrder
示例8: order
# 需要导入模块: from ib.ext.Order import Order [as 别名]
# 或者: from ib.ext.Order.Order import m_tif [as 别名]
def order(self, sid, amount, limit_price, stop_price, order_id=None):
id = super(LiveBlotter, self).order(sid, amount, limit_price, stop_price, order_id=None)
order_obj = self.orders[id]
ib_order = IBOrder()
ib_order.m_transmit = True
ib_order.m_orderRef = order_obj.id
ib_order.m_totalQuantity = order_obj.amount
ib_order.m_action = ["BUY" if ib_order.m_totalQuantity > 0 else "SELL"][0]
ib_order.m_tif = "DAY"
# Todo: make the FA params configurable
ib_order.m_faGroup = "ALL"
ib_order.m_faMethod = "AvailableEquity"
# infer order type
if order_obj.stop and not order_obj.limit:
ib_order.m_orderType = "STP"
ib_order.m_auxPrice = float(order_obj.stop)
elif order_obj.limit and not order_obj.stop:
ib_order.m_orderType = "LMT"
ib_order.m_lmtPrice = float(order_obj.limit)
elif order_obj.stop and order_obj.limit:
ib_order.m_orderType = "STPLMT"
ib_order.m_auxPrice = float(order_obj.stop)
ib_order.m_lmtPrice = float(order_obj.limit)
else:
ib_order.m_orderType = "MKT"
contract = Contract()
contract.m_symbol = order_obj.sid
contract.m_currency = "USD"
if hasattr(order_obj, "contract"):
# This is a futures contract
contract.m_secType = "FUT"
contract.m_exchange = "GLOBEX"
contract.m_expiry = order_obj.contract
else:
# This is a stock
contract.m_secType = "STK"
contract.m_exchange = "SMART"
ib_id = self.place_order(contract, ib_order)
self.id_map[order_obj.id] = ib_id
return order_obj.id
示例9: newOrder_GUI
# 需要导入模块: from ib.ext.Order import Order [as 别名]
# 或者: from ib.ext.Order.Order import m_tif [as 别名]
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
示例10: order
# 需要导入模块: from ib.ext.Order import Order [as 别名]
# 或者: from ib.ext.Order.Order import m_tif [as 别名]
def order(self, asset, amount, style):
contract = Contract()
contract.m_symbol = str(asset.symbol)
contract.m_currency = self.currency
contract.m_exchange = symbol_to_exchange[str(asset.symbol)]
contract.m_secType = symbol_to_sec_type[str(asset.symbol)]
order = Order()
order.m_totalQuantity = int(fabs(amount))
order.m_action = "BUY" if amount > 0 else "SELL"
is_buy = (amount > 0)
order.m_lmtPrice = style.get_limit_price(is_buy) or 0
order.m_auxPrice = style.get_stop_price(is_buy) or 0
if isinstance(style, MarketOrder):
order.m_orderType = "MKT"
elif isinstance(style, LimitOrder):
order.m_orderType = "LMT"
elif isinstance(style, StopOrder):
order.m_orderType = "STP"
elif isinstance(style, StopLimitOrder):
order.m_orderType = "STP LMT"
order.m_tif = "DAY"
order.m_orderRef = self._create_order_ref(order)
ib_order_id = self._tws.next_order_id
zp_order = self._get_or_create_zp_order(ib_order_id, order, contract)
log.info(
"Placing order-{order_id}: "
"{action} {qty} {symbol} with {order_type} order. "
"limit_price={limit_price} stop_price={stop_price} {tif}".format(
order_id=ib_order_id,
action=order.m_action,
qty=order.m_totalQuantity,
symbol=contract.m_symbol,
order_type=order.m_orderType,
limit_price=order.m_lmtPrice,
stop_price=order.m_auxPrice,
tif=order.m_tif
))
self._tws.placeOrder(ib_order_id, contract, order)
return zp_order
示例11: addmktorder
# 需要导入模块: from ib.ext.Order import Order [as 别名]
# 或者: from ib.ext.Order.Order import m_tif [as 别名]
def addmktorder(cid, action, qty):
id = len(orders)
o = Order()
o.m_orderId = id
o.m_clientId = 0
o.m_permid = 0
o.m_action = action
o.m_lmtPrice = 0
o.m_auxPrice = 0
o.m_tif = 'DAY'
o.m_orderType = 'MKT'
o.m_totalQuantity = qty
o.m_transmit = True
orders.append([o, cid, qty, id])
con.placeOrder(id, contracts[cid], o)
position(cid)
pending(cid)
示例12: addlmtorder
# 需要导入模块: from ib.ext.Order import Order [as 别名]
# 或者: from ib.ext.Order.Order import m_tif [as 别名]
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)
示例13: place_order
# 需要导入模块: from ib.ext.Order import Order [as 别名]
# 或者: from ib.ext.Order.Order import m_tif [as 别名]
def place_order(self, signal):
if signal['direction'] == 'short':
return # don't short sell for now
symbol = signal['symbol']
current_bbo = self.bbos[symbol].bbo
order = Order()
order.m_totalQuantity = 10
order.m_orderType = 'LMT'
order.m_tif = 'GTD'
#expiry_time = datetime.now(pytz.timezone('America/New_York'))
expiry_time = datetime.now()
expiry_time += timedelta(seconds=5)
order.m_goodTillDate = expiry_time.strftime('%Y%m%d %H:%M:%S')
if signal['direction'] == 'long':
order.m_lmtPrice = current_bbo['bid_px'] + 0.01
order.m_action = 'BUY'
else:
order.m_lmtPrice = current_bbo['ask_px'] - 0.01
order.m_action = 'SELL'
return order
示例14: makeOrder
# 需要导入模块: from ib.ext.Order import Order [as 别名]
# 或者: from ib.ext.Order.Order import m_tif [as 别名]
def makeOrder(self, action, orderId, tif, orderType, price, transmit, parentId):
newOrder = Order()
newOrder.m_orderId = orderId
newOrder.m_transmit = transmit
newOrder.m_lmtPrice = price
newOrder.m_tif = tif
newOrder.m_action = action
newOrder.m_orderType = orderType
if parentId is not None:
newOrder.m_parentId = parentId
newOrder.m_hidden = False
newOrder.m_outsideRth = True
newOrder.m_clientId = 999
newOrder.m_permid = 0
if orderType == 'LMT':
newOrder.m_auxPrice = 0
elif orderType == 'STP' or orderType == 'MIT':
newOrder.m_auxPrice = price
newOrder.m_totalQuantity = 1
return newOrder
示例15: processMsg
# 需要导入模块: from ib.ext.Order import Order [as 别名]
# 或者: from ib.ext.Order.Order import m_tif [as 别名]
#.........这里部分代码省略.........
timeStamp = self.readStr()
self.eWrapper().updateAccountTime(timeStamp)
elif msgId == self.ERR_MSG:
version = self.readInt()
if version < 2:
msg = self.readStr()
self.m_parent.error(msg)
else:
id = self.readInt()
errorCode = self.readInt()
errorMsg = self.readStr()
self.m_parent.error(id, errorCode, errorMsg)
elif msgId == self.OPEN_ORDER:
version = self.readInt()
order = Order()
order.m_orderId = self.readInt()
contract = Contract()
if version >= 17:
contract.m_conId = self.readInt()
contract.m_symbol = self.readStr()
contract.m_secType = self.readStr()
contract.m_expiry = self.readStr()
contract.m_strike = self.readDouble()
contract.m_right = self.readStr()
contract.m_exchange = self.readStr()
contract.m_currency = self.readStr()
if version >= 2:
contract.m_localSymbol = self.readStr()
order.m_action = self.readStr()
order.m_totalQuantity = self.readInt()
order.m_orderType = self.readStr()
order.m_lmtPrice = self.readDouble()
order.m_auxPrice = self.readDouble()
order.m_tif = self.readStr()
order.m_ocaGroup = self.readStr()
order.m_account = self.readStr()
order.m_openClose = self.readStr()
order.m_origin = self.readInt()
order.m_orderRef = self.readStr()
if version >= 3:
order.m_clientId = self.readInt()
if version >= 4:
order.m_permId = self.readInt()
if version < 18:
self.readBoolFromInt()
else:
order.m_outsideRth = self.readBoolFromInt()
order.m_hidden = (self.readInt() == 1)
order.m_discretionaryAmt = self.readDouble()
if version >= 5:
order.m_goodAfterTime = self.readStr()
if version >= 6:
self.readStr()
if version >= 7:
order.m_faGroup = self.readStr()
order.m_faMethod = self.readStr()
order.m_faPercentage = self.readStr()
order.m_faProfile = self.readStr()
if version >= 8:
order.m_goodTillDate = self.readStr()
if version >= 9:
order.m_rule80A = self.readStr()
order.m_percentOffset = self.readDouble()
order.m_settlingFirm = self.readStr()
order.m_shortSaleSlot = self.readInt()
order.m_designatedLocation = self.readStr()