Example #1
0
        private OrderPartiallyFilled GenerateOrderPartiallyFilledEvent(ExecutionReport message)
        {
            var orderId          = this.GetOrderId(message);
            var executionId      = new ExecutionId(message.GetField(Tags.ExecID));
            var positionIdBroker = new PositionIdBroker(message.GetField(FxcmTags.PosID));
            var symbol           = this.GetSymbol(message.GetField(Tags.Symbol));
            var orderSide        = FxcmMessageHelper.GetOrderSide(message.GetField(Tags.Side));
            var filledQuantity   = Quantity.Create(message.GetDecimal(Tags.CumQty));
            var averagePrice     = Price.Create(message.GetDecimal(Tags.AvgPx));
            var quoteCurrency    = this.GetQuoteCurrency(symbol, message.GetField(Tags.Currency));
            var leavesQuantity   = Quantity.Create(message.GetInt(Tags.LeavesQty));
            var executionTime    = FxcmMessageHelper.ParseTimestamp(message.GetField(Tags.TransactTime));

            return(new OrderPartiallyFilled(
                       this.accountId,
                       orderId,
                       executionId,
                       positionIdBroker,
                       symbol,
                       orderSide,
                       filledQuantity,
                       leavesQuantity,
                       averagePrice,
                       quoteCurrency,
                       executionTime,
                       this.NewGuid(),
                       this.TimeNow()));
        }
Example #2
0
        private OrderWorking GenerateOrderWorkingEvent(ExecutionReport message)
        {
            var orderId       = this.GetOrderId(message);
            var orderIdBroker = new OrderIdBroker(message.GetField(Tags.OrderID));
            var symbol        = this.GetSymbol(message.GetField(Tags.Symbol));
            var orderSide     = FxcmMessageHelper.GetOrderSide(message.GetField(Tags.Side));
            var orderType     = FxcmMessageHelper.GetOrderType(message.GetField(Tags.OrdType));
            var quantity      = Quantity.Create(message.GetDecimal(Tags.OrderQty));
            var price         = FxcmMessageHelper.GetOrderPrice(orderType, message);
            var timeInForce   = FxcmMessageHelper.GetTimeInForce(message.GetField(Tags.TimeInForce));
            var expireTime    = FxcmMessageHelper.GetExpireTime(message);
            var workingTime   = FxcmMessageHelper.ParseTimestamp(message.GetField(Tags.TransactTime));

            return(new OrderWorking(
                       this.accountId,
                       orderId,
                       orderIdBroker,
                       symbol,
                       orderSide,
                       orderType,
                       quantity,
                       price,
                       timeInForce,
                       expireTime,
                       workingTime,
                       this.NewGuid(),
                       this.TimeNow()));
        }
Example #3
0
        private OrderExpired GenerateOrderExpiredEvent(ExecutionReport message)
        {
            var orderId     = this.GetOrderId(message);
            var expiredTime = FxcmMessageHelper.ParseTimestamp(message.GetField(Tags.TransactTime));

            return(new OrderExpired(
                       this.accountId,
                       orderId,
                       expiredTime,
                       this.NewGuid(),
                       this.TimeNow()));
        }
Example #4
0
        private OrderRejected GenerateOrderRejectedEvent(ExecutionReport message)
        {
            var orderId      = this.GetOrderId(message);
            var rejectedTime = FxcmMessageHelper.ParseTimestamp(message.GetField(Tags.TransactTime));
            var rejectReason = message.GetField(FxcmTags.ErrorDetails).TrimEnd('.');

            return(new OrderRejected(
                       this.accountId,
                       orderId,
                       rejectedTime,
                       rejectReason,
                       this.NewGuid(),
                       this.TimeNow()));
        }
Example #5
0
        private OrderModified GenerateOrderModifiedEvent(ExecutionReport message)
        {
            var orderId       = this.GetOrderId(message);
            var orderIdBroker = new OrderIdBroker(message.GetField(Tags.OrderID));
            var orderType     = FxcmMessageHelper.GetOrderType(message.GetField(Tags.OrdType));
            var quantity      = message.IsSetField(Tags.LeavesQty)
                ? Quantity.Create(message.GetDecimal(Tags.LeavesQty))
                : Quantity.Create(message.GetDecimal(Tags.OrderQty));
            var price        = FxcmMessageHelper.GetOrderPrice(orderType, message);
            var modifiedTime = FxcmMessageHelper.ParseTimestamp(message.GetField(Tags.TransactTime));

            return(new OrderModified(
                       this.accountId,
                       orderId,
                       orderIdBroker,
                       quantity,
                       price,
                       modifiedTime,
                       this.NewGuid(),
                       this.TimeNow()));
        }
Example #6
0
        public void OnMessage(QuickFix.FIX44.OrderCancelReject message)
        {
            Debug.NotNull(this.tradingGateway, nameof(this.tradingGateway));

            this.Logger.LogDebug(LogId.Network, $"{Received}{Fix} {nameof(OrderCancelReject)}");

            var orderId          = this.GetOrderId(message);
            var rejectedTime     = FxcmMessageHelper.ParseTimestamp(message.GetField(Tags.TransactTime));
            var rejectResponseTo = FxcmMessageHelper.GetCxlRejResponseTo(message.CxlRejResponseTo);
            var rejectReason     = message.GetField(FxcmTags.ErrorDetails).TrimEnd('.');

            var orderCancelReject = new OrderCancelReject(
                this.accountId,
                orderId,
                rejectedTime,
                rejectResponseTo,
                rejectReason,
                this.NewGuid(),
                this.TimeNow());

            this.tradingGateway?.Send(orderCancelReject);
        }
Example #7
0
        private ZonedDateTime GetMarketDataTimestamp()
        {
            var dateTimeString = $"{this.mdBidGroup.GetField(Tags.MDEntryDate)}-{this.mdBidGroup.GetField(Tags.MDEntryTime)}";

            return(FxcmMessageHelper.ParseTimestamp(dateTimeString));
        }
Example #8
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);
        }