예제 #1
0
    def test_save_pair_orderbook_for_invalid_pair(self):
        crawler = BitBayCrawler(self.exchange)
        orderbook = crawler.parse_pair_orderbook(self.orderbook_response)

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

        self.assertFalse(result)
예제 #2
0
    def test_save_pair_ticker_for_invalid_pair(self):
        crawler = BitBayCrawler(self.exchange)
        ticker = crawler.parse_pair_ticker(self.ticker_response)

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

        self.assertFalse(result)
예제 #3
0
    def test_request_pair_api_raise_exception_for_invalid_url(self):
        orderbook_api = 'invalid_api_url'
        left, right = 'BTC', 'USD'

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

        self.assertTrue('Api request failed!' in str(context.exception))
예제 #4
0
    def test_save_pair_ticker_for_not_existing_pair(self):
        crawler = BitBayCrawler(self.exchange)
        ticker = crawler.parse_pair_ticker(self.ticker_response)
        exchange_pair = ExchangePair()

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

        self.assertFalse(result)
예제 #5
0
    def test_save_pair_orderbook_for_not_existing_pair(self):
        crawler = BitBayCrawler(self.exchange)
        orderbook = crawler.parse_pair_orderbook(self.orderbook_response)
        exchange_pair = ExchangePair()

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

        self.assertFalse(result)
예제 #6
0
    def test_save_pair_orderbook_for_valid_inputs(self):
        crawler = BitBayCrawler(self.exchange)
        orderbook = crawler.parse_pair_orderbook(self.orderbook_response)
        exchange_pair = crawler.exchange.pairs.first()

        result = crawler.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)
예제 #7
0
    def test_parse_pair_ticker_returns_empty_list_for_empty_response(self):
        crawler = BitBayCrawler(self.exchange)

        result = crawler.parse_pair_ticker("")
        self.assertIsNone(result[0])
        self.assertIsNone(result[1])

        result = crawler.parse_pair_ticker(None)
        self.assertIsNone(result[0])
        self.assertIsNone(result[1])
예제 #8
0
    def test_save_pair_ticker_for_valid_inputs(self):
        crawler = BitBayCrawler(self.exchange)
        ticker = crawler.parse_pair_ticker(self.ticker_response)
        exchange_pair = crawler.exchange.pairs.first()

        result = crawler.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)
예제 #9
0
    def test_parse_pair_ticker_returns_parsed_data_for_mocked_response(self):
        response = self.ticker_response
        crawler = BitBayCrawler(self.exchange)

        result = crawler.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)
예제 #10
0
    def test_parse_pair_orderbook_returns_parsed_data_for_mocked_response(self):
        crawler = BitBayCrawler(self.exchange)
        response = self.orderbook_response

        result = crawler.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)
예제 #11
0
    def test_parse_pair_orderbook_returns_empty_lists_for_empty_response(self):
        crawler = BitBayCrawler(self.exchange)

        result = crawler.parse_pair_orderbook("")

        self.assertEquals(type(result[0]), list)
        self.assertFalse(result[0])
        self.assertEquals(type(result[1]), list)
        self.assertFalse(result[1])

        result = crawler.parse_pair_orderbook(None)

        self.assertEquals(type(result[0]), list)
        self.assertFalse(result[0])
        self.assertEquals(type(result[1]), list)
        self.assertFalse(result[1])
예제 #12
0
    def test_request_pair_api_returns_any_result_for_exchange_url(self):
        orderbook_api = 'https://bitbay.net'
        left, right = 'BTC', 'USD'

        result = BitBayCrawler.request_pair_api(orderbook_api, left, right)

        self.assertTrue(result)
예제 #13
0
    def test_request_pair_api_returns_proper_result_for_ticker_api(self):
        left, right = 'BTC', 'USD'

        result = BitBayCrawler.request_pair_api(self.ticker_api, left, right)

        self.assertTrue('"bid":' in result)
        self.assertTrue('"ask":' in result)
예제 #14
0
    def test_init_raise_exception_for_mismatched_exchange(self):
        exchange = Exchange.objects.get(name="Cex.io")

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

        self.assertTrue('Mismatched Exchange' in str(context.exception))
예제 #15
0
    def test_save_pair_ticker_for_valid_pair_and_empty_orderbook(self):
        crawler = BitBayCrawler(self.exchange)

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

        self.assertFalse(result)
예제 #16
0
    def test_request_pair_api_returns_empty_result_for_empty_api(self):
        left, right = 'BTC', 'USD'

        self.assertEquals(BitBayCrawler.request_pair_api("", left, right), "")
        self.assertEquals(BitBayCrawler.request_pair_api(None, left, right), "")
예제 #17
0
    def test_init_raise_exception_for_wrong_input(self):
        with self.assertRaises(TypeError) as context:
            BitBayCrawler([])

        self.assertTrue('Given argument is not Exchange type' in str(context.exception))
예제 #18
0
    def test_crawler_is_properly_created(self):
        crawler = BitBayCrawler(self.exchange)

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