forked from LBRYCommunity/lbry-sdk
use lbryio api for price data instead of bittrex
This commit is contained in:
parent
6ed2c5831e
commit
40374ec202
5 changed files with 27 additions and 15 deletions
|
@ -19,6 +19,8 @@ at anytime.
|
|||
### Changed
|
||||
* Use `uri` instead of `name` for `get`, remove explicit `claim_id` parameter
|
||||
* Increase default download timeout
|
||||
* Use lbry.io api for exchange rate data
|
||||
*
|
||||
|
||||
### Fixed
|
||||
*
|
||||
|
|
|
@ -153,7 +153,6 @@ ADJUSTABLE_SETTINGS = {
|
|||
'api_host': (str, 'localhost'),
|
||||
|
||||
'api_port': (int, 5279),
|
||||
'bittrex_feed': (str, 'https://bittrex.com/api/v1.1/public/getmarkethistory'),
|
||||
'cache_time': (int, 150),
|
||||
'check_ui_requirements': (bool, True),
|
||||
'data_dir': (str, default_data_dir),
|
||||
|
|
|
@ -111,6 +111,24 @@ class BittrexFeed(MarketFeed):
|
|||
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):
|
||||
def __init__(self):
|
||||
MarketFeed.__init__(
|
||||
|
@ -144,7 +162,7 @@ def get_default_market_feed(currency_pair):
|
|||
if currencies == ("USD", "BTC"):
|
||||
return GoogleBTCFeed()
|
||||
elif currencies == ("BTC", "LBC"):
|
||||
return BittrexFeed()
|
||||
return LBRYioFeed()
|
||||
|
||||
|
||||
class ExchangeRateManager(object):
|
||||
|
|
|
@ -44,10 +44,11 @@ class WalletTest(unittest.TestCase):
|
|||
def not_enough_funds_send_name_claim(self, name, val, amount):
|
||||
claim_out = {'success':False, 'reason':'Not enough funds'}
|
||||
return claim_out
|
||||
|
||||
MocLbryumWallet._send_name_claim = not_enough_funds_send_name_claim
|
||||
wallet = MocLbryumWallet()
|
||||
d = wallet.claim_name('test', 1, test_claim_dict)
|
||||
self.assertFailure(d,Exception)
|
||||
self.assertFailure(d, Exception)
|
||||
return d
|
||||
|
||||
def test_successful_send_name_claim(self):
|
||||
|
|
|
@ -54,22 +54,14 @@ class GoogleBTCFeedTest(unittest.TestCase):
|
|||
out = yield feed._handle_response(response)
|
||||
|
||||
|
||||
|
||||
|
||||
class BittrexFeedTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
conf.initialize_settings()
|
||||
|
||||
def tearDown(self):
|
||||
conf.settings = None
|
||||
|
||||
class LBRYioFeedTest(unittest.TestCase):
|
||||
@defer.inlineCallbacks
|
||||
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)
|
||||
expected= 1.0 / ((0.00090980+0.00686151) / (56.12611239+430.99988180))
|
||||
expected = 1.0 / 5.065289549855739e-05
|
||||
self.assertEqual(expected, out)
|
||||
|
||||
response='{}'
|
||||
|
|
Loading…
Reference in a new issue