コード例 #1
0
        /// <summary>
        /// Returns the instrument from the Redis database matching the given key.
        /// </summary>
        /// <param name="key">The instrument key to read.</param>
        /// <returns>The keys.</returns>
        public QueryResult <Instrument> Read(string key)
        {
            Debug.NotEmptyOrWhiteSpace(key, nameof(key));

            if (!this.redisDatabase.KeyExists(key))
            {
                return(QueryResult <Instrument> .Fail($"Cannot find {key}"));
            }

            var instrumentDict = this.redisDatabase.HashGetAll(key)
                                 .ToDictionary(
                hashEntry => hashEntry.Name.ToString(),
                hashEntry => hashEntry.Value.ToString());

            var securityType = instrumentDict[nameof(Instrument.SecurityType)].ToEnum <SecurityType>();

            if (securityType == SecurityType.Forex)
            {
                var forexCcy = new ForexInstrument(
                    Symbol.FromString(instrumentDict[nameof(Instrument.Symbol)]),
                    int.Parse(instrumentDict[nameof(Instrument.PricePrecision)]),
                    int.Parse(instrumentDict[nameof(Instrument.SizePrecision)]),
                    int.Parse(instrumentDict[nameof(Instrument.MinStopDistanceEntry)]),
                    int.Parse(instrumentDict[nameof(Instrument.MinLimitDistanceEntry)]),
                    int.Parse(instrumentDict[nameof(Instrument.MinStopDistance)]),
                    int.Parse(instrumentDict[nameof(Instrument.MinLimitDistance)]),
                    Price.Create(Parser.ToDecimal(instrumentDict[nameof(Instrument.TickSize)])),
                    Quantity.Create(Parser.ToDecimal(instrumentDict[nameof(Instrument.RoundLotSize)])),
                    Quantity.Create(Parser.ToDecimal(instrumentDict[nameof(Instrument.MinTradeSize)])),
                    Quantity.Create(Parser.ToDecimal(instrumentDict[nameof(Instrument.MaxTradeSize)])),
                    Parser.ToDecimal(instrumentDict[nameof(Instrument.RolloverInterestBuy)]),
                    Parser.ToDecimal(instrumentDict[nameof(Instrument.RolloverInterestSell)]),
                    instrumentDict[nameof(Instrument.Timestamp)].ToZonedDateTimeFromIso());

                return(QueryResult <Instrument> .Ok(forexCcy));
            }

            var instrument = new Instrument(
                Symbol.FromString(instrumentDict[nameof(Instrument.Symbol)]),
                instrumentDict[nameof(Instrument.QuoteCurrency)].ToEnum <Currency>(),
                securityType,
                int.Parse(instrumentDict[nameof(Instrument.PricePrecision)]),
                int.Parse(instrumentDict[nameof(Instrument.SizePrecision)]),
                int.Parse(instrumentDict[nameof(Instrument.MinStopDistanceEntry)]),
                int.Parse(instrumentDict[nameof(Instrument.MinLimitDistanceEntry)]),
                int.Parse(instrumentDict[nameof(Instrument.MinStopDistance)]),
                int.Parse(instrumentDict[nameof(Instrument.MinLimitDistance)]),
                Price.Create(Parser.ToDecimal(instrumentDict[nameof(Instrument.TickSize)])),
                Quantity.Create(Parser.ToDecimal(instrumentDict[nameof(Instrument.RoundLotSize)])),
                Quantity.Create(Parser.ToDecimal(instrumentDict[nameof(Instrument.MinTradeSize)])),
                Quantity.Create(Parser.ToDecimal(instrumentDict[nameof(Instrument.MaxTradeSize)])),
                Parser.ToDecimal(instrumentDict[nameof(Instrument.RolloverInterestBuy)]),
                Parser.ToDecimal(instrumentDict[nameof(Instrument.RolloverInterestSell)]),
                instrumentDict[nameof(Instrument.Timestamp)].ToZonedDateTimeFromIso());

            return(QueryResult <Instrument> .Ok(instrument));
        }
