def test_public_rest_url(self):
     path_url = "TEST_PATH"
     domain = CONSTANTS.DEFAULT_DOMAIN
     expected_url = "https://" + CONSTANTS.REST_URL.format(
         CONSTANTS.PUBLIC_API_VERSION
     ) + f"/{CONSTANTS.PUBLIC_API_VERSION}/{path_url}"
     self.assertEqual(expected_url,
                      web_utils.public_rest_url(path_url, domain))
     self.assertEqual(
         CONSTANTS.REST_URL.format(CONSTANTS.PUBLIC_API_VERSION),
         web_utils.public_rest_url(path_url, domain, only_hostname=True))
Exemple #2
0
    def test_get_all_mid_prices(self, mock_api):
        url = web_utils.public_rest_url(
            path_url=CONSTANTS.TICKER_PRICE_CHANGE_PATH_URL,
            domain=self.domain)

        mock_response: List[Dict[str, Any]] = [
            {
                # Truncated Response
                "marketCode": self.ex_trading_pair,
                "last": "100",
            },
            {
                # Truncated Response for unrecognized pair
                "marketCode": "BCC-BTC",
                "last": "99",
            }
        ]

        mock_api.get(url, body=json.dumps(mock_response))

        result: Dict[str, float] = self.async_run_with_timeout(
            self.data_source.get_all_mid_prices())

        self.assertEqual(1, len(result))
        self.assertEqual(100, result[self.trading_pair])
Exemple #3
0
    def test_fetch_trading_pairs(self, mock_api):
        CoinflexAPIOrderBookDataSource._trading_pair_symbol_map = {}
        url = web_utils.public_rest_url(path_url=CONSTANTS.EXCHANGE_INFO_PATH_URL, domain=self.domain)

        mock_response: Dict[str, Any] = {
            "event": "markets",
            "timestamp": "1639598493658",
            "data": [
                {
                    "marketId": "2001000000000",
                    "marketCode": "BTC-USD",
                    "name": "BTC/USD",
                    "referencePair": "BTC/USD",
                    "base": "BTC",
                    "counter": "USD",
                    "type": "MARGIN",
                    "tickSize": "1",
                    "qtyIncrement": "0.001",
                    "marginCurrency": "USD",
                    "contractValCurrency": "BTC",
                    "upperPriceBound": "39203",
                    "lowerPriceBound": "36187",
                    "marketPrice": "37695",
                    "markPrice": None,
                    "listingDate": 1593316800000,
                    "endDate": 0,
                    "marketPriceLastUpdated": 1645547473153,
                    "markPriceLastUpdated": 0
                },
                {
                    "marketId": "34001000000000",
                    "marketCode": "LTC-USD",
                    "name": "LTC/USD",
                    "referencePair": "LTC/USD",
                    "base": "LTC",
                    "counter": "USD",
                    "type": "SPOT",
                    "tickSize": "0.1",
                    "qtyIncrement": "0.01",
                    "marginCurrency": "USD",
                    "contractValCurrency": "LTC",
                    "upperPriceBound": "114.2",
                    "lowerPriceBound": "97.2",
                    "marketPrice": "105.7",
                    "markPrice": None,
                    "listingDate": 1609765200000,
                    "endDate": 0,
                    "marketPriceLastUpdated": 1645547512308,
                    "markPriceLastUpdated": 0
                },
                {
                    "marketId": "4001000000000",
                    "marketCode": "ETH-USD",
                    "name": "ETH/USD",
                    "referencePair": "ETH/USD",
                    "base": "ETH",
                    "counter": "USD",
                    "type": "SPOT",
                    "tickSize": "0.1",
                    "qtyIncrement": "0.01",
                    "marginCurrency": "USD",
                    "contractValCurrency": "ETH",
                    "upperPriceBound": "2704.3",
                    "lowerPriceBound": "2496.1",
                    "marketPrice": "2600.2",
                    "markPrice": None,
                    "listingDate": 0,
                    "endDate": 0,
                    "marketPriceLastUpdated": 1645547505166,
                    "markPriceLastUpdated": 0
                },
            ]
        }

        mock_api.get(url, body=json.dumps(mock_response))

        result: Dict[str] = self.async_run_with_timeout(
            self.data_source.fetch_trading_pairs()
        )

        self.assertEqual(2, len(result))
        self.assertIn("ETH-USD", result)
        self.assertIn("LTC-USD", result)
        self.assertNotIn("BTC-USD", result)