Beispiel #1
0
 def setUp(self):
     # Fixture Setup
     self.account_id = TestStubs.account_id()
     self.order_factory = OrderFactory(id_tag_trader=IdTag('001'),
                                       id_tag_strategy=IdTag('001'),
                                       clock=TestClock(),
                                       guid_factory=TestGuidFactory())
Beispiel #2
0
    def position(number=1, entry_price=None) -> Position:
        if entry_price is None:
            entry_price = Price("1.00000")

        generator = PositionIdGenerator(id_tag_trader=IdTag("001"))

        for _i in range(number):
            generator.generate(TestStubs.symbol_audusd_fxcm())

        order_factory = OrderFactory(
            strategy_id=StrategyId("S", "001"),
            id_tag_trader=IdTag("001"),
            id_tag_strategy=IdTag("001"),
            clock=LiveClock(),
        )

        order = order_factory.market(
            TestStubs.symbol_audusd_fxcm(),
            OrderSide.BUY,
            Quantity(100000),
        )

        position_id = PositionId(TestStubs.symbol_audusd_fxcm().value)
        order_filled = TestStubs.event_order_filled(
            order,
            position_id=position_id,
            fill_price=entry_price,
        )

        position = Position(event=order_filled)

        return position
Beispiel #3
0
    def setUp(self):
        # Fixture Setup
        self.clock = TestClock()
        uuid_factor = TestUUIDFactory()
        logger = TestLogger(self.clock)
        self.order_factory = OrderFactory(
            strategy_id=StrategyId("S", "001"),
            id_tag_trader=IdTag("001"),
            id_tag_strategy=IdTag("001"),
            clock=TestClock(),
        )

        state = AccountState(
            AccountId.from_string("BITMEX-1513111-SIMULATED"),
            BTC,
            Money(10., BTC),
            Money(0., BTC),
            Money(0., BTC),
            uuid4(),
            UNIX_EPOCH
        )

        self.account = Account(state)
        self.portfolio = Portfolio(self.clock, uuid_factor, logger)
        self.portfolio.register_account(self.account)
Beispiel #4
0
 def setUp(self):
     # Fixture Setup
     self.account_id = TestStubs.account_id()
     self.order_factory = OrderFactory(
         strategy_id=StrategyId("S", "001"),
         id_tag_trader=IdTag("001"),
         id_tag_strategy=IdTag("001"),
         clock=TestClock())
 def setUp(self):
     # Fixture Setup
     self.generator = ClientOrderIdGenerator(IdTag("001"), IdTag("001"),
                                             LiveClock())
     self.order_factory = OrderFactory(
         trader_id=TraderId("TESTER", "000"),
         strategy_id=StrategyId("S", "001"),
         clock=TestClock(),
     )
    def setUp(self):
        # Fixture Setup
        self.clock = TestClock()
        self.guid_factory = TestGuidFactory()
        logger = TestLogger()

        self.trader_id = TraderId('TESTER', '000')
        self.account_id = TestStubs.account_id()

        self.order_factory = OrderFactory(
            id_tag_trader=self.trader_id.order_id_tag,
            id_tag_strategy=IdTag('001'),
            clock=self.clock)

        self.portfolio = Portfolio(currency=Currency.USD,
                                   clock=self.clock,
                                   guid_factory=self.guid_factory,
                                   logger=logger)

        self.analyzer = PerformanceAnalyzer()

        self.exec_db = InMemoryExecutionDatabase(trader_id=self.trader_id,
                                                 logger=logger)
        self.exec_engine = ExecutionEngine(trader_id=self.trader_id,
                                           account_id=self.account_id,
                                           database=self.exec_db,
                                           portfolio=self.portfolio,
                                           clock=self.clock,
                                           guid_factory=self.guid_factory,
                                           logger=logger)

        self.exec_engine.handle_event(TestStubs.account_event())

        self.exec_client = MockExecutionClient(self.exec_engine, logger)
        self.exec_engine.register_client(self.exec_client)
Beispiel #7
0
    def test_initialize_trader(self):
        # Arrange
        # Act
        trader_id = self.trader.id

        # Assert
        self.assertEqual(TraderId("TESTER", "000"), trader_id)
        self.assertEqual(IdTag("000"), trader_id.tag)
        self.assertEqual(ComponentState.INITIALIZED, self.trader.state)
        self.assertEqual(2, len(self.trader.strategy_states()))
Beispiel #8
0
    def test_can_initialize_trader(self):
        # Arrange
        # Act
        trader_id = self.trader.id

        # Assert
        self.assertEqual(TraderId('TESTER', '000'), trader_id)
        self.assertEqual(IdTag('000'), trader_id.order_id_tag)
        self.assertFalse(self.trader.is_running)
        self.assertEqual(0, len(self.trader.started_datetimes))
        self.assertEqual(0, len(self.trader.stopped_datetimes))
        self.assertEqual(2, len(self.trader.strategy_status()))
