コード例 #1
0
        public void InitiateTrading(IStockExchangeStream stockStream, IOrderStream <Order> tradeStream)
        {
            lock (this._stateTransition)
            {
                if (stockStream == null)
                {
                    this.Logger.Log(
                        LogLevel.Error,
                        "Initiation attempt in order data generator with null stock stream");
                    return;
                }

                if (tradeStream == null)
                {
                    this.Logger.Log(
                        LogLevel.Error,
                        "Initiation attempt in order data generator with null trade stream");
                    return;
                }

                if (this._generatorExecuting)
                {
                    this.Logger.LogInformation("Initiating new trading with predecessor active");
                    this._TerminateTrading();
                }

                this.Logger.LogInformation("Order data generator initiated with new stock stream");
                this.StockStream         = stockStream;
                this.TradeStream         = tradeStream;
                this._unsubscriber       = stockStream.Subscribe(this);
                this._generatorExecuting = true;

                this._InitiateTrading();
            }
        }
コード例 #2
0
        public void Initiate(IStockExchangeStream stockStream)
        {
            lock (this._stateTransition)
            {
                if (stockStream == null)
                {
                    this._logger.Log(
                        LogLevel.Error,
                        "Initiation attempt in order data generator with null stock stream");
                    return;
                }

                this._stockStream  = stockStream;
                this._unsubscriber = stockStream.Subscribe(this);
            }

            if (string.IsNullOrWhiteSpace(this._path))
            {
                this._logger.LogError(
                    "Equities File Data Import Process did not find file because the path was empty or null");
                return;
            }

            if (!Directory.Exists(this._path))
            {
                Directory.CreateDirectory(this._path);
            }
        }
コード例 #3
0
        /// <summary>
        ///     Avoid calling this from inside another state transition
        /// </summary>
        public void Terminate()
        {
            lock (this._stateTransition)
            {
                this._unsubscriber?.Dispose();

                this._stockStream = null;
            }
        }
コード例 #4
0
        public void Setup()
        {
            this._unsubscriber  = A.Fake <IDisposable>();
            this._stockStream   = A.Fake <IStockExchangeStream>();
            this._tradeStream   = A.Fake <IOrderStream <Order> >();
            this._tradeStrategy = A.Fake <ITradeStrategy <Order> >();
            this._logger        = A.Fake <ILogger>();

            A.CallTo(() => this._stockStream.Subscribe(A <IObserver <EquityIntraDayTimeBarCollection> > .Ignored))
            .Returns(this._unsubscriber);
        }
コード例 #5
0
        /// <summary>
        ///     Avoid dead locks with initiation terminating old trades
        /// </summary>
        private void _TerminateTrading()
        {
            this.Logger.LogInformation("Order data generator terminating trading");

            this._unsubscriber?.Dispose();

            this.StockStream         = null;
            this.TradeStream         = null;
            this._generatorExecuting = false;

            this._TerminateTradingStrategy();
        }
        public void InitiateWalk(IStockExchangeStream stream)
        {
            if (string.IsNullOrWhiteSpace(this._filePath))
            {
                this._logger.LogError(
                    "Equities File Data Import Process did not find file because the path was empty or null");
                return;
            }

            if (!File.Exists(this._filePath))
            {
                this._logger.LogError($"Equities File Data Import Process did not find file {this._filePath}");
                return;
            }

            var securities = new List <EquityInstrumentIntraDayTimeBar>();

            using (var reader = File.OpenText(this._filePath))
            {
                var csv = new CsvReader(reader);
                csv.Configuration.HasHeaderRecord = true;

                var csvRecords = csv.GetRecords <FinancialInstrumentTimeBarCsv>().ToList();

                foreach (var record in csvRecords)
                {
                    var mappedRecord = this._securityMapper.Map(record);
                    if (mappedRecord != null)
                    {
                        securities.Add(mappedRecord);
                    }
                }
            }

            if (this._securityMapper.FailedParseTotal > 0)
            {
                this._logger.LogError(
                    $"EquitiesFileDataImportProcess had {this._securityMapper.FailedParseTotal} errors parsing the input CSV file {this._filePath}");
            }

            if (!securities.Any())
            {
                return;
            }

            var frames = this.ExtractDateBasedExchangeFramesOverMarkets(securities);

            foreach (var frame in frames)
            {
                stream.Add(frame);
            }
        }
コード例 #7
0
        public void InitiateWalk(IStockExchangeStream stream)
        {
            this._logger.LogInformation("Walk initiated in equity generator");

            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            lock (this._stateTransitionLock)
            {
                this._walkInitiated = true;

                this._stream      = stream;
                this._activeFrame = this._exchangeTickInitialiser.InitialFrame();
                this._stream.Add(this._activeFrame);

                this._heartBeat.OnBeat(this.Tick);
                this._heartBeat.Start();
            }
        }
コード例 #8
0
        public void InitiateWalk(IStockExchangeStream stream, ExchangeDto market, SecurityPriceResponseDto prices)
        {
            this._logger.LogInformation("Walk initiated in equity generator");

            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            if (market == null)
            {
                throw new ArgumentNullException(nameof(market));
            }

            if (prices == null)
            {
                throw new ArgumentNullException(nameof(prices));
            }

            lock (this._stateTransitionLock)
            {
                this._stream = stream;

                var apiGeneration = new ApiDataGenerationInitialiser(
                    market,
                    this._tickSeparation,
                    prices.SecurityPrices);
                var framesToGenerateFor = apiGeneration.OrderedDailyFrames();

                foreach (var frame in framesToGenerateFor)
                {
                    this._activeFrame = frame;
                    this.AdvanceFrames(market, frame);
                }
            }
        }
 public void InitiateTrading(IStockExchangeStream stockStream, IOrderStream <Order> tradeStream)
 {
     this._unsubscriber = stockStream.Subscribe(this);
     this._stream       = this._streamFactory.Create();
     this._baseGenerator.InitiateTrading(this._stream, tradeStream);
 }