updated exchange rate manager to use v3 bittrex API (old one is deprecated)
This commit is contained in:
parent
a8177ea7fe
commit
39e78ff17e
3 changed files with 8 additions and 26 deletions
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue