/// <summary> /// Creates a TradingProvider containing the Binance implementation, treated with /// a mock communications service. /// </summary> /// <returns>Testable trading provider.</returns> private TradingProvider GetTradingProvider() { var container = ExchangeFactoryService.BuildContainer <TemplateAlgorithm>(AlgorithmConfiguration); var trading = container.TradingProvider; var property = trading.GetType().GetProperty("Implementation", BindingFlags.NonPublic | BindingFlags.Instance) ?? throw new Exception($"Expected property 'Implementation' on {nameof(TradingProvider)}"); // Inject test communications var comms = new TestBinanceCommunicationsService(LoggerFactory); // Inject test implementation var binance = new BinanceTradingProvider(LoggerFactory, comms, container.TimerProvider); property.SetValue(trading, binance); return(trading); }
/// <summary> /// Builds a container for Binance. /// </summary> /// <param name="config">The algorithm configuration to use.</param> /// <typeparam name="T">The algorithm type.</typeparam> /// <returns>ExchangeProviderContainer.</returns> public ExchangeProvidersContainer BuildBinanceContainer <T>(AlgorithmConfiguration config) where T : IBaseAlgorithm { // Makes sure that the communication is enabled _binanceCommunications.EnableStreams(); var timerProvider = new BinanceTimerProvider(_loggerFactory, _binanceCommunications.CandleDispenser); var dataImplementation = new BinanceDataProvider(_loggerFactory, _binanceCommunications, timerProvider); var tradingImplementation = new BinanceTradingProvider(_loggerFactory, _binanceCommunications, timerProvider); var dataProvider = new DataProvider(_loggerFactory, dataImplementation, config); var tradingProvider = new TradingProvider(_loggerFactory, tradingImplementation, dataProvider, _allocationManager); // Doubly linked data provider to check candles timerProvider.DataProvider = dataProvider; // Inject database event listener DatabaseEventListenerService.AddOrderSource(tradingProvider); return(new ExchangeProvidersContainer(_loggerFactory, dataProvider, timerProvider, tradingProvider, typeof(T))); }