Пример #1
0
        /// <summary>
        /// Write the specified message into FIX protocol.
        /// </summary>
        /// <param name="writer">The recorder of data in the FIX protocol format.</param>
        /// <param name="message">The message.</param>
        /// <returns><see cref="FixMessages"/> value.</returns>
        protected override string OnWrite(IFixWriter writer, Message message)
        {
            var msgType = base.OnWrite(writer, message);

            if (message.Type == MessageTypes.OrderCancel)
            {
                var type = ((OrderCancelMessage)message).OrderType;

                if (type != null)
                {
                    writer.Write(FixTags.Text);
                    writer.Write(type.Value.To <string>());
                }
            }

            return(msgType);
        }
Пример #2
0
		/// <summary>
		/// Write the specified message into FIX protocol.
		/// </summary>
		/// <param name="writer">The recorder of data in the FIX protocol format.</param>
		/// <param name="message">The message.</param>
		/// <returns><see cref="FixMessages"/> value.</returns>
		protected override string OnWrite(IFixWriter writer, Message message)
		{
			var msgType = base.OnWrite(writer, message);

			if (message.Type == MessageTypes.OrderCancel)
			{
				var type = ((OrderCancelMessage)message).OrderType;

				if (type != null)
				{
					writer.Write(FixTags.Text);
					writer.Write(type.Value.To<string>());
				}
			}

			return msgType;
		}
Пример #3
0
        /// <summary>
        /// Write the specified message into FIX protocol.
        /// </summary>
        /// <param name="writer">The recorder of data in the FIX protocol format.</param>
        /// <param name="message">The message.</param>
        /// <returns><see cref="FixMessages"/> value.</returns>
        protected override string OnWrite(IFixWriter writer, Message message)
        {
            var msgType = base.OnWrite(writer, message);

            var cancelMsg = message as OrderCancelMessage;

            if (cancelMsg == null)
            {
                return(msgType);
            }

            if (cancelMsg.OrderType == null)
            {
                return(msgType);
            }

            writer.Write(FixTags.Text);
            writer.Write(cancelMsg.OrderType.Value.To <string>());

            return(msgType);
        }
Пример #4
0
 protected override void WriterFixOrderCondition(IFixWriter writer, ExecutionMessage message)
 {
     writer.WriteOrderCondition((QuikOrderCondition)message.Condition, TransactionSession.DateTimeFormat);
 }
Пример #5
0
        public static void WriteOrderCondition(this IFixWriter writer, QuikOrderCondition condition, string dateTimeFormat)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

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

            if (condition.Type != null)
            {
                writer.Write((FixTags)QuikFixTags.Type);
                writer.Write((int)condition.Type.Value);
            }

            if (condition.StopPriceCondition != null)
            {
                writer.Write((FixTags)QuikFixTags.StopPriceCondition);
                writer.Write((int)condition.StopPriceCondition.Value);
            }

            if (condition.ConditionOrderSide != null)
            {
                writer.Write((FixTags)QuikFixTags.ConditionOrderSide);
                writer.Write((int)condition.ConditionOrderSide.Value);
            }

            if (condition.LinkedOrderCancel != null)
            {
                writer.Write((FixTags)QuikFixTags.LinkedOrderCancel);
                writer.Write(condition.LinkedOrderCancel.Value);
            }

            if (condition.Result != null)
            {
                writer.Write((FixTags)QuikFixTags.Result);
                writer.Write((int)condition.Result.Value);
            }

            if (condition.OtherSecurityId != null)
            {
                writer.Write((FixTags)QuikFixTags.OtherSecurityCode);
                writer.Write(condition.OtherSecurityId.Value.SecurityCode);
            }

            if (condition.StopPrice != null)
            {
                writer.Write((FixTags)QuikFixTags.StopPrice);
                writer.Write(condition.StopPrice.Value);
            }

            if (condition.StopLimitPrice != null)
            {
                writer.Write((FixTags)QuikFixTags.StopLimitPrice);
                writer.Write(condition.StopLimitPrice.Value);
            }

            if (condition.IsMarketStopLimit != null)
            {
                writer.Write((FixTags)QuikFixTags.IsMarketStopLimit);
                writer.Write(condition.IsMarketStopLimit.Value);
            }

            if (condition.ActiveTime != null)
            {
                writer.Write((FixTags)QuikFixTags.ActiveTimeFrom);
                writer.Write(condition.ActiveTime.Min.UtcDateTime, dateTimeFormat);

                writer.Write((FixTags)QuikFixTags.ActiveTimeTo);
                writer.Write(condition.ActiveTime.Max.UtcDateTime, dateTimeFormat);
            }

            if (condition.ConditionOrderId != null)
            {
                writer.Write((FixTags)QuikFixTags.ConditionOrderId);
                writer.Write(condition.ConditionOrderId.Value);
            }

            if (condition.ConditionOrderPartiallyMatched != null)
            {
                writer.Write((FixTags)QuikFixTags.ConditionOrderPartiallyMatched);
                writer.Write(condition.ConditionOrderPartiallyMatched.Value);
            }

            if (condition.ConditionOrderUseMatchedBalance != null)
            {
                writer.Write((FixTags)QuikFixTags.ConditionOrderUseMatchedBalance);
                writer.Write(condition.ConditionOrderUseMatchedBalance.Value);
            }

            if (condition.LinkedOrderPrice != null)
            {
                writer.Write((FixTags)QuikFixTags.LinkedOrderPrice);
                writer.Write(condition.LinkedOrderPrice.Value);
            }

            if (condition.Offset != null)
            {
                writer.Write((FixTags)QuikFixTags.Offset);
                writer.Write(condition.Offset.ToString());
            }

            if (condition.Spread != null)
            {
                writer.Write((FixTags)QuikFixTags.StopSpread);
                writer.Write(condition.Spread.ToString());
            }

            if (condition.IsMarketTakeProfit != null)
            {
                writer.Write((FixTags)QuikFixTags.IsMarketTakeProfit);
                writer.Write(condition.IsMarketTakeProfit.Value);
            }
        }
