def setUp(self): TestUnitSetUpStage.setUp(self) self.forex_order = create_filled_order( trade_summary=self.trade_summary, forex=self.forex, spread='FOREX', contract='FOREX', side='BUY', quantity=10000, price=120.1295) self.price_range = 0.2 filled_orders = FilledOrder.objects.filter(forex=self.forex) self.long_future = StageLongForex(filled_orders=filled_orders)
def setUp(self): TestUnitSetUpStage.setUp(self) self.forex_order = create_filled_order( trade_summary=self.trade_summary, forex=self.forex, spread='FOREX', contract='FOREX', side='BUY', quantity=10000, price=120.1295 ) self.price_range = 0.2 filled_orders = FilledOrder.objects.filter(forex=self.forex) self.long_future = StageLongForex(filled_orders=filled_orders)
class TestStageLongForex(TestUnitSetUpStage): def setUp(self): TestUnitSetUpStage.setUp(self) self.forex_order = create_filled_order( trade_summary=self.trade_summary, forex=self.forex, spread='FOREX', contract='FOREX', side='BUY', quantity=10000, price=120.1295 ) self.price_range = 0.2 filled_orders = FilledOrder.objects.filter(forex=self.forex) self.long_future = StageLongForex(filled_orders=filled_orders) def test_create_even_stage(self): """ Create even stage using filled orders data """ even_stage = self.long_future.create_even_stage() self.method_test_create_stage( stage=even_stage, name='EVEN', expression='{price_a} == {current_price}', detail={ 'price_a': 120.1295, 'amount_a': 0.0, 'price_b': 0.0, 'amount_b': 0.0, 'left_status': '', 'left_expression': '', 'right_status': '', 'right_expression': '', } ) self.check_in_stage(stage_cls=even_stage, price=120.1295, expect=True) self.check_in_stage(stage_cls=even_stage, price=120.33, expect=False) self.check_get_status( stage_cls=even_stage, new_price=120.1295, old_price=120.1295, expect='UNKNOWN' ) def test_create_profit_stage(self): """ Create profit stage using filled orders data """ profit_stage = self.long_future.create_profit_stage() self.method_test_create_stage( stage=profit_stage, name='PROFIT', expression='{price_a} < {current_price}', detail={ 'price_a': 120.1295, 'amount_a': 0.0, 'price_b': 0.0, 'amount_b': 0.0, 'left_status': 'DECREASING', 'left_expression': '{price_a} < {new_price} < {old_price}', 'right_status': 'PROFITING', 'right_expression': '{price_a} < {old_price} < {new_price}', } ) self.check_in_stage(stage_cls=profit_stage, price=121.1295, expect=True) self.check_in_stage(stage_cls=profit_stage, price=120.1295, expect=False) self.check_get_status(profit_stage, new_price=121.1295, old_price=122.1295, expect='DECREASING') self.check_get_status(profit_stage, new_price=123.1295, old_price=122.1295, expect='PROFITING') self.check_get_status(profit_stage, new_price=120.1295, old_price=120.1295, expect='UNKNOWN') def test_create_loss_stage(self): """ Create loss stage using filled orders data """ loss_stage = self.long_future.create_loss_stage() self.method_test_create_stage( stage=loss_stage, name='LOSS', expression='{current_price} < {price_a}', detail={ 'price_a': 120.1295, 'amount_a': 0.0, 'price_b': 0.0, 'amount_b': 0.0, 'left_status': 'RECOVERING', 'left_expression': '{old_price} < {new_price} < {price_a}', 'right_status': 'LOSING', 'right_expression': '{new_price} < {old_price} < {price_a}', } ) self.check_in_stage(stage_cls=loss_stage, price=118.1295, expect=True) self.check_in_stage(stage_cls=loss_stage, price=122.1295, expect=False) self.check_get_status(loss_stage, new_price=118.1295, old_price=116.1295, expect='RECOVERING') self.check_get_status(loss_stage, new_price=114.1295, old_price=116.1295, expect='LOSING') self.check_get_status(loss_stage, new_price=118.1295, old_price=118.1295, expect='UNKNOWN') def test_create_stages(self): """ Test create stages using filled orders """ print 'run create_stages...' stages = self.long_future.create_stages() self.assertEqual(type(stages), list) for stage in stages: print stage self.assertEqual(type(stage), PositionStage)
class TestStageLongForex(TestUnitSetUpStage): def setUp(self): TestUnitSetUpStage.setUp(self) self.forex_order = create_filled_order( trade_summary=self.trade_summary, forex=self.forex, spread='FOREX', contract='FOREX', side='BUY', quantity=10000, price=120.1295) self.price_range = 0.2 filled_orders = FilledOrder.objects.filter(forex=self.forex) self.long_future = StageLongForex(filled_orders=filled_orders) def test_create_even_stage(self): """ Create even stage using filled orders data """ even_stage = self.long_future.create_even_stage() self.method_test_create_stage( stage=even_stage, name='EVEN', expression='{price_a} == {current_price}', detail={ 'price_a': 120.1295, 'amount_a': 0.0, 'price_b': 0.0, 'amount_b': 0.0, 'left_status': '', 'left_expression': '', 'right_status': '', 'right_expression': '', }) self.check_in_stage(stage_cls=even_stage, price=120.1295, expect=True) self.check_in_stage(stage_cls=even_stage, price=120.33, expect=False) self.check_get_status(stage_cls=even_stage, new_price=120.1295, old_price=120.1295, expect='UNKNOWN') def test_create_profit_stage(self): """ Create profit stage using filled orders data """ profit_stage = self.long_future.create_profit_stage() self.method_test_create_stage( stage=profit_stage, name='PROFIT', expression='{price_a} < {current_price}', detail={ 'price_a': 120.1295, 'amount_a': 0.0, 'price_b': 0.0, 'amount_b': 0.0, 'left_status': 'DECREASING', 'left_expression': '{price_a} < {new_price} < {old_price}', 'right_status': 'PROFITING', 'right_expression': '{price_a} < {old_price} < {new_price}', }) self.check_in_stage(stage_cls=profit_stage, price=121.1295, expect=True) self.check_in_stage(stage_cls=profit_stage, price=120.1295, expect=False) self.check_get_status(profit_stage, new_price=121.1295, old_price=122.1295, expect='DECREASING') self.check_get_status(profit_stage, new_price=123.1295, old_price=122.1295, expect='PROFITING') self.check_get_status(profit_stage, new_price=120.1295, old_price=120.1295, expect='UNKNOWN') def test_create_loss_stage(self): """ Create loss stage using filled orders data """ loss_stage = self.long_future.create_loss_stage() self.method_test_create_stage( stage=loss_stage, name='LOSS', expression='{current_price} < {price_a}', detail={ 'price_a': 120.1295, 'amount_a': 0.0, 'price_b': 0.0, 'amount_b': 0.0, 'left_status': 'RECOVERING', 'left_expression': '{old_price} < {new_price} < {price_a}', 'right_status': 'LOSING', 'right_expression': '{new_price} < {old_price} < {price_a}', }) self.check_in_stage(stage_cls=loss_stage, price=118.1295, expect=True) self.check_in_stage(stage_cls=loss_stage, price=122.1295, expect=False) self.check_get_status(loss_stage, new_price=118.1295, old_price=116.1295, expect='RECOVERING') self.check_get_status(loss_stage, new_price=114.1295, old_price=116.1295, expect='LOSING') self.check_get_status(loss_stage, new_price=118.1295, old_price=118.1295, expect='UNKNOWN') def test_create_stages(self): """ Test create stages using filled orders """ print 'run create_stages...' stages = self.long_future.create_stages() self.assertEqual(type(stages), list) for stage in stages: print stage self.assertEqual(type(stage), PositionStage)