本文整理汇总了Python中zipline.finance.blotter.Blotter.reject方法的典型用法代码示例。如果您正苦于以下问题:Python Blotter.reject方法的具体用法?Python Blotter.reject怎么用?Python Blotter.reject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zipline.finance.blotter.Blotter
的用法示例。
在下文中一共展示了Blotter.reject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_order_rejection
# 需要导入模块: from zipline.finance.blotter import Blotter [as 别名]
# 或者: from zipline.finance.blotter.Blotter import reject [as 别名]
def test_order_rejection(self):
blotter = Blotter()
# Reject a nonexistent order -> no order appears in new_order,
# no exceptions raised out
blotter.reject(56)
self.assertEqual(blotter.new_orders, [])
# Basic tests of open order behavior
open_order_id = blotter.order(24, 100, MarketOrder())
second_order_id = blotter.order(24, 50, MarketOrder())
self.assertEqual(len(blotter.open_orders[24]), 2)
open_order = blotter.open_orders[24][0]
self.assertEqual(open_order.status, ORDER_STATUS.OPEN)
self.assertEqual(open_order.id, open_order_id)
self.assertIn(open_order, blotter.new_orders)
# Reject that order immediately (same bar, i.e. still in new_orders)
blotter.reject(open_order_id)
self.assertEqual(len(blotter.new_orders), 2)
self.assertEqual(len(blotter.open_orders[24]), 1)
still_open_order = blotter.new_orders[0]
self.assertEqual(still_open_order.id, second_order_id)
self.assertEqual(still_open_order.status, ORDER_STATUS.OPEN)
rejected_order = blotter.new_orders[1]
self.assertEqual(rejected_order.status, ORDER_STATUS.REJECTED)
self.assertEqual(rejected_order.reason, '')
# Do it again, but reject it at a later time (after tradesimulation
# pulls it from new_orders)
blotter = Blotter()
new_open_id = blotter.order(24, 10, MarketOrder())
new_open_order = blotter.open_orders[24][0]
self.assertEqual(new_open_id, new_open_order.id)
# Pretend that the trade simulation did this.
blotter.new_orders = []
rejection_reason = "Not enough cash on hand."
blotter.reject(new_open_id, reason=rejection_reason)
rejected_order = blotter.new_orders[0]
self.assertEqual(rejected_order.id, new_open_id)
self.assertEqual(rejected_order.status, ORDER_STATUS.REJECTED)
self.assertEqual(rejected_order.reason, rejection_reason)
# You can't reject a filled order.
blotter = Blotter() # Reset for paranoia
blotter.current_dt = datetime.datetime.now()
filled_id = blotter.order(24, 100, MarketOrder())
aapl_trade = create_trade(24, 50.0, 400, datetime.datetime.now())
filled_order = None
for txn, updated_order in blotter.process_trade(aapl_trade):
filled_order = updated_order
self.assertEqual(filled_order.id, filled_id)
self.assertIn(filled_order, blotter.new_orders)
self.assertEqual(filled_order.status, ORDER_STATUS.FILLED)
self.assertNotIn(filled_order, blotter.open_orders[24])
blotter.reject(filled_id)
updated_order = blotter.orders[filled_id]
self.assertEqual(updated_order.status, ORDER_STATUS.FILLED)
示例2: test_order_rejection
# 需要导入模块: from zipline.finance.blotter import Blotter [as 别名]
# 或者: from zipline.finance.blotter.Blotter import reject [as 别名]
def test_order_rejection(self):
blotter = Blotter(self.sim_params.data_frequency,
self.asset_finder)
# Reject a nonexistent order -> no order appears in new_order,
# no exceptions raised out
blotter.reject(56)
self.assertEqual(blotter.new_orders, [])
# Basic tests of open order behavior
open_order_id = blotter.order(self.asset_24, 100, MarketOrder())
second_order_id = blotter.order(self.asset_24, 50, MarketOrder())
self.assertEqual(len(blotter.open_orders[self.asset_24]), 2)
open_order = blotter.open_orders[self.asset_24][0]
self.assertEqual(open_order.status, ORDER_STATUS.OPEN)
self.assertEqual(open_order.id, open_order_id)
self.assertIn(open_order, blotter.new_orders)
# Reject that order immediately (same bar, i.e. still in new_orders)
blotter.reject(open_order_id)
self.assertEqual(len(blotter.new_orders), 2)
self.assertEqual(len(blotter.open_orders[self.asset_24]), 1)
still_open_order = blotter.new_orders[0]
self.assertEqual(still_open_order.id, second_order_id)
self.assertEqual(still_open_order.status, ORDER_STATUS.OPEN)
rejected_order = blotter.new_orders[1]
self.assertEqual(rejected_order.status, ORDER_STATUS.REJECTED)
self.assertEqual(rejected_order.reason, '')
# Do it again, but reject it at a later time (after tradesimulation
# pulls it from new_orders)
blotter = Blotter(self.sim_params.data_frequency,
self.asset_finder)
new_open_id = blotter.order(self.asset_24, 10, MarketOrder())
new_open_order = blotter.open_orders[self.asset_24][0]
self.assertEqual(new_open_id, new_open_order.id)
# Pretend that the trade simulation did this.
blotter.new_orders = []
rejection_reason = "Not enough cash on hand."
blotter.reject(new_open_id, reason=rejection_reason)
rejected_order = blotter.new_orders[0]
self.assertEqual(rejected_order.id, new_open_id)
self.assertEqual(rejected_order.status, ORDER_STATUS.REJECTED)
self.assertEqual(rejected_order.reason, rejection_reason)
# You can't reject a filled order.
# Reset for paranoia
blotter = Blotter(self.sim_params.data_frequency,
self.asset_finder)
blotter.slippage_func = FixedSlippage()
filled_id = blotter.order(self.asset_24, 100, MarketOrder())
filled_order = None
blotter.current_dt = self.sim_params.sessions[-1]
bar_data = self.create_bardata(
simulation_dt_func=lambda: self.sim_params.sessions[-1],
)
txns, _, closed_orders = blotter.get_transactions(bar_data)
for txn in txns:
filled_order = blotter.orders[txn.order_id]
blotter.prune_orders(closed_orders)
self.assertEqual(filled_order.id, filled_id)
self.assertIn(filled_order, blotter.new_orders)
self.assertEqual(filled_order.status, ORDER_STATUS.FILLED)
self.assertNotIn(filled_order, blotter.open_orders[self.asset_24])
blotter.reject(filled_id)
updated_order = blotter.orders[filled_id]
self.assertEqual(updated_order.status, ORDER_STATUS.FILLED)