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_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_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 _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_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 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("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_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_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("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_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 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("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 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_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_list_pairs(self): pairs = SpTodayExchange().list_pairs self.assertEqual(len(pairs), 17) self.assertTrue(Pair(ECurrency("USD"), ECurrency("SYP")) in pairs) self.assertTrue(Pair(ECurrency("EUR"), ECurrency("SYP")) in pairs) self.assertFalse(Pair(ECurrency("EUR"), ECurrency("USD")) 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 _get_data(self) -> dict: try: response = requests.get( "https://api.bittrex.com/api/v1.1/public/getmarketsummaries") response.raise_for_status() data = response.json() except (requests.exceptions.RequestException, ValueError) as e: raise APIErrorException(e) try: schema = { "type": "object", "properties": { "success": { "type": "boolean" }, "result": { "type": "array", "items": { "type": "object", "properties": { "MarketName": { "type": "string" }, "High": { "type": ["number", "null"] }, "Low": { "type": ["number", "null"] }, "TimeStamp": { "type": "string" }, "Bid": { "type": ["number", "null"] }, "Ask": { "type": ["number", "null"] }, "PrevDay": { "type": ["number", "null"] }, }, "required": [ "MarketName", "High", "Low", "TimeStamp", "Bid", "Ask", "PrevDay", ], }, }, }, "required": ["success", "result"], } validate(data, schema) except ValidationError as e: raise APIErrorException(e) result = {} all_currency_codes = get_all_currency_codes() for x in data["result"]: # reverse to_currency, from_currency = x["MarketName"].upper().split("-") if not x["Bid"] or not x["Ask"]: if (to_currency in all_currency_codes and from_currency in all_currency_codes): logging.info("Bittrex no Bid Ask: %s", x) continue del x["MarketName"] result[Pair(ECurrency(from_currency), ECurrency(to_currency))] = x return result
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_pairs(self): pairs = FixerExchange().list_pairs self.assertEqual(len(pairs), 168) self.assertTrue(Pair(ECurrency("EUR"), ECurrency("USD")) in pairs)
def test_get_pair_info_no_pair(self): pair = Pair(ECurrency("MONEY"), ECurrency("USD")) with self.assertRaises(PairNotExistsException): OpenExchangeRatesExchange().get_pair_info(pair)
def _get_data(self) -> dict: try: response = requests.get("https://api.bitkub.com/api/market/ticker") response.raise_for_status() data = response.json() except (requests.exceptions.RequestException, ValueError) as e: raise APIErrorException(e) try: schema = { "type": "object", "patternProperties": { r"^.*_.*$": { "type": "object", "properties": { "lowestAsk": { "type": "number" }, "highestBid": { "type": "number" }, "isFrozen": { "type": "number" }, "low24hr": { "type": "number" }, "high24hr": { "type": "number" }, }, "required": [ "lowestAsk", "highestBid", "isFrozen", "low24hr", "high24hr", ], }, "not": { "required": ["error", ""] }, }, } validate(data, schema) except ValidationError as e: raise APIErrorException(e) result = {} all_currency_codes = get_all_currency_codes() for currencies, info in data.items(): if info["isFrozen"]: logging.info("Bitkub isFrozen: %s", currencies) continue # reverse to_currency, from_currency = currencies.split("_") if not info["lowestAsk"] or not info["highestBid"]: if (to_currency in all_currency_codes and from_currency in all_currency_codes): logging.info("Bitkub no Bid Ask: %s", info) continue result[Pair(ECurrency(from_currency), ECurrency(to_currency))] = info return result
def test_null_bid_ask(self): pair = Pair(ECurrency("BTC"), ECurrency("USD")) with self.assertRaises(PairNotExistsException): BittrexExchange().get_pair_info(pair)
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_list_pairs(self): pairs = BittrexExchange().list_pairs self.assertEqual(len(pairs), 331) self.assertTrue(Pair(ECurrency("BTC"), ECurrency("USD")) in pairs) self.assertFalse(Pair(ECurrency("USD"), ECurrency("BTC")) in pairs)