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):
|
class BittrexFeed(MarketFeed):
|
||||||
name = "Bittrex"
|
name = "Bittrex"
|
||||||
market = "BTCLBC"
|
market = "BTCLBC"
|
||||||
url = "https://bittrex.com/api/v1.1/public/getmarkethistory"
|
url = "https://api.bittrex.com/v3/markets/LBC-BTC/ticker"
|
||||||
params = {'market': 'BTC-LBC', 'count': 50}
|
|
||||||
fee = 0.0025
|
fee = 0.0025
|
||||||
|
|
||||||
def get_rate_from_response(self, json_response):
|
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')
|
raise InvalidExchangeRateResponseError(self.name, 'result not found')
|
||||||
trades = json_response['result']
|
return 1.0 / float(json_response['lastTradeRate'])
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
class LBRYFeed(MarketFeed):
|
class LBRYFeed(MarketFeed):
|
||||||
|
|
|
@ -6,7 +6,6 @@ from lbry.extras.daemon.exchange_rate_manager import ExchangeRate, ExchangeRateM
|
||||||
class TestExchangeRateManager(AsyncioTestCase):
|
class TestExchangeRateManager(AsyncioTestCase):
|
||||||
async def test_exchange_rate_manager(self):
|
async def test_exchange_rate_manager(self):
|
||||||
# TODO: re-enable cryptonator.com
|
# TODO: re-enable cryptonator.com
|
||||||
# TODO: this uses real exchange rate feeds... update to use mocks
|
|
||||||
manager = ExchangeRateManager(FEEDS)
|
manager = ExchangeRateManager(FEEDS)
|
||||||
manager.start()
|
manager.start()
|
||||||
self.addCleanup(manager.stop)
|
self.addCleanup(manager.stop)
|
||||||
|
|
|
@ -117,20 +117,12 @@ class ExchangeRateTests(AsyncioTestCase):
|
||||||
def test_bittrex_feed_response(self):
|
def test_bittrex_feed_response(self):
|
||||||
feed = BittrexFeed()
|
feed = BittrexFeed()
|
||||||
out = feed.get_rate_from_response({
|
out = feed.get_rate_from_response({
|
||||||
"success": True,
|
"symbol": "LBC-BTC",
|
||||||
"message": "",
|
"lastTradeRate": "0.00000323",
|
||||||
"result": [
|
"bidRate": "0.00000322",
|
||||||
{
|
"askRate": "0.00000327"
|
||||||
'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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
self.assertEqual(1.0 / ((0.00090980+0.00686151) / (56.12611239+430.99988180)), out)
|
self.assertEqual(1.0 / 0.00000323, out)
|
||||||
with self.assertRaises(InvalidExchangeRateResponseError):
|
with self.assertRaises(InvalidExchangeRateResponseError):
|
||||||
feed.get_rate_from_response({})
|
feed.get_rate_from_response({})
|
||||||
with self.assertRaises(InvalidExchangeRateResponseError):
|
with self.assertRaises(InvalidExchangeRateResponseError):
|
||||||
|
|
Loading…
Add table
Reference in a new issue