Пример #6
0
 /// <summary>
 /// Записать данные по условию заявки.
 /// </summary>
 /// <param name="writer">Писатель FIX данных.</param>
 /// <param name="regMsg">Сообщение, содержащее информацию для регистрации заявки.</param>
 protected override void WriteOrderCondition(IFixWriter writer, OrderRegisterMessage regMsg)
 {
     writer.WriteOrderCondition((QuikOrderCondition)regMsg.Condition, TimeStampFormat);
 }
Пример #7
0
			protected override void WriterFixOrderCondition(IFixWriter writer, ExecutionMessage message)
			{
				writer.WriteOrderCondition((QuikOrderCondition)message.Condition, TransactionSession.DateTimeFormat);
			}
Пример #8
0
			protected override void WriterFixOrderCondition(IFixWriter writer, ExecutionMessage message)
			{
				writer.WriteOrderCondition((QuikOrderCondition)message.Condition);
			}
Пример #9
0
 protected override void WriterFixOrderCondition(IFixWriter writer, ExecutionMessage message)
 {
     writer.WriteOrderCondition((QuikOrderCondition)message.Condition);
 }
Пример #10
0
        /// <inheritdoc />
        protected override string OnWrite(IFixWriter writer, Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.OrderRegister:
            {
                var regMsg = (OrderRegisterMessage)message;

                switch (regMsg.OrderType)
                {
                case null:
                case OrderTypes.Limit:
                case OrderTypes.Market:
                case OrderTypes.Conditional:
                    break;

                default:
                    throw new NotSupportedException(LocalizedStrings.Str1601Params.Put(regMsg.OrderType, regMsg.TransactionId));
                }

                var securityId = regMsg.SecurityId;

                writer.Write(FixTags.ClOrdID);
                writer.Write(regMsg.TransactionId);

                writer.WriteHandlInst(regMsg);

                writer.Write(FixTags.Symbol);
                writer.Write(securityId.SecurityCode);

                writer.WriteSide(regMsg.Side);

                writer.WriteTransactTime(TimeStampParser);

                writer.Write(FixTags.OrderQty);
                writer.Write(regMsg.Volume);

                writer.Write(FixTags.OrdType);
                writer.Write(regMsg.GetFixType());

                if (regMsg.OrderType != OrderTypes.Market)
                {
                    writer.Write(FixTags.Price);
                    writer.Write(regMsg.Price);
                }

                var condition = (FixOrderCondition)regMsg.Condition;

                if (condition?.StopPrice != null)
                {
                    writer.Write(FixTags.StopPx);
                    writer.Write(condition.StopPrice.Value);
                }

                if (regMsg.Currency != null)
                {
                    writer.Write(FixTags.Currency);
                    writer.Write(regMsg.Currency.Value.To <string>());
                }

                var tif = regMsg.GetFixTimeInForce();

                writer.Write(FixTags.TimeInForce);
                writer.Write(tif);

                if (tif == FixTimeInForce.GoodTillDate)
                {
                    writer.WriteExpiryDate(regMsg, _expiryDateParser, TimeZone);
                }

                WriteAccount(writer, regMsg);

                if (!regMsg.ClientCode.IsEmpty())
                {
                    writer.Write(FixTags.NoPartyIDs);
                    writer.Write(1);

                    writer.Write(FixTags.PartyID);
                    writer.Write(regMsg.ClientCode);

                    writer.Write(FixTags.PartyIDSource);
                    writer.Write(PartyIDSource.Mic);

                    writer.Write(FixTags.PartyRole);
                    writer.Write((int)PartyRole.ClientId);
                }

                return(FixMessages.NewOrderSingle);
            }

            case MessageTypes.OrderCancel:
            {
                var cancelMsg  = (OrderCancelMessage)message;
                var securityId = cancelMsg.SecurityId;

                writer.Write(FixTags.ClOrdID);
                writer.Write(cancelMsg.TransactionId);

                if (cancelMsg.OriginalTransactionId != 0)
                {
                    writer.Write(FixTags.OrigClOrdID);
                    WriteClOrdId(writer, cancelMsg.OriginalTransactionId);
                }

                if (cancelMsg.OrderId != null)
                {
                    writer.Write(FixTags.OrderID);
                    writer.Write(cancelMsg.OrderId.Value);
                }

                writer.Write(FixTags.Symbol);
                writer.Write(securityId.SecurityCode);

                if (cancelMsg.Side != null)
                {
                    writer.WriteSide(cancelMsg.Side.Value);
                }

                if (cancelMsg.Volume != null)
                {
                    writer.Write(FixTags.OrderQty);
                    writer.Write(cancelMsg.Volume.Value);
                }

                writer.WriteTransactTime(TimeStampParser);

                return(FixMessages.OrderCancelRequest);
            }

            case MessageTypes.OrderReplace:
            {
                var replaceMsg = (OrderReplaceMessage)message;
                var securityId = replaceMsg.SecurityId;

                writer.Write(FixTags.ClOrdID);
                writer.Write(replaceMsg.TransactionId);

                if (replaceMsg.OriginalTransactionId != 0)
                {
                    writer.Write(FixTags.OrigClOrdID);
                    WriteClOrdId(writer, replaceMsg.OriginalTransactionId);
                }

                if (replaceMsg.OldOrderId != null)
                {
                    writer.Write(FixTags.OrderID);
                    writer.Write(replaceMsg.OldOrderId.Value);
                }

                writer.Write(FixTags.Symbol);
                writer.Write(securityId.SecurityCode);

                writer.WriteSide(replaceMsg.Side);

                writer.Write(FixTags.OrderQty);
                writer.Write(replaceMsg.Volume);

                writer.Write(FixTags.OrdType);
                writer.Write(replaceMsg.GetFixType());

                if (replaceMsg.OrderType != OrderTypes.Market)
                {
                    writer.Write(FixTags.Price);
                    writer.Write(replaceMsg.Price);
                }

                var condition = (FixOrderCondition)replaceMsg.Condition;

                if (condition?.StopPrice != null)
                {
                    writer.Write(FixTags.StopPx);
                    writer.Write(condition.StopPrice.Value);
                }

                var tif = replaceMsg.GetFixTimeInForce();

                writer.Write(FixTags.TimeInForce);
                writer.Write(tif);

                if (tif == FixTimeInForce.GoodTillDate)
                {
                    writer.WriteExpiryDate(replaceMsg, _expiryDateParser, TimeZone);
                }

                writer.WriteTransactTime(TimeStampParser);

                return(FixMessages.OrderCancelReplaceRequest);
            }

            case MessageTypes.OrderStatus:
            {
                var statusMsg = (OrderStatusMessage)message;

                if (statusMsg.OrderId != null || statusMsg.OriginalTransactionId != 0)
                {
                    if (statusMsg.OrderId != null)
                    {
                        writer.Write(FixTags.OrderID);
                        writer.Write(statusMsg.OrderId.Value);
                    }

                    if (statusMsg.OriginalTransactionId != 0)
                    {
                        writer.Write(FixTags.ClOrdID);
                        writer.Write(statusMsg.OriginalTransactionId);
                    }

                    return(FixMessages.OrderStatusRequest);
                }
                else
                {
                    if (statusMsg.TransactionId != 0)
                    {
                        writer.Write(FixTags.MassStatusReqID);
                        writer.Write(statusMsg.TransactionId);
                    }

                    writer.Write(FixTags.MassStatusReqType);
                    writer.Write((int)MassStatusReqType.StatusForAllOrders);

                    return(FixMessages.OrderMassStatusRequest);
                }
            }

            case MessageTypes.MarketData:
            {
                var mdMsg = (MarketDataMessage)message;

                if (!(mdMsg.DataType2 == DataType.Level1 || mdMsg.DataType2 == DataType.MarketDepth))
                {
                    return(null);
                }

                writer.Write(FixTags.QuoteReqID);
                writer.Write(mdMsg.TransactionId);

                writer.Write(CfhFixTags.QuoteRequestAction);
                writer.Write(mdMsg.IsSubscribe ? 0 : 1);

                return(FixMessages.QuoteRequest);
            }

            case MessageTypes.Portfolio:
            {
                var pfMsg = (PortfolioMessage)message;

                if (!pfMsg.IsSubscribe)
                {
                    return(null);
                }

                WriteAccount(writer, pfMsg);

                return(CfhFixMessages.AccountInfoRequest);
            }

            default:
                return(base.OnWrite(writer, message));
            }
        }
		/// <summary>
		/// Записать данные по условию заявки.
		/// </summary>
		/// <param name="writer">Писатель FIX данных.</param>
		/// <param name="regMsg">Сообщение, содержащее информацию для регистрации заявки.</param>
		protected override void WriteOrderCondition(IFixWriter writer, OrderRegisterMessage regMsg)
		{
			writer.WriteOrderCondition((QuikOrderCondition)regMsg.Condition, DateTimeFormat);
		}