def test_get_btcusdt_when_loaded_returns_expected_instrument(self):
        # Arrange
        mock_client = MagicMock()
        mock_client.name = "Binance"

        with open(TEST_PATH + "res_instruments.json") as response:
            instruments = json.load(response)

        mock_client.markets = instruments

        provider = CCXTInstrumentProvider(client=mock_client)
        provider.load_all()

        symbol = Symbol("BTC/USDT", Venue("BINANCE"))

        # Act
        instrument = provider.get(symbol)

        # Assert
        self.assertEqual(Instrument, type(instrument))
        self.assertEqual(AssetClass.CRYPTO, instrument.asset_class)
        self.assertEqual(AssetType.SPOT, instrument.asset_type)
        self.assertEqual(BTC, instrument.base_currency)
        self.assertEqual(USDT, instrument.quote_currency)
        self.assertEqual(USDT, instrument.settlement_currency)
    def test_get_btcusdt_when_loaded_returns_expected_instrument(self):
        # Arrange
        with open(TEST_PATH + "markets.json") as response:
            markets = json.load(response)

        with open(TEST_PATH + "currencies.json") as response:
            currencies = json.load(response)

        mock_client = MagicMock()
        mock_client.name = "Binance"
        mock_client.precisionMode = 2
        mock_client.markets = markets
        mock_client.currencies = currencies

        provider = CCXTInstrumentProvider(client=mock_client)
        provider.load_all()

        instrument_id = InstrumentId(Symbol("BTC/USDT"), Venue("BINANCE"))

        # Act
        instrument = provider.find(instrument_id)

        # Assert
        self.assertEqual(Instrument, type(instrument))
        self.assertEqual(AssetClass.CRYPTO, instrument.asset_class)
        self.assertEqual(AssetType.SPOT, instrument.asset_type)
        self.assertEqual(BTC, instrument.base_currency)
        self.assertEqual(USDT, instrument.quote_currency)
        self.assertEqual(USDT, instrument.settlement_currency)
Beispiel #3
0
    def test_real_api(self):
        import ccxt

        client = ccxt.binance()
        provider = CCXTInstrumentProvider(client=client)

        # Act
        provider.load_all()

        # Assert
        self.assertTrue(provider.count > 0)  # No exceptions raised
    def test_get_btc_currency_when_not_loaded_returns_none(self):
        # Arrange
        mock_client = MagicMock()
        mock_client.name = "Binance"
        mock_client.precisionMode = 2

        provider = CCXTInstrumentProvider(client=mock_client)
        provider.load_all()

        # Act
        currency = provider.currency("BTC")

        # Assert
        self.assertIsNone(currency)
    def test_load_all(self):
        # Arrange
        mock_client = MagicMock()
        mock_client.name = "Binance"

        with open(TEST_PATH + "res_instruments.json") as response:
            instruments = json.load(response)

        mock_client.markets = instruments

        provider = CCXTInstrumentProvider(client=mock_client)

        # Act
        provider.load_all()

        # Assert
        self.assertTrue(provider.count > 0)  # No exceptions raised
    def test_get_all_when_loaded_returns_instruments(self):
        # Arrange
        mock_client = MagicMock()
        mock_client.name = "Binance"

        with open(TEST_PATH + "res_instruments.json") as response:
            instruments = json.load(response)

        mock_client.markets = instruments

        provider = CCXTInstrumentProvider(client=mock_client)
        provider.load_all()

        # Act
        instruments = provider.get_all()

        # Assert
        self.assertTrue(len(instruments) > 0)
        self.assertEqual(dict, type(instruments))
        self.assertEqual(Symbol, type(next(iter(instruments))))
    def test_load_all_when_tick_size_precision_mode_exchange(self):
        # Arrange
        with open(TEST_PATH + "markets2.json") as response:
            markets = json.load(response)

        with open(TEST_PATH + "currencies2.json") as response:
            currencies = json.load(response)

        mock_client = MagicMock()
        mock_client.name = "BitMEX"
        mock_client.precisionMode = 4
        mock_client.markets = markets
        mock_client.currencies = currencies

        provider = CCXTInstrumentProvider(client=mock_client)

        # Act
        provider.load_all()

        # Assert
        self.assertEqual(120, provider.count)  # No exceptions raised
    def test_get_btc_currency_when_loaded_returns_expected_currency(self):
        # Arrange
        with open(TEST_PATH + "markets.json") as response:
            markets = json.load(response)

        with open(TEST_PATH + "currencies.json") as response:
            currencies = json.load(response)

        mock_client = MagicMock()
        mock_client.name = "Binance"
        mock_client.precisionMode = 2
        mock_client.markets = markets
        mock_client.currencies = currencies

        provider = CCXTInstrumentProvider(client=mock_client)
        provider.load_all()

        # Act
        currency = provider.currency("BTC")

        # Assert
        self.assertEqual(Currency, type(currency))
        self.assertEqual("BTC", currency.code)
        self.assertEqual(8, currency.precision)
    def test_get_all_when_loaded_returns_instruments(self):
        # Arrange
        with open(TEST_PATH + "markets.json") as response:
            markets = json.load(response)

        with open(TEST_PATH + "currencies.json") as response:
            currencies = json.load(response)

        mock_client = MagicMock()
        mock_client.name = "Binance"
        mock_client.precisionMode = 2
        mock_client.markets = markets
        mock_client.currencies = currencies

        provider = CCXTInstrumentProvider(client=mock_client)
        provider.load_all()

        # Act
        instruments = provider.get_all()

        # Assert
        self.assertTrue(len(instruments) > 0)
        self.assertEqual(dict, type(instruments))
        self.assertEqual(InstrumentId, type(next(iter(instruments))))