Example #1
0
    def test_init_raise_exception_for_mismatched_exchange(self):
        exchange = Exchange.objects.get(name="Cex.io")

        with self.assertRaises(TypeError) as context:
            KrakenCrawler(exchange)

        self.assertTrue('Mismatched Exchange' in str(context.exception))
Example #2
0
    def test_save_pair_ticker_for_valid_pair_and_empty_orderbook(self):
        exchange = self.exchange
        crawler = KrakenCrawler(exchange)

        result = KrakenCrawler.save_pair_ticker(crawler.exchange.pairs.first(),
                                                None, None)

        self.assertFalse(result)
Example #3
0
    def test_save_pair_ticker_for_valid_inputs(self):
        ticker = KrakenCrawler.parse_pair_ticker(self.ticker_response)
        exchange = self.exchange
        crawler = KrakenCrawler(exchange)
        exchange_pair = crawler.exchange.pairs.first()

        result = KrakenCrawler.save_pair_ticker(exchange_pair, ticker[0],
                                                ticker[1])
        self.assertTrue(result)
        self.assertEqual(exchange_pair.last_bid, self.saved_ticker_bid)
        self.assertEqual(exchange_pair.last_ask, self.saved_ticker_ask)
Example #4
0
    def test_save_pair_orderbook_for_valid_inputs(self):
        orderbook = KrakenCrawler.parse_pair_orderbook(self.orderbook_response)
        exchange = self.exchange
        crawler = KrakenCrawler(exchange)
        exchange_pair = crawler.exchange.pairs.first()

        result = KrakenCrawler.save_pair_orderbook(exchange_pair, orderbook[0],
                                                   orderbook[1])
        self.assertTrue(result)
        self.assertEqual(exchange_pair.bids, self.saved_orderbook_bids)
        self.assertEqual(exchange_pair.asks, self.saved_orderbook_asks)
Example #5
0
    def test_init_raise_exception_for_wrong_input(self):
        with self.assertRaises(TypeError) as context:
            KrakenCrawler([])

        self.assertTrue(
            'Given argument is not Exchange type' in str(context.exception))
Example #6
0
    def test_crawler_is_properly_created(self):
        exchange = self.exchange

        crawler = KrakenCrawler(exchange)

        self.assertEquals(exchange.id, crawler.exchange.id)