Merge pull request #594 from lbryio/use-lbryio-price-api

use lbryio api for price data instead of bittrex
This commit is contained in:
Jack Robison 2017-04-07 20:13:55 -04:00 committed by GitHub
commit c0ccfe2046
5 changed files with 27 additions and 15 deletions

View file

@ -19,6 +19,8 @@ at anytime.
### Changed ### Changed
* Use `uri` instead of `name` for `get`, remove explicit `claim_id` parameter * Use `uri` instead of `name` for `get`, remove explicit `claim_id` parameter
* Increase default download timeout * Increase default download timeout
* Use lbry.io api for exchange rate data
*
### Fixed ### Fixed
* *

View file

@ -153,7 +153,6 @@ ADJUSTABLE_SETTINGS = {
'api_host': (str, 'localhost'), 'api_host': (str, 'localhost'),
'api_port': (int, 5279), 'api_port': (int, 5279),
'bittrex_feed': (str, 'https://bittrex.com/api/v1.1/public/getmarkethistory'),
'cache_time': (int, 150), 'cache_time': (int, 150),
'check_ui_requirements': (bool, True), 'check_ui_requirements': (bool, True),
'data_dir': (str, default_data_dir), 'data_dir': (str, default_data_dir),

View file

@ -111,6 +111,24 @@ class BittrexFeed(MarketFeed):
return defer.succeed(float(1.0 / vwap)) return defer.succeed(float(1.0 / vwap))
class LBRYioFeed(MarketFeed):
def __init__(self):
MarketFeed.__init__(
self,
"BTCLBC",
"lbry.io",
"https://api.lbry.io/lbc/exchange_rate",
{},
0.0,
)
def _handle_response(self, response):
json_response = json.loads(response)
if 'data' not in json_response:
raise InvalidExchangeRateResponse(self.name, 'result not found')
return defer.succeed(1.0 / json_response['data']['lbc_btc'])
class GoogleBTCFeed(MarketFeed): class GoogleBTCFeed(MarketFeed):
def __init__(self): def __init__(self):
MarketFeed.__init__( MarketFeed.__init__(
@ -144,7 +162,7 @@ def get_default_market_feed(currency_pair):
if currencies == ("USD", "BTC"): if currencies == ("USD", "BTC"):
return GoogleBTCFeed() return GoogleBTCFeed()
elif currencies == ("BTC", "LBC"): elif currencies == ("BTC", "LBC"):
return BittrexFeed() return LBRYioFeed()
class ExchangeRateManager(object): class ExchangeRateManager(object):

View file

@ -44,10 +44,11 @@ class WalletTest(unittest.TestCase):
def not_enough_funds_send_name_claim(self, name, val, amount): def not_enough_funds_send_name_claim(self, name, val, amount):
claim_out = {'success':False, 'reason':'Not enough funds'} claim_out = {'success':False, 'reason':'Not enough funds'}
return claim_out return claim_out
MocLbryumWallet._send_name_claim = not_enough_funds_send_name_claim MocLbryumWallet._send_name_claim = not_enough_funds_send_name_claim
wallet = MocLbryumWallet() wallet = MocLbryumWallet()
d = wallet.claim_name('test', 1, test_claim_dict) d = wallet.claim_name('test', 1, test_claim_dict)
self.assertFailure(d,Exception) self.assertFailure(d, Exception)
return d return d
def test_successful_send_name_claim(self): def test_successful_send_name_claim(self):

View file

@ -54,22 +54,14 @@ class GoogleBTCFeedTest(unittest.TestCase):
out = yield feed._handle_response(response) out = yield feed._handle_response(response)
class LBRYioFeedTest(unittest.TestCase):
class BittrexFeedTest(unittest.TestCase):
def setUp(self):
conf.initialize_settings()
def tearDown(self):
conf.settings = None
@defer.inlineCallbacks @defer.inlineCallbacks
def test_handle_response(self): def test_handle_response(self):
feed = ExchangeRateManager.BittrexFeed() feed = ExchangeRateManager.LBRYioFeed()
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"}]}' response ='{\"data\": {\"fresh\": 0, \"lbc_usd\": 0.05863062523378918, \"lbc_btc\": 5.065289549855739e-05, \"btc_usd\": 1157.498}, \"success\": true, \"error\": null}'
out = yield feed._handle_response(response) out = yield feed._handle_response(response)
expected= 1.0 / ((0.00090980+0.00686151) / (56.12611239+430.99988180)) expected = 1.0 / 5.065289549855739e-05
self.assertEqual(expected, out) self.assertEqual(expected, out)
response='{}' response='{}'