def test_is_currency_exists(self): exchange = SatangExchange() self.assertTrue(exchange.is_currency_exists(ECurrency(code="BTC"))) self.assertTrue(exchange.is_currency_exists(ECurrency(code="THB"))) self.assertFalse(exchange.is_currency_exists(ECurrency(code="thb"))) self.assertFalse(exchange.is_currency_exists(ECurrency(code="MONEY")))
def test_is_currency_exists(self): exchange = OpenExchangeRatesExchange() self.assertTrue(exchange.is_currency_exists(ECurrency(code="EUR"))) self.assertTrue(exchange.is_currency_exists(ECurrency(code="USD"))) self.assertFalse(exchange.is_currency_exists(ECurrency(code="usd"))) self.assertFalse(exchange.is_currency_exists(ECurrency(code="MONEY")))
def list_pairs(self) -> Tuple[Pair]: currencies = self._get_data["rates"].keys() base_currency = self._get_data["base"].upper() return tuple( Pair(ECurrency(base_currency), ECurrency(x.upper())) for x in currencies )
def _get_data(self) -> dict: try: response = requests.get("https://api.tdax.com/api/orderbook-tickers/") response.raise_for_status() data = response.json() except (requests.exceptions.RequestException, ValueError) as e: raise APIErrorException(e) try: # TODO: [bid][price] [ask][price] schema = { "type": "object", "patternProperties": { r"^.*_.*$": { "type": "object", "properties": { "bid": {"type": "object"}, "ask": {"type": "object"}, }, "required": ["bid", "ask"], }, }, } validate(data, schema) except ValidationError as e: raise APIErrorException(e) result = {} for currencies, info in data.items(): from_currency, to_currency = currencies.split("_") result[Pair(ECurrency(from_currency), ECurrency(to_currency))] = info return result
def list_currencies(self) -> Tuple[ECurrency]: currencies = self._get_data["rates"].keys() base_currency = self._get_data["base"].upper() return (ECurrency(base_currency),) + tuple( ECurrency(x.upper()) for x in currencies )
def test_is_currency_exists(self): exchange = BittrexExchange() self.assertTrue(exchange.is_currency_exists(ECurrency(code="BTC"))) self.assertTrue(exchange.is_currency_exists(ECurrency(code="USD"))) self.assertFalse(exchange.is_currency_exists(ECurrency(code="usd"))) self.assertFalse(exchange.is_currency_exists(ECurrency(code="MONEY")))
def test_is_currency_exists(self): exchange = SpTodayExchange() self.assertTrue(exchange.is_currency_exists(ECurrency(code="SYP"))) self.assertTrue(exchange.is_currency_exists(ECurrency(code="USD"))) self.assertTrue(exchange.is_currency_exists(ECurrency(code="EUR"))) self.assertFalse(exchange.is_currency_exists(ECurrency(code="thb"))) self.assertFalse(exchange.is_currency_exists(ECurrency(code="MONEY")))
def test_get_pair_info(self): pair = Pair(ECurrency("EUR"), ECurrency("USD")) self.assertEqual( FixerExchange().get_pair_info(pair), PairData( pair=pair, rate=Decimal("1.137314"), rate_open=None, last_trade_at=datetime(2019, 3, 21, 20, 47, 5), ), )
def test_get_pair_info(self): pair = Pair(ECurrency("USD"), ECurrency("SYP")) self.assertEqual( SpTodayExchange().get_pair_info(pair), PairData( pair=pair, rate=Decimal("2105"), rate_open=None, last_trade_at=datetime(2019, 3, 17, 22, 14, 15, 0), ), )
def test_get_pair_info(self): pair = Pair(ECurrency("USD"), ECurrency("EUR")) self.assertEqual( OpenExchangeRatesExchange().get_pair_info(pair), PairData( pair=pair, rate=Decimal("0.8792"), rate_open=None, last_trade_at=datetime(2019, 3, 21, 21, 0), ), )
def test_get_pair_info(self): pair = Pair(ECurrency("BTC"), ECurrency("USD")) self.assertEqual( BitfinexExchange().get_pair_info(pair), PairData( pair=pair, rate=Decimal("3996.05"), rate_open=None, low24h=Decimal("3850.0"), high24h=Decimal("4021.0"), last_trade_at=datetime(2019, 3, 9, 11, 21, 12, 996645), ), )
def test_get_pair_info(self): pair = Pair(ECurrency("BTC"), ECurrency("THB")) self.assertEqual( SatangExchange().get_pair_info(pair), PairData( pair=pair, rate=Decimal("304799.5"), last_trade_at=datetime(2020, 2, 17, 22, 14, 15), rate_open=None, low24h=None, high24h=None, ), )
def test_get_pair_info(self): pair = Pair(ECurrency("BTC"), ECurrency("USD")) self.assertEqual( BittrexExchange().get_pair_info(pair), PairData( pair=pair, rate=Decimal("3909.439"), rate_open=Decimal("3879.0"), low24h=Decimal("3773.806"), high24h=Decimal("3923.994"), last_trade_at=datetime(2019, 3, 9, 13, 47, 19, 0), ), )
def test_get_pair_info(self): pair = Pair(ECurrency("BTC"), ECurrency("THB")) self.assertEqual( BitkubExchange().get_pair_info(pair), PairData( pair=pair, rate=Decimal("300353.515"), rate_open=None, low24h=Decimal("281470"), high24h=Decimal("304000"), last_trade_at=datetime(2019, 3, 17, 22, 14, 15, 0), ), )
def test_null_high_low(self): pair = Pair(ECurrency("BTC"), ECurrency("USD")) self.assertEqual( BittrexExchange().get_pair_info(pair), PairData( pair=pair, rate=Decimal("5132.308"), rate_open=Decimal("5001.301"), low24h=None, high24h=None, last_trade_at=datetime(2019, 4, 7, 7, 54, 34), ), )
def list_pairs(self) -> Tuple[Pair]: pairs = set() for x in self._get_pairs: x = x.upper() if ":" in x: from_currency, to_currency = x.split(":") else: from_currency, to_currency = x[:3], x[3:] pairs.add(Pair(ECurrency(from_currency), ECurrency(to_currency))) return tuple(pairs)
def test_is_pair_exists(self): exchange = SpTodayExchange() self.assertTrue( exchange.is_pair_exists(Pair(ECurrency("USD"), ECurrency("SYP")))) self.assertFalse( exchange.is_pair_exists(Pair(ECurrency("SYP"), ECurrency("EUR")))) self.assertFalse( exchange.is_pair_exists(Pair(ECurrency("usd"), ECurrency("syp")))) self.assertFalse( exchange.is_pair_exists(Pair(ECurrency("syp"), ECurrency("MONEY"))))
def test_reverse_pair_data(self): pair_data = PairData( pair=Pair(ECurrency("BTC"), ECurrency("USD")), rate=Decimal("1") / Decimal("3"), last_trade_at=datetime(2019, 3, 9, 12), rate_open=Decimal("1") / Decimal("2"), low24h=Decimal("1") / Decimal("4"), high24h=Decimal("1") / Decimal("8"), ) pair_data_reversed = PairData( pair=Pair(ECurrency("USD"), ECurrency("BTC")), rate=Decimal("3"), last_trade_at=datetime(2019, 3, 9, 12), rate_open=Decimal("2"), low24h=Decimal("4"), high24h=Decimal("8"), ) self.assertEqual(reverse_pair_data(pair_data), pair_data_reversed)
def test_ok(self): pair_data = PairData( pair=Pair(ECurrency("BTC"), ECurrency("USD")), rate=Decimal("1") / Decimal("3"), last_trade_at=datetime(2019, 3, 9, 12), rate_open=Decimal("1") / Decimal("2"), low24h=Decimal("1") / Decimal("4"), high24h=Decimal("1") / Decimal("8"), ) rate_obj = rate_from_pair_data(pair_data, exchange_id=1) inst = inspect(rate_obj) self.assertSetEqual( {c_attr.key for c_attr in inst.mapper.column_attrs}, { "id", "exchange_id", "from_currency_id", "to_currency_id", "rate", "rate_open", "low24h", "high24h", "last_trade_at", "created_at", "modified_at", }, ) self.assertEqual(rate_obj.exchange_id, 1) self.assertEqual(rate_obj.from_currency.code, pair_data.pair.from_currency.code) self.assertEqual(rate_obj.to_currency.code, pair_data.pair.to_currency.code) self.assertEqual(rate_obj.rate, pair_data.rate) self.assertEqual(rate_obj.rate_open, pair_data.rate_open) self.assertEqual(rate_obj.low24h, pair_data.low24h) self.assertEqual(rate_obj.high24h, pair_data.high24h) self.assertEqual(rate_obj.last_trade_at, pair_data.last_trade_at)
def test_is_pair_exists(self): exchange = BittrexExchange() self.assertTrue( exchange.is_pair_exists(Pair(ECurrency("BTC"), ECurrency("USD"))) ) self.assertFalse( exchange.is_pair_exists(Pair(ECurrency("USD"), ECurrency("BTC"))) ) self.assertFalse( exchange.is_pair_exists(Pair(ECurrency("usd"), ECurrency("BTC"))) ) self.assertFalse( exchange.is_pair_exists(Pair(ECurrency("usd"), ECurrency("MONEY"))) )
def test_is_pair_exists(self): exchange = SatangExchange() self.assertTrue( exchange.is_pair_exists(Pair(ECurrency("BTC"), ECurrency("THB"))) ) self.assertFalse( exchange.is_pair_exists(Pair(ECurrency("THB"), ECurrency("BTC"))) ) self.assertFalse( exchange.is_pair_exists(Pair(ECurrency("thb"), ECurrency("BTC"))) ) self.assertFalse( exchange.is_pair_exists(Pair(ECurrency("btc"), ECurrency("MONEY"))) )
def test_is_pair_exists(self): exchange = FixerExchange() self.assertTrue( exchange.is_pair_exists(Pair(ECurrency("EUR"), ECurrency("USD")))) self.assertFalse( exchange.is_pair_exists(Pair(ECurrency("eur"), ECurrency("USD")))) self.assertFalse( exchange.is_pair_exists(Pair(ECurrency("eur"), ECurrency("MONEY"))))
def test_is_pair_exists(self): exchange = OpenExchangeRatesExchange() self.assertTrue( exchange.is_pair_exists(Pair(ECurrency("USD"), ECurrency("EUR")))) self.assertFalse( exchange.is_pair_exists(Pair(ECurrency("usd"), ECurrency("EUR")))) self.assertFalse( exchange.is_pair_exists(Pair(ECurrency("USD"), ECurrency("MONEY"))))
def test_list_pairs(self): pairs = OpenExchangeRatesExchange().list_pairs self.assertEqual(len(pairs), 171) self.assertTrue(Pair(ECurrency("USD"), ECurrency("EUR")) in pairs)
def test_reverse_pair(self): pair = Pair(ECurrency("BTC"), ECurrency("USD")) reversed_pair = Pair(ECurrency("USD"), ECurrency("BTC")) self.assertEqual(reverse_pair(pair), reversed_pair)
def test_get_pair_info_no_pair(self): pair = Pair(ECurrency("USD"), ECurrency("BTC")) with self.assertRaises(PairNotExistsException): SatangExchange().get_pair_info(pair)
def test_list_pairs(self): pairs = SatangExchange().list_pairs self.assertEqual(len(pairs), 11) self.assertTrue(Pair(ECurrency("BTC"), ECurrency("THB")) in pairs) self.assertFalse(Pair(ECurrency("THB"), ECurrency("BTC")) in pairs)
def test_list_currencies(self): currencies = SatangExchange().list_currencies self.assertEqual(len(currencies), 12) self.assertTrue(ECurrency(code="BTC") in currencies) self.assertTrue(ECurrency(code="THB") in currencies)
def test_list_currencies(self): currencies = OpenExchangeRatesExchange().list_currencies self.assertEqual(len(currencies), 172) self.assertTrue(ECurrency(code="EUR") in currencies) self.assertTrue(ECurrency(code="USD") in currencies)
def test_get_pair_info_no_pair(self): pair = Pair(ECurrency("MONEY"), ECurrency("USD")) with self.assertRaises(PairNotExistsException): OpenExchangeRatesExchange().get_pair_info(pair)