예제 #1
0
        public void Add(Instrument instrument)
        {
            var symbol = instrument.Symbol;

            if (!this.cache.ContainsKey(symbol))
            {
                this.cache.Add(symbol, instrument);
                this.Write(instrument);
                this.Logger.LogInformation(LogId.Database, $"Added Instrument {symbol.Value}.");
                return;
            }

            var instrumentBuilder = new InstrumentBuilder(this.cache[symbol]).Update(instrument);

            if (instrumentBuilder.Changes.Count == 0)
            {
                this.Logger.LogInformation(LogId.Database, $"Instrument {symbol.Value} unchanged in cache.");
                return;
            }

            var changesString = new StringBuilder();

            foreach (var change in instrumentBuilder.Changes)
            {
                changesString.Append(change);
            }

            var updatedInstrument = instrumentBuilder.Build(this.TimeNow());

            this.cache[symbol] = updatedInstrument;
            this.Write(instrument);

            this.Logger.LogInformation(LogId.Database, $"Updated instrument {symbol.Value}" + changesString + ".");
        }
예제 #2
0
        internal void Build_WithValidInstrument_ReturnsExpectedInstrument()
        {
            // Arrange
            var audusd            = StubInstrumentProvider.AUDUSD();
            var instrumentBuilder = new InstrumentBuilder(audusd);

            // Act
            var result = instrumentBuilder.Build(StubZonedDateTime.UnixEpoch());

            // Assert
            Assert.Equal(audusd, result);
        }
예제 #3
0
        internal void Update_WithChanges_ReturnsNewInstrument()
        {
            // Arrange
            var audusd            = StubInstrumentProvider.AUDUSD();
            var instrumentBuilder = new InstrumentBuilder(audusd);

            var instrument = new Instrument(
                new Symbol("SPX500", new Venue("FXCM")),
                Currency.USD,
                SecurityType.CFD,
                2,
                0,
                1,
                1,
                1,
                1,
                Price.Create(0.01m, 2),
                Quantity.Create(1m),
                Quantity.Create(10m),
                Quantity.Create(10000m),
                45,
                45,
                StubZonedDateTime.UnixEpoch());

            // Act
            var result = instrumentBuilder
                         .Update(instrument)
                         .Build(StubZonedDateTime.UnixEpoch());

            // Assert
            Assert.Equal(8, instrumentBuilder.Changes.Count);
            Assert.Equal(Quantity.Create(10000), result.MaxTradeSize);
            Assert.Equal(45, result.RolloverInterestBuy);
            Assert.Equal(45, result.RolloverInterestSell);

            foreach (var change in instrumentBuilder.Changes)
            {
                this.Output.WriteLine(change);
            }
        }
예제 #4
0
 internal void Freeze(InstrumentBuilder builder)
 {
     this.autoCapture.CopyFrom(builder.AutoCapture);
     this.sampleRates.CopyFrom(builder.SampleRates);
 }