MCPcopy
hub / github.com/quantopian/zipline / order

Method order

zipline/finance/blotter/simulation_blotter.py:95–154  ·  view source on GitHub ↗

Place an order. Parameters ---------- asset : zipline.assets.Asset The asset that this order is for. amount : int The amount of shares to order. If ``amount`` is positive, this is the number of shares to buy or cover. If ``amount``

(self, asset, amount, style, order_id=None)

Source from the content-addressed store, hash-verified

93
94 @expect_types(asset=Asset)
95 def order(self, asset, amount, style, order_id=None):
96 """Place an order.
97
98 Parameters
99 ----------
100 asset : zipline.assets.Asset
101 The asset that this order is for.
102 amount : int
103 The amount of shares to order. If ``amount`` is positive, this is
104 the number of shares to buy or cover. If ``amount`` is negative,
105 this is the number of shares to sell or short.
106 style : zipline.finance.execution.ExecutionStyle
107 The execution style for the order.
108 order_id : str, optional
109 The unique identifier for this order.
110
111 Returns
112 -------
113 order_id : str or None
114 The unique identifier for this order, or None if no order was
115 placed.
116
117 Notes
118 -----
119 amount > 0 :: Buy/Cover
120 amount < 0 :: Sell/Short
121 Market order: order(asset, amount)
122 Limit order: order(asset, amount, style=LimitOrder(limit_price))
123 Stop order: order(asset, amount, style=StopOrder(stop_price))
124 StopLimit order: order(asset, amount, style=StopLimitOrder(limit_price,
125 stop_price))
126 """
127 # something could be done with amount to further divide
128 # between buy by share count OR buy shares up to a dollar amount
129 # numeric == share count AND "$dollar.cents" == cost amount
130
131 if amount == 0:
132 # Don't bother placing orders for 0 shares.
133 return None
134 elif amount > self.max_shares:
135 # Arbitrary limit of 100 billion (US) shares will never be
136 # exceeded except by a buggy algorithm.
137 raise OverflowError("Can't order more than %d shares" %
138 self.max_shares)
139
140 is_buy = (amount > 0)
141 order = Order(
142 dt=self.current_dt,
143 asset=asset,
144 amount=amount,
145 stop=style.get_stop_price(is_buy),
146 limit=style.get_limit_price(is_buy),
147 id=order_id
148 )
149
150 self.open_orders[order.asset].append(order)
151 self.orders[order.id] = order
152 self.new_orders.append(order)

Calls 3

OrderClass · 0.90
get_stop_priceMethod · 0.45
get_limit_priceMethod · 0.45