Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BacktestDaemonState"/> class.
 /// </summary>
 /// <param name="algoService">The algorithm service.</param>
 /// <param name="allocationManager">The allocation manager.</param>
 /// <param name="exchangeFactory">The exchange factory service.</param>
 public BacktestDaemonState(AlgorithmService algoService, IAllocationManager allocationManager, ExchangeFactoryService exchangeFactory)
 {
     Guard.Argument(algoService).NotNull();
     AlgorithmService  = algoService;
     AllocationManager = allocationManager;
     ExchangeFactory   = exchangeFactory;
 }
Exemplo n.º 2
0
        public TimerProviderTests(ITestOutputHelper outputHelper)
            : base(outputHelper)
        {
            var container =
                ExchangeFactoryService.BuildContainer <TemplateAlgorithm>(AlgorithmConfiguration);

            _time = container.TimerProvider;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseProviderTests"/> class.
        /// </summary>
        /// <param name="outputHelper">Used to create output.</param>
        public BaseProviderTests(ITestOutputHelper outputHelper)
            : base(outputHelper)
        {
            var serviceProvider = ServiceProviderSingleton.Instance.ServiceProvider;

            ExchangeFactoryService = serviceProvider.GetService <ExchangeFactoryService>();
            AlgorithmConfiguration = new DeserializerBuilder().Build()
                                     .Deserialize <TemplateAlgorithmConfiguration>(new StringReader(AlgorithmSettingsSource));
            ConfigurationValidator.ValidateConstraintsRecursively(AlgorithmConfiguration);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BinanceDataProviderTests"/> class.
        /// </summary>
        /// <param name="outputHelper">Used to create output.</param>
        public BinanceDataProviderTests(ITestOutputHelper outputHelper)
            : base(outputHelper)
        {
            string source = $@"
                TradingPairs: [EOSETH]
                CandleWidth: {Configuration.Instance.CandleWidth}
            ";
            var    config = ParseAlgorithmConfiguration(source);

            _container = ExchangeFactoryService.BuildBinanceContainer <TemplateAlgorithm>(config);
        }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
0
        public StateTests(ITestOutputHelper outputHelper)
            : base(outputHelper)
        {
            _container = ExchangeFactoryService.BuildBinanceContainer <TemplateAlgorithm>(AlgorithmConfiguration);

            var setTimerMethod = typeof(State <TemplateAlgorithmConfiguration>)
                                 .GetMethod("SetTimer", BindingFlags.NonPublic | BindingFlags.Instance);

            _setTimer = (state, timespan) =>
            {
                try
                {
                    setTimerMethod.Invoke(state, new object[] { timespan });
                }
                catch (TargetInvocationException e)
                {
                    throw e.InnerException;
                }
            };
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AlgorithmService"/> class.
        /// </summary>
        /// <param name="loggerFactory">Provides logging capabilities.</param>
        /// <param name="allocationManager">Set allocations on startup.</param>
        /// <param name="exchangeFactoryService">Provides containers for algorithms.</param>
        public AlgorithmService(
            ILoggerFactory loggerFactory,
            IAllocationManager allocationManager,
            ExchangeFactoryService exchangeFactoryService)
        {
            _logger = loggerFactory.CreateLogger <AlgorithmService>();
            _exchangeFactoryService = exchangeFactoryService;

            if (Program.CommandLineArgs.Trading)
            {
                // Sets initial configuration
                try
                {
                    allocationManager.SetInitialConfiguration(Configuration.Instance.EnabledAlgorithm.Allocation);
                }
                catch (AllocationUnavailableException)
                {
                    Program.ExitProgramWithCode(ExitCode.AllocationUnavailable);
                }
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BacktestDaemonService"/> class.
 /// </summary>
 /// <param name="algoService">The algorithm service.</param>
 /// <param name="allocationManager">The allocation manager.</param>
 /// <param name="exchangeFactoryService">The exchange factory service.</param>
 public BacktestDaemonService(AlgorithmService algoService, IAllocationManager allocationManager, ExchangeFactoryService exchangeFactoryService)
 {
     State = new BacktestDaemonState(algoService, allocationManager, exchangeFactoryService);
 }