public ProtoMessage CreateAmendStopOrderRequest(long accountId, string accessToken, long orderId, double stopPrice, string clientMsgId = null)
        {
            var _msg = ProtoOAAmendOrderReq.CreateBuilder();

            _msg.SetCtidTraderAccountId(accountId);
            _msg.SetOrderId(orderId);
            _msg.SetStopPrice(stopPrice);
            return(CreateMessage((uint)_msg.PayloadType, _msg.Build().ToByteString(), clientMsgId));
        }
        public ProtoMessage CreateAmendStopOrderRequest(long accountId, string accessToken, long orderId, double stopPrice, string clientMsgId = null)
        {
            var _msg = new ProtoOAAmendOrderReq();

            _msg.accountId   = accountId;
            _msg.accessToken = accessToken;
            _msg.orderId     = orderId;
            _msg.stopPrice   = stopPrice;
            return(CreateMessage((uint)_msg.payloadType, Utils.Serialize <ProtoOAAmendOrderReq>(_msg), clientMsgId));
        }
        public ProtoMessage CreateAmendLimitOrderRequest(long accountId, string accessToken, long orderId, double limitPrice, string clientMsgId = null)
        {
            var _msg = ProtoOAAmendOrderReq.CreateBuilder();

            _msg.SetAccountId(accountId);
            _msg.SetAccessToken(accessToken);
            _msg.SetOrderId(orderId);
            _msg.SetLimitPrice(limitPrice);
            _msg.SetTakeProfitPrice(limitPrice + 0.02);
            return(CreateMessage((uint)_msg.PayloadType, _msg.Build().ToByteString(), clientMsgId));
        }
Beispiel #4
0
        public async Task ModifyOrder(PendingOrderModel oldOrder, PendingOrderModel newOrder, long accountId, bool isLive)
        {
            VerifyConnection();

            var requestMessage = new ProtoOAAmendOrderReq
            {
                OrderId             = oldOrder.Id,
                CtidTraderAccountId = accountId,
                Volume = newOrder.Volume,
            };

            if (newOrder.IsStopLossEnabled)
            {
                requestMessage.StopLoss         = newOrder.StopLossInPrice;
                requestMessage.TrailingStopLoss = newOrder.IsTrailingStopLossEnabled;
            }

            if (newOrder.IsTakeProfitEnabled)
            {
                requestMessage.TakeProfit = newOrder.TakeProfitInPrice;
            }

            if (newOrder.IsExpiryEnabled)
            {
                requestMessage.ExpirationTimestamp = new DateTimeOffset(newOrder.ExpiryTime).ToUnixTimeMilliseconds();
            }

            if (newOrder.Type == PendingOrderType.Limit)
            {
                requestMessage.LimitPrice = newOrder.Price;
            }
            else
            {
                requestMessage.StopPrice = newOrder.Price;

                if (newOrder.Type == PendingOrderType.StopLimit)
                {
                    var slippageinPoint = newOrder.Symbol.Data.GetPointsFromPips(newOrder.LimitRangeInPips);

                    if (slippageinPoint < int.MaxValue)
                    {
                        requestMessage.SlippageInPoints = (int)slippageinPoint;
                    }
                }
            }

            var client = GetClient(isLive);

            await client.SendMessage(requestMessage, ProtoOAPayloadType.ProtoOaAmendOrderReq);
        }
Beispiel #5
0
        public ProtoMessage CreateAmendLimitOrderRequest(long accountId, string accessToken, long orderId, double limitPrice, double takeProfit = 0, double stopLoss = 0, string clientMsgId = null)
        {
            var _msg = ProtoOAAmendOrderReq.CreateBuilder();

            _msg.SetCtidTraderAccountId(accountId);
            _msg.SetOrderId(orderId);
            _msg.SetLimitPrice(limitPrice);
            if (takeProfit > 0)
            {
                _msg.SetTakeProfit(takeProfit);
            }
            if (stopLoss > 0)
            {
                _msg.SetStopLoss(stopLoss);
            }
            return(CreateMessage((uint)_msg.PayloadType, _msg.Build().ToByteString(), clientMsgId));
        }
 public ProtoOAAmendOrderReq GetAmendOrderRequest(byte[] msg = null)
 {
     return(ProtoOAAmendOrderReq.CreateBuilder().MergeFrom(GetPayload(msg)).Build());
 }
Beispiel #7
0
        public static ProtoMessage Amend_Order_Req(long ctidTraderAccountId,
                                                   long orderId,
                                                   long volume              = 0,
                                                   double limitPrice        = 0,
                                                   double stopPrice         = 0,
                                                   long expirationTimestamp = 0,
                                                   double stopLoss          = 0,
                                                   double takeProfit        = 0,
                                                   int slippageInPoints     = 0,
                                                   long relativeStopLoss    = 0,
                                                   long relativeTakeProfit  = 0,
                                                   bool guaranteedStopLoss  = false,
                                                   bool trailingStopLoss    = false,
                                                   ProtoOAOrderTriggerMethod stopTriggerMethod = ProtoOAOrderTriggerMethod.Trade)
        {
            ProtoOAAmendOrderReq message = new ProtoOAAmendOrderReq
            {
                payloadType         = ProtoOAPayloadType.ProtoOaAmendOrderReq,
                ctidTraderAccountId = ctidTraderAccountId,
                orderId             = orderId
            };

            if (volume > 0)
            {
                message.Volume = volume;
            }
            if (limitPrice > 0)
            {
                message.limitPrice = limitPrice;
            }
            if (stopPrice > 0)
            {
                message.stopPrice = stopPrice;
            }
            if (expirationTimestamp > 0)
            {
                message.expirationTimestamp = expirationTimestamp;
            }
            if (stopLoss > 0)
            {
                message.stopLoss = stopLoss;
            }
            if (takeProfit > 0)
            {
                message.takeProfit = takeProfit;
            }
            if (slippageInPoints > 0)
            {
                message.slippageInPoints = slippageInPoints;
            }
            if (relativeStopLoss > 0)
            {
                message.relativeStopLoss = relativeStopLoss;
            }
            if (relativeTakeProfit > 0)
            {
                message.relativeTakeProfit = relativeTakeProfit;
            }
            if (guaranteedStopLoss)
            {
                message.guaranteedStopLoss = true;
            }
            if (trailingStopLoss)
            {
                message.trailingStopLoss = true;
            }
            if (stopTriggerMethod != ProtoOAOrderTriggerMethod.Trade)
            {
                message.stopTriggerMethod = stopTriggerMethod;
            }

            Log.Info("ProtoOAAmendOrderReq:: " +
                     $"ctidTraderAccountId: {ctidTraderAccountId}; " +
                     $"volume: {volume}; " +
                     $"limitPrice: {limitPrice}; " +
                     $"stopPrice: {stopPrice}; " +
                     $"expirationTimestamp: {expirationTimestamp} ({EpochToString(expirationTimestamp)}; " +
                     $"stopLoss: {stopLoss}; " +
                     $"takeProfit: {takeProfit}; " +
                     $"slippageInPoints: {slippageInPoints}; " +
                     $"relativeStopLoss: {relativeStopLoss}; " +
                     $"relativeTakeProfit: {relativeTakeProfit}; " +
                     $"guaranteedStopLoss: {guaranteedStopLoss}; " +
                     $"trailingStopLoss: {trailingStopLoss}; " +
                     $"stopTriggerMethod: {stopTriggerMethod}");

            InnerMemoryStream.SetLength(0);
            Serializer.Serialize(InnerMemoryStream, message);

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }