Example #1
0
    def __init__(self, config: Config = None):
        super(ApplicationContext, self).__init__()

        self.config = config if config else Config()

        self.clock = self.add_startable(self.__get_clock())
        self.provider_mgr = self.add_startable(ProviderManager())

        self.seq_mgr = self.add_startable(SequenceManager())

        self.inst_data_mgr = self.add_startable(InstrumentDataManager())
        self.ref_data_mgr = self.add_startable(RefDataManager())

        self.order_mgr = self.add_startable(OrderManager())
        self.acct_mgr = self.add_startable(AccountManager())
        self.portf_mgr = self.add_startable(PortfolioManager())
        self.stg_mgr = self.add_startable(StrategyManager())

        self.event_bus = EventBus()
        self.model_factory = ModelFactory
 def setUp(self):
     self.inst_data_mgr = InstrumentDataManager()
class InstrumentDataTest(TestCase):
    def setUp(self):
        self.inst_data_mgr = InstrumentDataManager()

    def test_get_bar(self):
        bar = self.inst_data_mgr.get_bar(1)
        self.assertIsNone(bar)

        bar1 = ModelFactory.build_bar(timestamp=0, inst_id="1", open=20, high=21, low=19, close=20.5)
        self.inst_data_mgr.on_bar(bar1)
        bar = self.inst_data_mgr.get_bar("1")
        self.assertEqual(bar1, bar)

    def test_get_quote(self):
        quote = self.inst_data_mgr.get_quote("1")
        self.assertIsNone(quote)

        quote1 = ModelFactory.build_quote(timestamp=0, inst_id="1", bid=18, ask=19, bid_size=200, ask_size=500)
        self.inst_data_mgr.on_quote(quote1)
        quote = self.inst_data_mgr.get_quote("1")
        self.assertEqual(quote1, quote)

    def test_get_trade(self):
        trade = self.inst_data_mgr.get_trade("1")
        self.assertIsNone(trade)

        trade1 = ModelFactory.build_trade(timestamp=0, inst_id="1", price=20, size=200)
        self.inst_data_mgr.on_trade(trade1)
        trade = self.inst_data_mgr.get_trade("1")
        self.assertEqual(trade1, trade)

    def get_latest_price(self):
        price = self.inst_data_mgr.get_latest_price(1)
        self.assertIsNone(price)

        bar1 = ModelFactory.build_bar(timestamp=0, inst_id="1", open=20, high=21, low=19, close=20.5)
        self.inst_data_mgr.on_bar(bar1)
        price = self.inst_data_mgr.get_latest_price(1)
        self.assertEqual(20.5, price)

        bar1 = ModelFactory.build_bar(timestamp=0, inst_id="1", open=20, high=21, low=19, close=20.5, adj_close=22)
        self.inst_data_mgr.on_bar(bar1)
        price = self.inst_data_mgr.get_latest_price(1)
        self.assertEqual(22, price)

        quote1 = ModelFactory.build_quote(timestamp=0, inst_id="1", bid=18, ask=19, bid_size=200, ask_size=500)
        self.inst_data_mgr.on_quote(quote1)
        price = self.inst_data_mgr.get_latest_price(1)
        self.assertEqual(18.5, price)

        trade1 = ModelFactory.build_trade(timestamp=0, inst_id="1", price=20, size=200)
        self.inst_data_mgr.on_bar(trade1)
        price = self.inst_data_mgr.get_latest_price(1)
        self.assertEqual(20, price)
 def setUp(self):
     self.inst_data_mgr = InstrumentDataManager()
class InstrumentDataTest(TestCase):
    def setUp(self):
        self.inst_data_mgr = InstrumentDataManager()

    def test_get_bar(self):
        bar = self.inst_data_mgr.get_bar(1)
        self.assertIsNone(bar)

        bar1 = Bar(inst_id=1, open=20, high=21, low=19, close=20.5)
        self.inst_data_mgr.on_bar(bar1)
        bar = self.inst_data_mgr.get_bar(1)
        self.assertEqual(bar1, bar)

    def test_get_quote(self):
        quote = self.inst_data_mgr.get_quote(1)
        self.assertIsNone(quote)

        quote1 = Quote(inst_id=1, bid=18, ask=19, bid_size=200, ask_size=500)
        self.inst_data_mgr.on_quote(quote1)
        quote = self.inst_data_mgr.get_quote(1)
        self.assertEqual(quote1, quote)

    def test_get_trade(self):
        trade = self.inst_data_mgr.get_trade(1)
        self.assertIsNone(trade)

        trade1 = Trade(inst_id=1, price=20, size=200)
        self.inst_data_mgr.on_trade(trade1)
        trade = self.inst_data_mgr.get_trade(1)
        self.assertEqual(trade1, trade)

    def get_latest_price(self):
        price = self.inst_data_mgr.get_latest_price(1)
        self.assertIsNone(price)

        bar1 = Bar(inst_id=1, open=20, high=21, low=19, close=20.5)
        self.inst_data_mgr.on_bar(bar1)
        price = self.inst_data_mgr.get_latest_price(1)
        self.assertEqual(20.5, price)

        bar1 = Bar(inst_id=1, open=20, high=21, low=19, close=20.5, adj_close=22)
        self.inst_data_mgr.on_bar(bar1)
        price = self.inst_data_mgr.get_latest_price(1)
        self.assertEqual(22, price)

        quote1 = Quote(inst_id=1, bid=18, ask=19, bid_size=200, ask_size=500)
        self.inst_data_mgr.on_quote(quote1)
        price = self.inst_data_mgr.get_latest_price(1)
        self.assertEqual(18.5, price)

        trade1 = Trade(inst_id=1, price=20, size=200)
        self.inst_data_mgr.on_bar(trade1)
        price = self.inst_data_mgr.get_latest_price(1)
        self.assertEqual(20, price)