def test_validateOrder(self): info = liqui_client.APIInfo(self.connection) for pair_name, pair_data in info.pairs.items(): for t in ("buy", "sell"): info.validate_order(pair_name, t, pair_data.min_price, pair_data.min_amount) info.validate_order(pair_name, t, pair_data.max_price, pair_data.min_amount) self.assertRaises( liqui_client.InvalidTradeAmountException, info.validate_order, pair_name, t, pair_data.min_price, pair_data.min_amount - decimal.Decimal("0.0001")) self.assertRaises( liqui_client.InvalidTradePriceException, info.validate_order, pair_name, t, pair_data.min_price - decimal.Decimal("0.0001"), pair_data.min_amount) self.assertRaises( liqui_client.InvalidTradePriceException, info.validate_order, pair_name, t, pair_data.max_price + decimal.Decimal("0.0001"), pair_data.min_amount) self.assertRaises(liqui_client.InvalidTradePairException, info.validate_order, "foo_bar", "buy", decimal.Decimal("1.0"), decimal.Decimal("1.0")) self.assertRaises(liqui_client.InvalidTradeTypeException, info.validate_order, "btc_usd", "foo", decimal.Decimal("1.0"), decimal.Decimal("1.0"))
def test_truncateAmount(self): info = liqui_client.APIInfo(self.connection) for i in info.pairs.values(): d = i.decimal_places self.assertEqual(i.truncate_amount(1.12), liqui_client.truncateAmountDigits(1.12, d)) self.assertEqual(i.truncate_amount(44.0), liqui_client.truncateAmountDigits(44.0, d))
def test_getTicker(self): connection = liqui_client.BTCEConnection() info = liqui_client.APIInfo(connection) for pair in info.pair_names: liqui_client.getTicker(pair, connection, info) liqui_client.getTicker(pair, connection) liqui_client.getTicker(pair, info=info) liqui_client.getTicker(pair)
def test_currency_sets(self): currencies_from_pairs = set() info = liqui_client.APIInfo(self.connection) for pair in info.pair_names: c1, c2 = pair.split("_") currencies_from_pairs.add(c1) currencies_from_pairs.add(c2) self.assertEqual(len(info.currencies), len(set(info.currencies))) self.assertEqual(currencies_from_pairs, set(info.currencies))
def test_scrape_main_page(self): with liqui_client.BTCEConnection() as connection: info = liqui_client.APIInfo(connection) mainPage = info.scrapeMainPage() for message in mainPage.messages: msgId, user, time, text = message assert type(time) is datetime if sys.version_info[0] == 2: # python2.x assert type(msgId) in (str, unicode) assert type(user) in (str, unicode) assert type(text) in (str, unicode) else: # python3.x self.assertIs(type(msgId), str) self.assertIs(type(user), str) self.assertIs(type(text), str)
#!/usr/bin/env python import liqui_client btce_domain = "api.liqui.io" with liqui_client.BTCEConnection(btce_domain) as connection: info = liqui_client.APIInfo(connection) mainPage = info.scrapeMainPage() for message in mainPage.messages: msgId, user, time, text = message print("%s %s: %s" % (time, user, text)) print() print("dev online: %s" % ('yes' if mainPage.devOnline else 'no')) print("support online: %s" % ('yes' if mainPage.supportOnline else 'no')) print("admin online: %s" % ('yes' if mainPage.adminOnline else 'no'))
def test_validate_pair_suggest(self): info = liqui_client.APIInfo(self.connection) self.assertRaises(liqui_client.InvalidTradePairException, info.validate_pair, "usd_btc")
def test_validatePair(self): info = liqui_client.APIInfo(self.connection) for pair in info.pair_names: info.validate_pair(pair) self.assertRaises(liqui_client.InvalidTradePairException, info.validate_pair, "not_a_real_pair")
def test_pair_identity(self): info = liqui_client.APIInfo(self.connection) self.assertEqual(len(info.pair_names), len(set(info.pair_names))) self.assertEqual(set(info.pairs.keys()), set(info.pair_names))