From 39e78ff17eb92504e3489af14d0938bffbc97da7 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Wed, 3 Feb 2021 10:10:18 -0500 Subject: [PATCH] updated exchange rate manager to use v3 bittrex API (old one is deprecated) --- lbry/extras/daemon/exchange_rate_manager.py | 15 +++------------ .../other/test_exchange_rate_manager.py | 1 - .../test_exchange_rate_manager.py | 18 +++++------------- 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/lbry/extras/daemon/exchange_rate_manager.py b/lbry/extras/daemon/exchange_rate_manager.py index eb2de04f9..ccc3c77bb 100644 --- a/lbry/extras/daemon/exchange_rate_manager.py +++ b/lbry/extras/daemon/exchange_rate_manager.py @@ -107,22 +107,13 @@ class MarketFeed: class BittrexFeed(MarketFeed): name = "Bittrex" market = "BTCLBC" - url = "https://bittrex.com/api/v1.1/public/getmarkethistory" - params = {'market': 'BTC-LBC', 'count': 50} + url = "https://api.bittrex.com/v3/markets/LBC-BTC/ticker" fee = 0.0025 def get_rate_from_response(self, json_response): - if 'result' not in json_response: + if 'lastTradeRate' not in json_response: raise InvalidExchangeRateResponseError(self.name, 'result not found') - trades = json_response['result'] - if len(trades) == 0: - raise InvalidExchangeRateResponseError(self.name, 'trades not found') - totals = sum([i['Total'] for i in trades]) - qtys = sum([i['Quantity'] for i in trades]) - if totals <= 0 or qtys <= 0: - raise InvalidExchangeRateResponseError(self.name, 'quantities were not positive') - vwap = totals / qtys - return float(1.0 / vwap) + return 1.0 / float(json_response['lastTradeRate']) class LBRYFeed(MarketFeed): diff --git a/tests/integration/other/test_exchange_rate_manager.py b/tests/integration/other/test_exchange_rate_manager.py index c9664f12c..6688d4a14 100644 --- a/tests/integration/other/test_exchange_rate_manager.py +++ b/tests/integration/other/test_exchange_rate_manager.py @@ -6,7 +6,6 @@ from lbry.extras.daemon.exchange_rate_manager import ExchangeRate, ExchangeRateM class TestExchangeRateManager(AsyncioTestCase): async def test_exchange_rate_manager(self): # TODO: re-enable cryptonator.com - # TODO: this uses real exchange rate feeds... update to use mocks manager = ExchangeRateManager(FEEDS) manager.start() self.addCleanup(manager.stop) diff --git a/tests/unit/lbrynet_daemon/test_exchange_rate_manager.py b/tests/unit/lbrynet_daemon/test_exchange_rate_manager.py index 3a88436f1..6d7bf4e6e 100644 --- a/tests/unit/lbrynet_daemon/test_exchange_rate_manager.py +++ b/tests/unit/lbrynet_daemon/test_exchange_rate_manager.py @@ -117,20 +117,12 @@ class ExchangeRateTests(AsyncioTestCase): def test_bittrex_feed_response(self): feed = BittrexFeed() out = feed.get_rate_from_response({ - "success": True, - "message": "", - "result": [ - { - 'Id': 6902471, 'TimeStamp': '2017-02-27T23:41:52.213', 'Quantity': 56.12611239, - "Price": 0.00001621, "Total": 0.00090980, "FillType": "PARTIAL_FILL", "OrderType": "SELL" - }, - { - "Id": 6902403, "TimeStamp": "2017-02-27t23:31:40.463", "Quantity": 430.99988180, - "Price": 0.00001592, "Total": 0.00686151, "FillType": "PARTIAL_FILL", "OrderType": "SELL" - } - ] + "symbol": "LBC-BTC", + "lastTradeRate": "0.00000323", + "bidRate": "0.00000322", + "askRate": "0.00000327" }) - self.assertEqual(1.0 / ((0.00090980+0.00686151) / (56.12611239+430.99988180)), out) + self.assertEqual(1.0 / 0.00000323, out) with self.assertRaises(InvalidExchangeRateResponseError): feed.get_rate_from_response({}) with self.assertRaises(InvalidExchangeRateResponseError):