Ejemplo n.º 1
0
 async def test_get_rate_failure_retrieved(self):
     manager = ExchangeRateManager([BadMarketFeed])
     manager.start()
     await manager.wait()
     for feed in manager.market_feeds:  # no rate but it tried
         self.assertFalse(feed.has_rate)
         self.assertTrue(feed.event.is_set())
     self.addCleanup(manager.stop)
Ejemplo n.º 2
0
 async def test_median_rate_used(self):
     manager = ExchangeRateManager([BittrexBTCFeed, CoinExBTCFeed])
     for feed in manager.market_feeds:
         feed.last_check = time()
     bittrex, coinex = manager.market_feeds
     bittrex.rate = ExchangeRate(bittrex.market, 1.0, time())
     coinex.rate = ExchangeRate(coinex.market, 2.0, time())
     coinex.rate = ExchangeRate(coinex.market, 3.0, time())
     self.assertEqual(14.0,
                      manager.convert_currency("BTC", "LBC", Decimal(7.0)))
     coinex.rate.spot = 4.0
     self.assertEqual(17.5,
                      manager.convert_currency("BTC", "LBC", Decimal(7.0)))
 async def test_it_handles_feed_being_offline(self):
     class FakeFeed(MarketFeed):
         name = "fake"
         url = "http://impossi.bru"
     manager = ExchangeRateManager((FakeFeed,))
     manager.start()
     self.addCleanup(manager.stop)
     for feed in manager.market_feeds:
         self.assertFalse(feed.is_online)
         self.assertIsNone(feed.rate)
     await asyncio.wait_for(manager.wait(), 2)
     for feed in manager.market_feeds:
         self.assertFalse(feed.is_online)
         self.assertFalse(feed.has_rate)
Ejemplo n.º 4
0
 async def test_exchange_rate_manager(self):
     # TODO: re-enable cryptonator.com
     manager = ExchangeRateManager(FEEDS)
     manager.start()
     self.addCleanup(manager.stop)
     for feed in manager.market_feeds:
         self.assertFalse(feed.is_online)
         self.assertIsNone(feed.rate)
     await manager.wait()
     for feed in manager.market_feeds:
         self.assertTrue(feed.is_online)
         self.assertIsInstance(feed.rate, ExchangeRate)
     lbc = manager.convert_currency('USD', 'LBC', Decimal('0.01'))
     self.assertGreaterEqual(lbc, 0.1)
     self.assertLessEqual(lbc, 10.0)
 async def test_exchange_rate_manager(self):
     manager = ExchangeRateManager(FEEDS)
     manager.start()
     self.addCleanup(manager.stop)
     for feed in manager.market_feeds:
         self.assertFalse(feed.is_online)
         self.assertIsNone(feed.rate)
     await manager.wait()
     for feed in manager.market_feeds:
         self.assertTrue(feed.is_online)
         self.assertIsInstance(feed.rate, ExchangeRate)
         # print(f'{feed.name} - {feed.market} - {feed.rate.spot}')
     lbc = manager.convert_currency('USD', 'LBC', Decimal('1.0'))
     self.assertGreaterEqual(lbc, 2.0)
     self.assertLessEqual(lbc, 10.0)
     lbc = manager.convert_currency('BTC', 'LBC', Decimal('0.01'))
     self.assertGreaterEqual(lbc, 1_000)
     self.assertLessEqual(lbc, 4_000)
 async def test_exchange_rate_manager(self):
     manager = ExchangeRateManager(FEEDS)
     manager.start()
     self.addCleanup(manager.stop)
     for feed in manager.market_feeds:
         self.assertFalse(feed.is_online)
         self.assertIsNone(feed.rate)
     await manager.wait()
     failures = set()
     for feed in manager.market_feeds:
         if feed.is_online:
             self.assertIsInstance(feed.rate, ExchangeRate)
         else:
             failures.add(feed.name)
             self.assertFalse(feed.has_rate)
     self.assertLessEqual(len(failures), 1, f"feed failures: {failures}. Please check exchange rate feeds!")
     lbc = manager.convert_currency('USD', 'LBC', Decimal('1.0'))
     self.assertGreaterEqual(lbc, 2.0)
     self.assertLessEqual(lbc, 10.0)
     lbc = manager.convert_currency('BTC', 'LBC', Decimal('0.01'))
     self.assertGreaterEqual(lbc, 1_000)
     self.assertLessEqual(lbc, 4_000)
Ejemplo n.º 7
0
 def __init__(self, component_manager):
     super().__init__(component_manager)
     self.exchange_rate_manager = ExchangeRateManager()
 async def test_get_rate_failure_retrieved(self):
     manager = ExchangeRateManager([BadMarketFeed])
     manager.start()
     await asyncio.sleep(1)
     self.addCleanup(manager.stop)