def test_invalid_rates(self): with self.assertRaises(AssertionError): ExchangeRateManager.ExchangeRate('USDBTC', 0, util.DEFAULT_ISO_TIME) with self.assertRaises(AssertionError): ExchangeRateManager.ExchangeRate('USDBTC', -1, util.DEFAULT_ISO_TIME)
def get_test_daemon(data_rate=None, generous=True, with_fee=False): if data_rate is None: data_rate = conf.ADJUSTABLE_SETTINGS['data_rate'][1] rates = { 'BTCLBC': {'spot': 3.0, 'ts': util.DEFAULT_ISO_TIME + 1}, 'USDBTC': {'spot': 2.0, 'ts': util.DEFAULT_ISO_TIME + 2} } daemon = LBRYDaemon(None, None) daemon.session = mock.Mock(spec=Session.Session) daemon.exchange_rate_manager = ExchangeRateManager.DummyExchangeRateManager(rates) base_prm = PaymentRateManager.BasePaymentRateManager(rate=data_rate) prm = PaymentRateManager.NegotiatedPaymentRateManager(base_prm, DummyBlobAvailabilityTracker(), generous=generous) daemon.session.payment_rate_manager = prm metadata = { "author": "fake author", "content_type": "fake/format", "description": "fake description", "license": "fake license", "license_url": "fake license url", "nsfw": False, "sources": { "lbry_sd_hash": "d2b8b6e907dde95245fe6d144d16c2fdd60c4e0c6463ec98b85642d06d8e9414e8fcfdcb7cb13532ec5454fb8fe7f280" }, "thumbnail": "fake thumbnail", "title": "fake title", "ver": "0.0.3" } if with_fee: metadata.update( {"fee": {"USD": {"address": "bQ6BGboPV2SpTMEP7wLNiAcnsZiH8ye6eA", "amount": 0.75}}}) daemon._resolve_name = lambda _: defer.succeed(metadata) return daemon
def test_handle_response(self): feed = ExchangeRateManager.GoogleBTCFeed() response = '// [ { "id": "-2001" ,"t" : "USDBTC" ,"e" : "CURRENCY" ,"l" : "0.0008" ,"l_fix" : "" ,"l_cur" : "" ,"s": "0" ,"ltt":"" ,"lt" : "Feb 27, 10:21PM GMT" ,"lt_dts" : "2017-02-27T22:21:39Z" ,"c" : "-0.00001" ,"c_fix" : "" ,"cp" : "-0.917" ,"cp_fix" : "" ,"ccol" : "chr" ,"pcls_fix" : "" } ]' out = yield feed._handle_response(response) self.assertEqual(0.0008, out) # check negative trade price throws exception response = '// [ { "id": "-2001" ,"t" : "USDBTC" ,"e" : "CURRENCY" ,"l" : "-0.0008" ,"l_fix" : "" ,"l_cur" : "" ,"s": "0" ,"ltt":"" ,"lt" : "Feb 27, 10:21PM GMT" ,"lt_dts" : "2017-02-27T22:21:39Z" ,"c" : "-0.00001" ,"c_fix" : "" ,"cp" : "-0.917" ,"cp_fix" : "" ,"ccol" : "chr" ,"pcls_fix" : "" } ]' with self.assertRaises(InvalidExchangeRateResponse): out = yield feed._handle_response(response)
def test_fee_converts_to_lbc(self): fee_dict = { 'USD': { 'amount': 10.0, 'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9" } } rates = { 'BTCLBC': {'spot': 3.0, 'ts': util.DEFAULT_ISO_TIME + 1}, 'USDBTC': {'spot': 2.0, 'ts': util.DEFAULT_ISO_TIME + 2} } manager = ExchangeRateManager.DummyExchangeRateManager(rates) result = manager.to_lbc(fee_dict).amount self.assertEqual(60.0, result)
def test_handle_response(self): feed = ExchangeRateManager.LBRYioFeed() 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 / 5.065289549855739e-05 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)
def test_handle_response(self): feed = ExchangeRateManager.BittrexFeed() 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"}]}' 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)
def test_fee_converts_to_lbc(self): fee_dict = { 'USD': { 'amount': 10.0, 'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9" } } rates = { 'BTCLBC': { 'spot': 3.0, 'ts': 2 }, 'USDBTC': { 'spot': 2.0, 'ts': 3 } } manager = ExchangeRateManager.DummyExchangeRateManager(rates) self.assertEqual(60.0, manager.to_lbc(fee_dict).amount)
def __init__(self, market_feeds, rates): self.market_feeds = market_feeds for feed in self.market_feeds: feed.rate = ERM.ExchangeRate(feed.market, rates[feed.market]['spot'], rates[feed.market]['ts'])