add Bittrex feed as a redundant feed, add unit test for it

This commit is contained in:
Kay Kurokawa 2017-10-23 16:05:41 -04:00
parent 4411c5c202
commit 7e7931fbf1
2 changed files with 27 additions and 3 deletions

View file

@ -5,7 +5,6 @@ import json
from twisted.internet import defer, threads
from twisted.internet.task import LoopingCall
from lbrynet import conf
from lbrynet.core.Error import InvalidExchangeRateResponse
log = logging.getLogger(__name__)
@ -102,7 +101,7 @@ class BittrexFeed(MarketFeed):
self,
"BTCLBC",
"Bittrex",
conf.settings['bittrex_feed'],
"https://bittrex.com/api/v1.1/public/getmarkethistory",
{'market': 'BTC-LBC', 'count': 50},
BITTREX_FEE
)
@ -223,7 +222,7 @@ def get_default_market_feed(currency_pair):
class ExchangeRateManager(object):
def __init__(self):
self.market_feeds = [
LBRYioBTCFeed(), LBRYioFeed(), CryptonatorBTCFeed(), CryptonatorFeed()]
LBRYioBTCFeed(), LBRYioFeed(), BittrexFeed(), CryptonatorBTCFeed(), CryptonatorFeed()]
def start(self):
log.info("Starting exchange rate manager")

View file

@ -159,3 +159,28 @@ class CryptonatorBTCFeedTest(unittest.TestCase):
response = '{"success":true,"ticker":{}}'
with self.assertRaises(InvalidExchangeRateResponse):
out = yield feed._handle_response(response)
class BittrexFeedTest(unittest.TestCase):
@defer.inlineCallbacks
def test_handle_response(self):
feed = ExchangeRateManager.BittrexFeed()
response = '{"success":true,"message":"","result":[{"Id":6902471,"TimeStamp":"2017-02-2'\
'7T23: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","Qu'\
'antity":430.99988180,"Price":0.00001592,"Total":0.00686151,"FillType":"PARTIAL_FILL","Ord'\
'erType":"SELL"}]}'
out = yield feed._handle_response(response)
expected = 1.0 / ((0.00090980+0.00686151) / (56.12611239+430.99988180))
self.assertEqual(expected, out)
response = '{}'
with self.assertRaises(InvalidExchangeRateResponse):
out = yield feed._handle_response(response)
response = '{"success":true,"result":[]}'
with self.assertRaises(InvalidExchangeRateResponse):
out = yield feed._handle_response(response)