コード例 #2
0
        public static ForexInstrument USDJPY()
        {
            var instrument = new ForexInstrument(
                new Symbol("USD/JPY", new Venue("FXCM")),
                3,
                0,
                0,
                0,
                0,
                0,
                Price.Create(0.001m, 3),
                Quantity.Create(1000m),
                Quantity.Create(1m),
                Quantity.Create(50000000m),
                1,
                1,
                StubZonedDateTime.UnixEpoch());

            return(instrument);
        }
コード例 #3
0
        public static ForexInstrument EURUSD()
        {
            var instrument = new ForexInstrument(
                new Symbol("EUR/USD", new Venue("FXCM")),
                5,
                0,
                0,
                0,
                0,
                0,
                Price.Create(0.00001m, 5),
                Quantity.Create(1000m),
                Quantity.Create(1m),
                Quantity.Create(50000000m),
                1,
                1,
                StubZonedDateTime.UnixEpoch());

            return(instrument);
        }
コード例 #4
0
        public void OnMessage(SecurityList message)
        {
            Debug.NotNull(this.dataGateway, nameof(this.dataGateway));

            var responseId = message.GetField(Tags.SecurityResponseID);
            var result     = FxcmMessageHelper.GetSecurityRequestResult(message.SecurityRequestResult);

            this.Logger.LogDebug(LogId.Network, $"{Received}{Fix} {nameof(SecurityList)}(ResponseId={responseId}, Result={result}).");

            var instruments = new List <Instrument>();
            var groupCount  = int.Parse(message.NoRelatedSym.ToString());
            var group       = new SecurityList.NoRelatedSymGroup();

            for (var i = 1; i <= groupCount; i++)
            {
                message.GetGroup(i, group);

                var symbol                = this.GetSymbol(group.GetField(Tags.Symbol));
                var securityType          = FxcmMessageHelper.GetSecurityType(group.GetField(FxcmTags.ProductID));
                var tickPrecision         = group.GetInt(FxcmTags.SymPrecision);
                var tickSize              = group.GetDecimal(FxcmTags.SymPointSize) * 0.1m; // Field 9002 returns 'point' size (* 0.1m to get tick size)
                var roundLot              = group.GetInt(Tags.RoundLot);
                var minStopDistanceEntry  = group.GetInt(FxcmTags.CondDistEntryStop);
                var minLimitDistanceEntry = group.GetInt(FxcmTags.CondDistEntryLimit);
                var minStopDistance       = group.GetInt(FxcmTags.CondDistStop);
                var minLimitDistance      = group.GetInt(FxcmTags.CondDistLimit);
                var minTradeSize          = group.GetInt(FxcmTags.MinQuantity);
                var maxTradeSize          = group.GetInt(FxcmTags.MaxQuantity);
                var rolloverInterestBuy   = group.GetDecimal(FxcmTags.SymInterestBuy);
                var rolloverInterestSell  = group.GetDecimal(FxcmTags.SymInterestSell);

                if (securityType == SecurityType.Forex)
                {
                    var forexInstrument = new ForexInstrument(
                        symbol,
                        tickPrecision,
                        0,
                        minStopDistanceEntry,
                        minLimitDistanceEntry,
                        minStopDistance,
                        minLimitDistance,
                        Price.Create(tickSize, tickPrecision),
                        Quantity.Create(roundLot),
                        Quantity.Create(minTradeSize),
                        Quantity.Create(maxTradeSize),
                        rolloverInterestBuy,
                        rolloverInterestSell,
                        this.TimeNow());

                    instruments.Add(forexInstrument);
                }
                else
                {
                    var instrument = new Instrument(
                        symbol,
                        group.GetField(Tags.Currency).ToEnum <Nautilus.DomainModel.Enums.Currency>(),
                        securityType,
                        tickPrecision,
                        0,
                        minStopDistanceEntry,
                        minLimitDistanceEntry,
                        minStopDistance,
                        minLimitDistance,
                        Price.Create(tickSize, tickPrecision),
                        Quantity.Create(roundLot),
                        Quantity.Create(minTradeSize),
                        Quantity.Create(maxTradeSize),
                        rolloverInterestBuy,
                        rolloverInterestSell,
                        this.TimeNow());

                    instruments.Add(instrument);
                }
            }

            this.dataGateway?.OnData(instruments);
        }