mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-16 11:18:05 +08:00
REF: Explicitly use Assets in Position, Order, Transaction
(Instead of `sid`, which were already usually assets) Perf packets are unchanged and still emit `sid`: int
This commit is contained in:
+22
-17
@@ -187,8 +187,8 @@ class FinanceTestCase(WithLogger,
|
||||
# if present, expect transaction amounts to match orders exactly.
|
||||
complete_fill = params.get('complete_fill')
|
||||
|
||||
sid = 1
|
||||
metadata = make_simple_equity_info([sid], self.start, self.end)
|
||||
asset1 = self.asset_finder.retrieve_asset(1)
|
||||
metadata = make_simple_equity_info([asset1.sid], self.start, self.end)
|
||||
with TempDirectory() as tempdir, \
|
||||
tmp_trading_env(equities=metadata) as env:
|
||||
|
||||
@@ -206,7 +206,7 @@ class FinanceTestCase(WithLogger,
|
||||
|
||||
price_data = np.array([10.1] * len(minutes))
|
||||
assets = {
|
||||
sid: pd.DataFrame({
|
||||
asset1.sid: pd.DataFrame({
|
||||
"open": price_data,
|
||||
"high": price_data,
|
||||
"low": price_data,
|
||||
@@ -305,7 +305,7 @@ class FinanceTestCase(WithLogger,
|
||||
# place an order
|
||||
direction = alternator ** len(order_list)
|
||||
order_id = blotter.order(
|
||||
blotter.asset_finder.retrieve_asset(sid),
|
||||
asset1,
|
||||
order_amount * direction,
|
||||
MarketOrder())
|
||||
order_list.append(blotter.orders[order_id])
|
||||
@@ -333,7 +333,7 @@ class FinanceTestCase(WithLogger,
|
||||
|
||||
for i in range(order_count):
|
||||
order = order_list[i]
|
||||
self.assertEqual(order.sid, sid)
|
||||
self.assertEqual(order.asset, asset1)
|
||||
self.assertEqual(order.amount, order_amount * alternator ** i)
|
||||
|
||||
if complete_fill:
|
||||
@@ -351,15 +351,19 @@ class FinanceTestCase(WithLogger,
|
||||
|
||||
self.assertEqual(len(transactions), expected_txn_count)
|
||||
|
||||
cumulative_pos = tracker.position_tracker.positions[sid]
|
||||
cumulative_pos = tracker.position_tracker.positions[asset1]
|
||||
if total_volume == 0:
|
||||
self.assertIsNone(cumulative_pos)
|
||||
else:
|
||||
self.assertEqual(total_volume, cumulative_pos.amount)
|
||||
|
||||
# the open orders should not contain sid.
|
||||
# the open orders should not contain the asset.
|
||||
oo = blotter.open_orders
|
||||
self.assertNotIn(sid, oo, "Entry is removed when no open orders")
|
||||
self.assertNotIn(
|
||||
asset1,
|
||||
oo,
|
||||
"Entry is removed when no open orders"
|
||||
)
|
||||
|
||||
def test_blotter_processes_splits(self):
|
||||
blotter = Blotter('daily', self.env.asset_finder,
|
||||
@@ -376,23 +380,24 @@ class FinanceTestCase(WithLogger,
|
||||
blotter.process_splits([(2, 0.3333)])
|
||||
|
||||
for sid in [1, 2]:
|
||||
order_lists = blotter.open_orders[sid]
|
||||
order_lists = \
|
||||
blotter.open_orders[blotter.asset_finder.retrieve_asset(sid)]
|
||||
self.assertIsNotNone(order_lists)
|
||||
self.assertEqual(1, len(order_lists))
|
||||
|
||||
aapl_order = blotter.open_orders[1][0].to_dict()
|
||||
fls_order = blotter.open_orders[2][0].to_dict()
|
||||
aapl_order = blotter.open_orders[1][0]
|
||||
fls_order = blotter.open_orders[2][0]
|
||||
|
||||
# make sure the aapl order didn't change
|
||||
self.assertEqual(100, aapl_order['amount'])
|
||||
self.assertEqual(10, aapl_order['limit'])
|
||||
self.assertEqual(1, aapl_order['sid'])
|
||||
self.assertEqual(100, aapl_order.amount)
|
||||
self.assertEqual(10, aapl_order.limit)
|
||||
self.assertEqual(1, aapl_order.asset)
|
||||
|
||||
# make sure the fls order did change
|
||||
# to 300 shares at 3.33
|
||||
self.assertEqual(300, fls_order['amount'])
|
||||
self.assertEqual(3.33, fls_order['limit'])
|
||||
self.assertEqual(2, fls_order['sid'])
|
||||
self.assertEqual(300, fls_order.amount)
|
||||
self.assertEqual(3.33, fls_order.limit)
|
||||
self.assertEqual(2, fls_order.asset)
|
||||
|
||||
|
||||
class TradingEnvironmentTestCase(WithLogger,
|
||||
|
||||
Reference in New Issue
Block a user