Beispiel #9
0
    def test_equality_of_subclass(self):
        # Arrange
        id1 = Venue("BINANCE")
        id2 = Venue("BINANCE")
        id3 = InstrumentId(Symbol("BINANCE"), Venue("BINANCE"))  # Invalid
        id4 = IdTag("BINANCE")

        # Act
        # Assert
        assert id1 == id1
        assert id2 == id2
        assert id1 == id2
        assert id2 == id1
        assert id1 != id3
        assert id2 != id3
        assert id2 != id4
        assert id4 != id1
Beispiel #10
0
    def setUp(self):
        # Fixture Setup
        self.clock = TestClock()
        self.uuid_factory = TestUUIDFactory()
        self.logger = TestLogger(self.clock)

        self.trader_id = TraderId("TESTER", "000")
        self.account_id = TestStubs.account_id()

        self.order_factory = OrderFactory(
            strategy_id=StrategyId("S", "001"),
            id_tag_trader=self.trader_id.tag,
            id_tag_strategy=IdTag("001"),
            clock=self.clock,
        )

        self.portfolio = Portfolio(
            clock=self.clock,
            uuid_factory=self.uuid_factory,
            logger=self.logger,
        )

        self.analyzer = PerformanceAnalyzer()

        database = BypassExecutionDatabase(trader_id=self.trader_id,
                                           logger=self.logger)
        self.exec_engine = ExecutionEngine(
            database=database,
            portfolio=self.portfolio,
            clock=self.clock,
            uuid_factory=self.uuid_factory,
            logger=self.logger,
        )

        self.cache = self.exec_engine.cache
        self.exec_engine.process(TestStubs.event_account_state())

        self.venue = Venue("FXCM")
        self.exec_client = MockExecutionClient(
            self.venue,
            self.account_id,
            self.exec_engine,
            self.logger,
        )

        self.exec_engine.register_client(self.exec_client)
Beispiel #11
0
 def setUp(self):
     self.generator = OrderIdGenerator(IdTag("001"), IdTag("001"), LiveClock())
Beispiel #12
0
    def position_which_is_closed(position_id, close_price=None) -> Position:

        if close_price is None:
            close_price = Price("1.0001")

        order_factory = OrderFactory(
            strategy_id=StrategyId("S", "001"),
            id_tag_trader=IdTag("001"),
            id_tag_strategy=IdTag("001"),
        )

        order = order_factory.market(
            TestStubs.symbol_audusd_fxcm(),
            OrderSide.SELL,
            Quantity(100000),
        )

        filled1 = OrderFilled(
            TestStubs.account_id(),
            order.cl_ord_id,
            OrderId("1"),
            ExecutionId(order.cl_ord_id.value.replace('O', 'E')),
            position_id,
            StrategyId("S", "1"),
            order.symbol,
            order.side,
            order.quantity,
            Quantity(),
            close_price,
            Money(0, USD),
            LiquiditySide.TAKER,
            USD,  # Stub event
            USD,  # Stub event
            UNIX_EPOCH + timedelta(minutes=5),
            uuid4(),
            UNIX_EPOCH + timedelta(minutes=5),
        )

        filled2 = OrderFilled(
            TestStubs.account_id(),
            order.cl_ord_id,
            OrderId("2"),
            ExecutionId(order.cl_ord_id.value.replace('O', 'E')),
            position_id,
            StrategyId("S", "1"),
            order.symbol,
            OrderSide.BUY,
            order.quantity,
            Quantity(),
            close_price,
            Money(0, USD),
            LiquiditySide.TAKER,
            USD,  # Stub event
            USD,  # Stub event
            UNIX_EPOCH + timedelta(minutes=5),
            uuid4(),
            UNIX_EPOCH + timedelta(minutes=5),
        )

        position = Position(filled1)
        position.apply(filled2)

        return position
Beispiel #13
0
 def setUp(self):
     # Fixture Setup
     self.position_id_generator = PositionIdGenerator(
         id_tag_trader=IdTag("001"),
         clock=TestClock(),
     )
Beispiel #14
0
 def setUp(self):
     # Fixture Setup
     self.generator = OrderIdGenerator(IdTag("001"), IdTag("001"),
                                       LiveClock())
Beispiel #15
0
 def setup(self):
     # Fixture Setup
     self.order_id_generator = ClientOrderIdGenerator(
         id_tag_trader=IdTag("001"),
         id_tag_strategy=IdTag("001"),
         clock=TestClock())
Beispiel #16
0
 def setUp(self):
     # Fixture Setup
     self.order_id_generator = OrderIdGenerator(
         id_tag_trader=IdTag('001'),
         id_tag_strategy=IdTag('001'),
         clock=TestClock())
Beispiel #17
0
 def setUp(self):
     # Fixture Setup
     self.position_id_generator = PositionIdGenerator(
         id_tag_trader=IdTag('001'),
         id_tag_strategy=IdTag('001'),
         clock=TestClock())
 def setUp(self):
     self.generator = OrderIdGenerator(IdTag('001'), IdTag('001'))