public static ProtoMessage Deal_List_Req(long ctidTraderAccountId,
                                                 long fromTimestamp,
                                                 long toTimestamp,
                                                 int maxRows = 0)
        {
            ProtoOADealListReq message = new ProtoOADealListReq
            {
                payloadType         = ProtoOAPayloadType.ProtoOaDealListReq,
                ctidTraderAccountId = ctidTraderAccountId,
                fromTimestamp       = fromTimestamp,
                toTimestamp         = toTimestamp
            };

            if (maxRows > 0)
            {
                message.maxRows = maxRows;
            }

            Log.Info("ProtoOADealListReq:: " +
                     $"ctidTraderAccountId: {ctidTraderAccountId}; " +
                     $"fromTimestamp: {fromTimestamp} ({EpochToString(fromTimestamp)}; " +
                     $"toTimestamp: {toTimestamp} ({EpochToString(toTimestamp)}; " +
                     $"maxRows: {maxRows}");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
        public static ProtoMessage Get_Tickdata_Req(long ctidTraderAccountId,
                                                    long symbolId,
                                                    ProtoOAQuoteType quoteType,
                                                    long fromTimestamp,
                                                    long toTimestamp)
        {
            ProtoOAGetTickDataReq message = new ProtoOAGetTickDataReq
            {
                payloadType         = ProtoOAPayloadType.ProtoOaGetTickdataReq,
                ctidTraderAccountId = ctidTraderAccountId,
                symbolId            = symbolId,
                Type          = quoteType,
                fromTimestamp = fromTimestamp,
                toTimestamp   = toTimestamp
            };

            Log.Info("ProtoOAGetTickDataReq:: " +
                     $"ctidTraderAccountId: {ctidTraderAccountId}; " +
                     $"symbolId: {symbolId}; " +
                     $"quoteType: {quoteType}; " +
                     $"fromTimestamp: {fromTimestamp} ({EpochToString(fromTimestamp)}; " +
                     $"toTimestamp: {toTimestamp} ({EpochToString(toTimestamp)}");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
Ejemplo n.º 3
0
        public static ProtoMessage Get_Trendbars_Req(long ctidTraderAccountId,
                                                     long fromTimestamp,
                                                     long toTimestamp,
                                                     ProtoOATrendbarPeriod period,
                                                     long symbolId = 0)
        {
            ProtoOAGetTrendbarsReq message = new ProtoOAGetTrendbarsReq
            {
                payloadType         = ProtoOAPayloadType.ProtoOaGetTrendbarsReq,
                ctidTraderAccountId = ctidTraderAccountId,
                fromTimestamp       = fromTimestamp,
                toTimestamp         = toTimestamp,
                Period = period
            };

            if (symbolId > 0)
            {
                message.symbolId = symbolId;
            }

            Log.Info("ProtoOAGetTrendbarsReq:: " +
                     $"ctidTraderAccountId: {ctidTraderAccountId}; " +
                     $"fromTimestamp: {fromTimestamp} ({EpochToString(fromTimestamp)}; " +
                     $"toTimestamp: {toTimestamp} ({EpochToString(toTimestamp)}; " +
                     $"period: {period}");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
Ejemplo n.º 4
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()));
        }
        private static ProtoMessage Heartbeat()
        {
            ProtoHeartbeatEvent message = new ProtoHeartbeatEvent
            {
                payloadType = ProtoPayloadType.HeartbeatEvent
            };

            Log.Info("ProtoHeartbeatEventReq");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
        public static ProtoMessage Version_Req()
        {
            ProtoOAVersionReq message = new ProtoOAVersionReq
            {
                payloadType = ProtoOAPayloadType.ProtoOaVersionReq
            };

            Log.Info("ProtoOAVersionReq");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
Ejemplo n.º 7
0
        public static ProtoMessage Asset_Class_List_Req(long ctidTraderAccountId)
        {
            ProtoOAAssetClassListRes message = new ProtoOAAssetClassListRes
            {
                payloadType         = ProtoOAPayloadType.ProtoOaAssetClassListReq,
                ctidTraderAccountId = ctidTraderAccountId
            };

            Log.Info("ProtoOAAssetClassListRes:: " +
                     $"ctidTraderAccountId: {ctidTraderAccountId}");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
        public ProtoMessage Margin_Call_List_Req(long ctidTraderAccountId)
        {
            ProtoOAMarginCallListReq message = new ProtoOAMarginCallListReq
            {
                payloadType         = ProtoOAPayloadType.ProtoOaMarginCallListReq,
                ctidTraderAccountId = ctidTraderAccountId
            };

            Log.Info("ProtoOAMarginCallListReq:: " +
                     $"ctidTraderAccountId: {ctidTraderAccountId}");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
        public static ProtoMessage Refresh_Token_Req(string refreshToken)
        {
            ProtoOARefreshTokenReq message = new ProtoOARefreshTokenReq
            {
                payloadType  = ProtoOAPayloadType.ProtoOaRefreshTokenReq,
                refreshToken = refreshToken
            };

            Log.Info("ProtoOARefreshTokenReq:: " +
                     $"refreshToken: {refreshToken}");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
Ejemplo n.º 10
0
        public static ProtoMessage Account_Logout_Req(long ctidTraderAccountId)
        {
            ProtoOAAccountLogoutReq message = new ProtoOAAccountLogoutReq
            {
                payloadType         = ProtoOAPayloadType.ProtoOaAccountAuthReq,
                ctidTraderAccountId = ctidTraderAccountId
            };

            Log.Info("ProtoOAAccountLogoutReq:: " +
                     $"ctidTraderAccountId: {ctidTraderAccountId}");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
Ejemplo n.º 11
0
        public static ProtoMessage Get_Accounts_By_Access_Token_Req(string accessToken)
        {
            ProtoOAGetAccountListByAccessTokenReq message = new ProtoOAGetAccountListByAccessTokenReq
            {
                payloadType = ProtoOAPayloadType.ProtoOaGetAccountsByAccessTokenReq,
                accessToken = accessToken
            };

            Log.Info("ProtoOAGetAccountListByAccessTokenReq:: " +
                     $"accessToken: {accessToken}");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
        public static ProtoMessage Symbol_By_Id_Req(long ctidTraderAccountId, long[] symbolIDs)
        {
            ProtoOASymbolByIdReq message = new ProtoOASymbolByIdReq
            {
                payloadType         = ProtoOAPayloadType.ProtoOaSymbolByIdReq,
                ctidTraderAccountId = ctidTraderAccountId,
                symbolIds           = symbolIDs
            };

            Log.Info("ProtoOASymbolByIdReq:: " +
                     $"ctidTraderAccountId: {ctidTraderAccountId}; " +
                     $"symbolIds: [{string.Join("; ", symbolIDs)}]");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
Ejemplo n.º 13
0
        public static ProtoMessage Application_Auth_Req(string clientId,
                                                        string clientSecret)
        {
            ProtoOAApplicationAuthReq message = new ProtoOAApplicationAuthReq
            {
                payloadType  = ProtoOAPayloadType.ProtoOaApplicationAuthReq,
                clientId     = clientId,
                clientSecret = clientSecret
            };

            Log.Info("ProtoOAApplicationAuthReq:: " +
                     $"clientId: {clientId}; " +
                     $"clientSecret: {clientSecret}");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
        public static ProtoMessage Cancel_Order_Req(long ctidTraderAccountId,
                                                    long orderId)
        {
            ProtoOACancelOrderReq message = new ProtoOACancelOrderReq
            {
                payloadType         = ProtoOAPayloadType.ProtoOaCancelOrderReq,
                ctidTraderAccountId = ctidTraderAccountId,
                orderId             = orderId
            };

            Log.Info("ProtoOACancelOrderReq:: " +
                     $"ctidTraderAccountId: {ctidTraderAccountId}; " +
                     $"orderId: {orderId}");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
Ejemplo n.º 15
0
        public static ProtoMessage Symbols_For_Conversion_Req(long ctidTraderAccountId, long firstAssetId, long lastAssetId)
        {
            ProtoOASymbolsForConversionReq message = new ProtoOASymbolsForConversionReq
            {
                payloadType         = ProtoOAPayloadType.ProtoOaSymbolsForConversionReq,
                ctidTraderAccountId = ctidTraderAccountId,
                firstAssetId        = firstAssetId,
                lastAssetId         = lastAssetId
            };

            Log.Info("ProtoOASymbolsForConversionReq:: " +
                     $"ctidTraderAccountId: {ctidTraderAccountId}; " +
                     $"firstAssetId: {firstAssetId}; " +
                     $"lastAssetId: {lastAssetId}");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
Ejemplo n.º 16
0
        public static ProtoMessage Subscribe_Live_Trendbar_Req(long ctidTraderAccountId, ProtoOATrendbarPeriod period, long symbolId)
        {
            ProtoOASubscribeLiveTrendbarReq message = new ProtoOASubscribeLiveTrendbarReq
            {
                payloadType         = ProtoOAPayloadType.ProtoOaSubscribeLiveTrendbarReq,
                ctidTraderAccountId = ctidTraderAccountId,
                Period   = period,
                symbolId = symbolId
            };

            Log.Info("ProtoOASubscribeLiveTrendbarReq:: " +
                     $"ctidTraderAccountId: {ctidTraderAccountId}; " +
                     $"Period: {period}; " +
                     $"symbolId: {symbolId}");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
Ejemplo n.º 17
0
        public static ProtoMessage Expected_Margin_Req(long ctidTraderAccountId,
                                                       long symbolId,
                                                       long[] volumes)
        {
            ProtoOAExpectedMarginReq message = new ProtoOAExpectedMarginReq
            {
                payloadType         = ProtoOAPayloadType.ProtoOaExpectedMarginReq,
                ctidTraderAccountId = ctidTraderAccountId,
                symbolId            = symbolId,
                Volumes             = volumes
            };

            Log.Info("ProtoOAExpectedMarginReq:: " +
                     $"ctidTraderAccountId: {ctidTraderAccountId}; " +
                     $"symbolId: {symbolId}; " +
                     $"Volumes: [{string.Join("; ", volumes)}]");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
Ejemplo n.º 18
0
        public static ProtoMessage Cash_Flow_History_List_Req(long ctidTraderAccountId,
                                                              long fromTimestamp,
                                                              long toTimestamp)
        {
            ProtoOACashFlowHistoryListReq message = new ProtoOACashFlowHistoryListReq
            {
                payloadType         = ProtoOAPayloadType.ProtoOaCashFlowHistoryListReq,
                ctidTraderAccountId = ctidTraderAccountId,
                fromTimestamp       = fromTimestamp,
                toTimestamp         = toTimestamp
            };

            Log.Info("ProtoOACashFlowHistoryListReq:: " +
                     $"ctidTraderAccountId: {ctidTraderAccountId}; " +
                     $"fromTimestamp: {fromTimestamp} ({EpochToString(fromTimestamp)}; " +
                     $"toTimestamp: {toTimestamp} ({EpochToString(toTimestamp)}");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
        public static ProtoMessage Close_Position_Req(long ctidTraderAccountId,
                                                      long positionId,
                                                      long volume)
        {
            ProtoOAClosePositionReq message = new ProtoOAClosePositionReq
            {
                payloadType         = ProtoOAPayloadType.ProtoOaClosePositionReq,
                ctidTraderAccountId = ctidTraderAccountId,
                positionId          = positionId,
                Volume = volume
            };

            Log.Info("ProtoOAClosePositionReq:: " +
                     $"ctidTraderAccountId: {ctidTraderAccountId}; " +
                     $"positionId: {positionId}; " +
                     $"volume: {volume}");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
        public static ProtoMessage New_Order_Req(long ctidTraderAccountId,
                                                 long symbolId,
                                                 ProtoOAOrderType orderType,
                                                 ProtoOATradeSide tradeSide,
                                                 long volume,
                                                 double limitPrice = 0,
                                                 double stopPrice  = 0,
                                                 ProtoOATimeInForce timeInForce = ProtoOATimeInForce.GoodTillCancel,
                                                 long expirationTimestamp       = 0,
                                                 double stopLoss          = 0,
                                                 double takeProfit        = 0,
                                                 string comment           = "",
                                                 double baseSlippagePrice = 0,
                                                 int slippageInPoints     = 0,
                                                 string label             = "",
                                                 long positionId          = 0,
                                                 string clientOrderId     = "",
                                                 long relativeStopLoss    = 0,
                                                 long relativeTakeProfit  = 0,
                                                 bool guaranteedStopLoss  = false,
                                                 bool trailingStopLoss    = false,
                                                 ProtoOAOrderTriggerMethod stopTriggerMethod = ProtoOAOrderTriggerMethod.Trade)
        {
            ProtoOANewOrderReq message = new ProtoOANewOrderReq
            {
                payloadType         = ProtoOAPayloadType.ProtoOaNewOrderReq,
                ctidTraderAccountId = ctidTraderAccountId,
                symbolId            = symbolId,
                orderType           = orderType,
                tradeSide           = tradeSide,
                Volume = volume
            };

            if (limitPrice > 0)
            {
                message.limitPrice = limitPrice;
            }
            if (stopPrice > 0)
            {
                message.stopPrice = stopPrice;
            }
            if (timeInForce > 0)
            {
                message.timeInForce = timeInForce;
            }
            if (expirationTimestamp > 0)
            {
                message.expirationTimestamp = expirationTimestamp;
            }
            if (stopLoss > 0)
            {
                message.stopLoss = stopLoss;
            }
            if (takeProfit > 0)
            {
                message.takeProfit = takeProfit;
            }
            if (comment != "")
            {
                message.Comment = comment;
            }
            if (baseSlippagePrice > 0)
            {
                message.baseSlippagePrice = baseSlippagePrice;
            }
            if (slippageInPoints > 0)
            {
                message.slippageInPoints = slippageInPoints;
            }
            if (label != "")
            {
                message.Label = label;
            }
            if (positionId > 0)
            {
                message.positionId = positionId;
            }
            if (clientOrderId != "")
            {
                message.clientOrderId = clientOrderId;
            }
            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("ProtoOANewOrderReq:: " +
                     $"ctidTraderAccountId: {ctidTraderAccountId}; " +
                     $"symbolId: {symbolId}; " +
                     $"orderType: {orderType}; " +
                     $"tradeSide: {tradeSide}; " +
                     $"volume: {volume}; " +
                     $"limitPrice: {limitPrice}; " +
                     $"stopPrice: {stopPrice}; " +
                     $"timeInForce: {timeInForce}; " +
                     $"expirationTimestamp: {expirationTimestamp} ({EpochToString(expirationTimestamp)}; " +
                     $"stopLoss: {stopLoss}; " +
                     $"takeProfit: {takeProfit}; " +
                     $"comment: {comment}; " +
                     $"baseSlippagePrice: {baseSlippagePrice}; " +
                     $"slippageInPoints: {slippageInPoints}; " +
                     $"label: {label}; " +
                     $"positionId: {positionId}; " +
                     $"clientOrderId: {clientOrderId}; " +
                     $"relativeStopLoss: {relativeStopLoss}; " +
                     $"relativeTakeProfit: {relativeTakeProfit}; " +
                     $"guaranteedStopLoss: {guaranteedStopLoss}; " +
                     $"trailingStopLoss: {trailingStopLoss}; " +
                     $"stopTriggerMethod: {stopTriggerMethod}");

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

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
Ejemplo n.º 21
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()));
        }