Example #1
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_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)
Example #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)