Example #1
0
    def test_save_pair_orderbook_for_invalid_pair(self):
        orderbook = KrakenCrawler.parse_pair_orderbook(self.orderbook_response)

        result = KrakenCrawler.save_pair_orderbook(None, orderbook[0],
                                                   orderbook[1])

        self.assertFalse(result)
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_orderbook_for_not_existing_pair(self):
        orderbook = KrakenCrawler.parse_pair_orderbook(self.orderbook_response)

        exchange_pair = ExchangePair()
        result = KrakenCrawler.save_pair_orderbook(exchange_pair, orderbook[0],
                                                   orderbook[1])

        self.assertFalse(result)
Example #4
0
    def test_parse_pair_ticker_returns_empty_list_for_empty_response(self):
        result = KrakenCrawler.parse_pair_ticker("")
        self.assertIsNone(result[0])
        self.assertIsNone(result[1])

        result = KrakenCrawler.parse_pair_ticker(None)
        self.assertIsNone(result[0])
        self.assertIsNone(result[1])
Example #5
0
    def test_save_pair_ticker_for_not_existing_pair(self):
        ticker = KrakenCrawler.parse_pair_ticker(self.ticker_response)

        exchange_pair = ExchangePair()
        result = KrakenCrawler.save_pair_ticker(exchange_pair, ticker[0],
                                                ticker[1])

        self.assertFalse(result)
Example #6
0
    def test_request_pair_api_raise_exception_for_invalid_url(self):
        exchange = self.exchange
        exchange.orderbook_api = 'invalid_api_url'

        left, right = 'XBT', 'USD'

        with self.assertRaises(ConnectionError) as context:
            KrakenCrawler.request_pair_api(exchange.orderbook_api, left, right)

        self.assertTrue('Api request failed!' in str(context.exception))
Example #7
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 #8
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 #9
0
    def test_parse_pair_orderbook_returns_empty_lists_for_empty_response(self):

        result = KrakenCrawler.parse_pair_orderbook("")
        self.assertEquals(type(result[0]), list)
        self.assertFalse(result[0])
        self.assertEquals(type(result[1]), list)
        self.assertFalse(result[1])

        result = KrakenCrawler.parse_pair_orderbook(None)
        self.assertEquals(type(result[0]), list)
        self.assertFalse(result[0])
        self.assertEquals(type(result[1]), list)
        self.assertFalse(result[1])
Example #10
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 #11
0
    def test_parse_pair_ticker_returns_parsed_data_for_mocked_response(self):
        response = self.ticker_response

        result = KrakenCrawler.parse_pair_ticker(response)
        self.assertTrue(result[0])  # "bid":17152.01
        self.assertEquals(result[0], 17152.01)

        self.assertTrue(result[1])  # "ask":17699.94
        self.assertEquals(result[1], 17699.94)
Example #12
0
    def test_request_pair_api_returns_any_result_for_exchange_url(self):
        exchange = self.exchange
        exchange.orderbook_api = self.url

        left, right = 'XBT', 'USD'

        result = KrakenCrawler.request_pair_api(exchange.orderbook_api, left,
                                                right)
        self.assertTrue(result)
Example #13
0
    def test_request_pair_api_returns_proper_result_for_orderbook_api(self):
        exchange = self.exchange
        exchange.orderbook_api = self.orderbook_api

        left, right = 'XBT', 'USD'

        result = KrakenCrawler.request_pair_api(exchange.orderbook_api, left,
                                                right)

        self.assertTrue('"bids":' in result)
        self.assertTrue('"asks":' in result)
Example #14
0
    def test_request_pair_api_returns_proper_result_for_ticker_api(self):
        exchange = self.exchange
        exchange.ticker_api = self.ticker_api

        left, right = 'XBT', 'USD'

        result = KrakenCrawler.request_pair_api(exchange.ticker_api, left,
                                                right)

        self.assertTrue('"b":' in result)
        self.assertTrue('"a":' in result)
Example #15
0
    def test_parse_pair_orderbook_returns_parsed_data_for_mocked_response(
            self):
        response = self.orderbook_response

        result = KrakenCrawler.parse_pair_orderbook(response)
        self.assertTrue(result[0])  # [17151.01, 0.055]
        self.assertEquals(len(result[0]), 1)
        self.assertEquals(result[0][0][0], 17151.01)
        self.assertEquals(result[0][0][1], 0.055)

        self.assertTrue(result[1])  # [17699.99, 0.01529216]
        self.assertEquals(len(result[1]), 1)
        self.assertEquals(result[1][0][0], 17699.99)
        self.assertEquals(result[1][0][1], 0.01529216)
Example #16
0
    def test_save_pair_ticker_for_invalid_pair(self):
        ticker = KrakenCrawler.parse_pair_ticker(self.ticker_response)

        result = KrakenCrawler.save_pair_ticker(None, ticker[0], ticker[1])

        self.assertFalse(result)
Example #17
0
    def test_request_pair_api_returns_empty_result_for_empty_api(self):
        left, right = 'XBT', 'USD'

        self.assertEquals(KrakenCrawler.request_pair_api("", left, right), "")
        self.assertEquals(KrakenCrawler.request_pair_api(None, left, right),
                          "")
Example #18
0
    def test_crawler_is_properly_created(self):
        exchange = self.exchange

        crawler = KrakenCrawler(exchange)

        self.assertEquals(exchange.id, crawler.exchange.id)
Example #19
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))