public ProtoMessage CreateAmendPositionTakeProfitRequest(long accountId, string accessToken, long positionId, double takeProfitPrice, string clientMsgId = null)
        {
            var _msg = ProtoOAAmendPositionSLTPReq.CreateBuilder();

            _msg.SetCtidTraderAccountId(accountId);
            _msg.SetPositionId(positionId);
            _msg.SetTakeProfit(takeProfitPrice);
            return(CreateMessage((uint)_msg.PayloadType, _msg.Build().ToByteString(), clientMsgId));
        }
Пример #2
0
        public async Task ModifyPosition(MarketOrderModel oldOrder, MarketOrderModel newOrder, long accountId, bool isLive)
        {
            VerifyConnection();

            if (oldOrder.TradeData.TradeSide != newOrder.TradeSide)
            {
                await ClosePosition(oldOrder.Id, oldOrder.Volume, accountId, isLive);

                newOrder.Id = default;

                await CreateNewOrder(newOrder, accountId, isLive);
            }
            else
            {
                if (newOrder.Volume > oldOrder.Volume)
                {
                    newOrder.Volume = newOrder.Volume - oldOrder.Volume;

                    await CreateNewOrder(newOrder, accountId, isLive);
                }
                else
                {
                    if (newOrder.StopLossInPips != oldOrder.StopLossInPips || newOrder.TakeProfitInPips != oldOrder.TakeProfitInPips)
                    {
                        var amendPositionRequestMessage = new ProtoOAAmendPositionSLTPReq
                        {
                            PositionId          = oldOrder.Id,
                            CtidTraderAccountId = accountId,
                            GuaranteedStopLoss  = oldOrder.GuaranteedStopLoss,
                        };

                        if (newOrder.IsStopLossEnabled)
                        {
                            amendPositionRequestMessage.StopLoss = newOrder.StopLossInPrice;
                            amendPositionRequestMessage.StopLossTriggerMethod = oldOrder.StopTriggerMethod;
                            amendPositionRequestMessage.TrailingStopLoss      = newOrder.IsTrailingStopLossEnabled;
                        }

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

                        var client = GetClient(isLive);

                        await client.SendMessage(amendPositionRequestMessage, ProtoOAPayloadType.ProtoOaAmendPositionSltpReq);
                    }

                    if (newOrder.Volume < oldOrder.Volume)
                    {
                        await ClosePosition(oldOrder.Id, oldOrder.Volume - newOrder.Volume, accountId, isLive);
                    }
                }
            }
        }
Пример #3
0
        public static ProtoMessage Amend_Position_SLTP_Req(long ctidTraderAccountId,
                                                           long positionId,
                                                           double stopLoss         = 0,
                                                           double takeProfit       = 0,
                                                           bool guaranteedStopLoss = false,
                                                           bool trailingStopLoss   = false,
                                                           ProtoOAOrderTriggerMethod stopLossTriggerMethod = ProtoOAOrderTriggerMethod.Trade)
        {
            ProtoOAAmendPositionSLTPReq message = new ProtoOAAmendPositionSLTPReq
            {
                payloadType         = ProtoOAPayloadType.ProtoOaAmendPositionSltpReq,
                ctidTraderAccountId = ctidTraderAccountId,
                positionId          = positionId
            };

            if (stopLoss > 0)
            {
                message.stopLoss = stopLoss;
            }
            if (takeProfit > 0)
            {
                message.takeProfit = takeProfit;
            }
            if (guaranteedStopLoss)
            {
                message.guaranteedStopLoss = true;
            }
            if (trailingStopLoss)
            {
                message.trailingStopLoss = true;
            }
            if (stopLossTriggerMethod != ProtoOAOrderTriggerMethod.Trade)
            {
                message.stopLossTriggerMethod = stopLossTriggerMethod;
            }

            Log.Info("ProtoOAAmendPositionSLTPReq:: " +
                     $"ctidTraderAccountId: {ctidTraderAccountId}; " +
                     $"positionId: {positionId}; " +
                     $"stopLoss: {stopLoss}; " +
                     $"takeProfit: {takeProfit}; " +
                     $"guaranteedStopLoss: {guaranteedStopLoss}; " +
                     $"trailingStopLoss: {trailingStopLoss}; " +
                     $"stopLossTriggerMethod: {stopLossTriggerMethod}");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
 public ProtoOAAmendPositionSLTPReq GetAmendPositionStopLossTakeProfitRequest(byte[] msg = null)
 {
     return(ProtoOAAmendPositionSLTPReq.CreateBuilder().MergeFrom(GetPayload(msg)).Build());
 }