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_not_loaded_returns_none(self):
        # Arrange
        mock_client = MagicMock()
        mock_client.name = "Binance"

        provider = CCXTInstrumentProvider(client=mock_client)

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

        # Act
        instrument = provider.get(symbol)

        # Assert
        self.assertIsNone(instrument)
Beispiel #3
0
from nautilus_trader.model.enums import OMSType
from nautilus_trader.model.enums import PriceType
from nautilus_trader.model.identifiers import Symbol
from nautilus_trader.model.identifiers import Venue
from nautilus_trader.model.objects import Money
from tests.test_kit.providers import TestDataProvider

if __name__ == "__main__":
    # Setup trading instruments
    # Requires an internet connection for the instrument loader
    # Alternatively use the TestInstrumentProvider in the test kit
    print("Loading instruments...")
    instruments = CCXTInstrumentProvider(client=ccxt.binance(), load_all=True)

    BINANCE = Venue("BINANCE")
    ETHUSDT_BINANCE = instruments.get(Symbol("ETH/USDT", BINANCE))

    # Setup data container
    data = BacktestDataContainer()
    data.add_instrument(ETHUSDT_BINANCE)
    data.add_trade_ticks(ETHUSDT_BINANCE.symbol,
                         TestDataProvider.ethusdt_trades())

    # Instantiate your strategy
    strategy = EMACross(
        symbol=ETHUSDT_BINANCE.symbol,
        bar_spec=BarSpecification(250, BarAggregation.TICK, PriceType.LAST),
        fast_ema_period=10,
        slow_ema_period=20,
        trade_size=Decimal(100),
        order_id_tag="001",