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)
def test_get_btcusdt_when_not_loaded_returns_none(self): # Arrange mock_client = MagicMock() mock_client.name = "Binance" provider = CCXTInstrumentProvider(client=mock_client) instrument_id = InstrumentId(Symbol("BTC/USDT"), Venue("BINANCE")) # Act instrument = provider.find(instrument_id) # Assert self.assertIsNone(instrument)
from nautilus_trader.model.identifiers import InstrumentId 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") instrument_id = InstrumentId(symbol=Symbol("ETH/USDT"), venue=BINANCE) ETHUSDT_BINANCE = instruments.find(instrument_id) # Setup data container data = BacktestDataContainer() data.add_instrument(ETHUSDT_BINANCE) data.add_trade_ticks(ETHUSDT_BINANCE.id, TestDataProvider.ethusdt_trades()) # Instantiate your strategy strategy = EMACross( instrument_id=ETHUSDT_BINANCE.id, bar_spec=BarSpecification(250, BarAggregation.TICK, PriceType.LAST), fast_ema_period=10, slow_ema_period=20, trade_size=Decimal("0.05"), order_id_tag="001", )