Ejemplo n.º 1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <see cref="Message"/>
        /// <param name="message">Source message.</param>
        public OrderCanceledData(Message message)
        {
            ClientId = DWConverter.FromProtoUuid(message.ClientId);

            OrderCanceledMessage orderCanceledMessage = message.OrderCanceledMsg.Clone();

            OrigClientId = DWConverter.FromProtoUuid(orderCanceledMessage.PrevClientId);
            TraderId     = message.TraderId;
            Symbol       = SymbolsContainer.GetSymbol(message.MarketId);
            MarkPrice    = DWConverter.FromProtoDecimal(orderCanceledMessage.MarkPrice);
            OrderIds     = new List <Guid>();
            foreach (ByteString orderId in orderCanceledMessage.OrderIds)
            {
                OrderIds.Add(DWConverter.FromProtoUuid(orderId));
            }
            OrderMargin       = DWConverter.FromProtoDecimal(orderCanceledMessage.OrderMargin);
            PositionMargin    = DWConverter.FromProtoDecimal(orderCanceledMessage.PositionMargin);
            Status            = orderCanceledMessage.Status;
            TraderBalance     = DWConverter.FromProtoDecimal(orderCanceledMessage.TraderBalance);
            TraderBalance2    = DWConverter.FromProtoDecimal(orderCanceledMessage.TraderBalance2);
            Upnl              = DWConverter.FromProtoDecimal(orderCanceledMessage.Upnl);
            BuyOrderMargin    = DWConverter.FromProtoDecimal(orderCanceledMessage.BuyOrderMargin);
            Pnl               = DWConverter.FromProtoDecimal(orderCanceledMessage.Pnl);
            SellOrderMargin   = DWConverter.FromProtoDecimal(orderCanceledMessage.SellOrderMargin);
            BuyOrderQuantity  = DWConverter.FromProtoDecimal(orderCanceledMessage.BuyOrderQuantity);
            SellOrderQuantity = DWConverter.FromProtoDecimal(orderCanceledMessage.SellOrderQuantity);
            AccumQuantity     = DWConverter.FromProtoDecimal(orderCanceledMessage.AccumQuantity);
            Orders            = new List <OrderBase>();
            foreach (OrderMessage order in orderCanceledMessage.Orders)
            {
                Orders.Add(order.OrderType == OrderType.Limit ? (OrderBase) new OrderLimit(order, Symbol) :
                           new OrderMarket(order, Symbol));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <see cref="Message"/>
        /// <param name="message">Source message.</param>
        public OrderStatusData(Message message)
        {
            OrderStatusMessage orderStatusMessage = message.OrderStatusMsg.Clone();

            TraderId       = message.TraderId;
            ClientId       = DWConverter.FromProtoUuid(message.ClientId);
            Symbol         = SymbolsContainer.GetSymbol(message.MarketId);
            Direction      = orderStatusMessage.Side;
            Status         = orderStatusMessage.Status;
            PositionMargin = DWConverter.FromProtoDecimal(orderStatusMessage.PositionMargin);
            OrderMargin    = DWConverter.FromProtoDecimal(orderStatusMessage.OrderMargin);
            TraderBalance  = DWConverter.FromProtoDecimal(orderStatusMessage.TraderBalance);
            TraderBalance2 = DWConverter.FromProtoDecimal(orderStatusMessage.TraderBalance2);
            MarkPrice      = DWConverter.FromProtoDecimal(orderStatusMessage.MarkPrice);
            PaidPrice      = DWConverter.FromProtoDecimal(orderStatusMessage.PaidPrice);
            Price          = DWConverter.FromProtoDecimal(orderStatusMessage.Price);
            Quantity       = DWConverter.FromProtoDecimal(orderStatusMessage.Quantity);
            //this.TakeProfitPrice = message.FromProtoDecimal(orderStatusMessage.TakeProfitPrice);
            Upnl           = DWConverter.FromProtoDecimal(orderStatusMessage.Upnl);
            BuyOrderMargin = DWConverter.FromProtoDecimal(orderStatusMessage.BuyOrderMargin);
            Duration       = orderStatusMessage.Duration;
            Leverage       = orderStatusMessage.Leverage;
            OldContractId  = orderStatusMessage.OldContractId;
            OrderClientId  = DWConverter.FromProtoUuid(orderStatusMessage.OrderClientId);
            if (orderStatusMessage.OrderTimestamp == 0)
            {
                OrderTimestamp = DWConverter.FromLongDateTime(message.Timestamp);
            }
            else
            {
                OrderTimestamp = DWConverter.FromLongDateTime(orderStatusMessage.OrderTimestamp);
            }
            OrderType       = orderStatusMessage.OrderType;
            PaidPrice       = DWConverter.FromProtoDecimal(orderStatusMessage.PaidPrice);
            SellOrderMargin = DWConverter.FromProtoDecimal(orderStatusMessage.SellOrderMargin);
            Side            = orderStatusMessage.Side;
            //this.TakeProfitType = orderStatusMessage.TakeProfitType;
            Pnl = DWConverter.FromProtoDecimal(orderStatusMessage.Pnl);
            BuyOrderQuantity  = DWConverter.FromProtoDecimal(orderStatusMessage.BuyOrderQuantity);
            SellOrderQuantity = DWConverter.FromProtoDecimal(orderStatusMessage.SellOrderQuantity);
            AccumQuantity     = DWConverter.FromProtoDecimal(orderStatusMessage.AccumQuantity);
            OpenTime          = DWConverter.FromLongDateTime(orderStatusMessage.OpenTime);
            OrigClientId      = DWConverter.FromProtoUuid(orderStatusMessage.OrigClientId);
            OrigQuantity      = DWConverter.FromProtoDecimal(orderStatusMessage.OrigQuantity);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="message">Original message. <see cref="TradeMessage"/></param>
 public Trade(TradeMessage message, Symbol symbol)
 {
     TradeTraderId    = message.TradeTraderId;
     TradeTimeStamp   = DWConverter.FromLongDateTime(message.TradeTimestamp);
     Position         = message.Position;
     Price            = DWConverter.FromProtoDecimal(message.Price);
     Quantity         = DWConverter.FromProtoDecimal(message.Quantity);
     PaidPrice        = DWConverter.FromProtoDecimal(message.PaidPrice);
     LiquidationPrice = DWConverter.FromProtoDecimal(message.LiquidationPrice);
     ExitPrice        = DWConverter.FromProtoDecimal(message.ExitPrice);
     Leverage         = message.Leverage;
     ContractId       = message.ContractId;
     OldContractId    = message.OldContractId;
     OldClientId      = DWConverter.FromProtoUuid(message.OldClientId);
     IsIncrease       = message.IsIncrease;
     IsLiquidation    = message.IsLiquidation;
     Symbol           = symbol;
 }
Ejemplo n.º 4
0
 protected OrderBase(OrderMessage message, Symbol symbol)
 {
     ClientId      = DWConverter.FromProtoUuid(message.OrderClientId);
     TimeStamp     = DWConverter.FromLongDateTime(message.OrderTimestamp);
     Type          = message.OrderType;
     Side          = message.Side;
     Leverage      = message.Leverage;
     Duration      = message.Duration;
     Price         = DWConverter.FromProtoDecimal(message.Price);
     Quantity      = DWConverter.FromProtoDecimal(message.Quantity);
     PaidPrice     = DWConverter.FromProtoDecimal(message.PaidPrice);
     status        = null;
     TargetSymbol  = symbol;
     ContractId    = message.ContractId;
     OldClientId   = DWConverter.FromProtoUuid(message.OldClientId);
     OpenTime      = DWConverter.FromLongDateTime(message.OpenTime);
     OrderTraderId = message.OrderTraderId;
     OrigClientId  = DWConverter.FromProtoUuid(message.OrigClientId);
     OrigQuantity  = DWConverter.FromProtoDecimal(message.OrigQuantity);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <see cref="Message"/>
        /// <param name="message">Source message.</param>
        public OrderFilledData(Message message)
        {
            OrderFilledMessage orderFilledMessage = message.OrderFilledMsg.Clone();

            TraderId          = message.TraderId;
            ClientId          = DWConverter.FromProtoUuid(message.ClientId);
            Symbol            = SymbolsContainer.GetSymbol(message.MarketId);
            Status            = orderFilledMessage.Status;
            AccumQuantity     = DWConverter.FromProtoDecimal(orderFilledMessage.AccumQuantity);
            BuyOrderQuantity  = DWConverter.FromProtoDecimal(orderFilledMessage.BuyOrderQuantity);
            SellOrderQuantity = DWConverter.FromProtoDecimal(orderFilledMessage.SellOrderQuantity);
            PositionType      = orderFilledMessage.PositionType;
            PositionMargin    = DWConverter.FromProtoDecimal(orderFilledMessage.PositionMargin);
            OrderMargin       = DWConverter.FromProtoDecimal(orderFilledMessage.OrderMargin);
            TraderBalance     = DWConverter.FromProtoDecimal(orderFilledMessage.TraderBalance);
            TraderBalance2    = DWConverter.FromProtoDecimal(orderFilledMessage.TraderBalance2);
            Pnl                       = DWConverter.FromProtoDecimal(orderFilledMessage.Pnl);
            Upnl                      = DWConverter.FromProtoDecimal(orderFilledMessage.Upnl);
            NewClientId               = Status == OrderStatus.Partial ? DWConverter.FromProtoUuid(orderFilledMessage.NewClientId) : Guid.Empty;
            BuyOrderMargin            = DWConverter.FromProtoDecimal(orderFilledMessage.BuyOrderMargin);
            DroppedQuantity           = DWConverter.FromProtoDecimal(orderFilledMessage.DroppedQuantity);
            Duration                  = orderFilledMessage.Duration;
            LastTradePrice            = DWConverter.FromProtoDecimal(orderFilledMessage.LastTradePrice);
            LastTradeQuantity         = DWConverter.FromProtoDecimal(orderFilledMessage.LastTradeQuantity);
            Leverage                  = orderFilledMessage.Leverage;
            MarkPrice                 = DWConverter.FromProtoDecimal(orderFilledMessage.MarkPrice);
            OrderType                 = orderFilledMessage.OrderType;
            PaidPrice                 = DWConverter.FromProtoDecimal(orderFilledMessage.PaidPrice);
            PositionBankruptcyVolume  = DWConverter.FromProtoDecimal(orderFilledMessage.PositionBankruptcyVolume);
            PositionContracts         = DWConverter.FromProtoDecimal(orderFilledMessage.PositionContracts);
            PositionLiquidationVolume = DWConverter.FromProtoDecimal(orderFilledMessage.PositionLiquidationVolume);
            PositionVolume            = DWConverter.FromProtoDecimal(orderFilledMessage.PositionVolume);
            Price                     = DWConverter.FromProtoDecimal(orderFilledMessage.Price);
            Quantity                  = DWConverter.FromProtoDecimal(orderFilledMessage.Quantity);

            RawTrades = new List <Trade>();
            foreach (TradeMessage trade in orderFilledMessage.RawTrades)
            {
                Trade rawTrade = new Trade(trade, SymbolsContainer.GetSymbol(message.MarketId));
                if (trade.TradeTimestamp == 0)
                {
                    rawTrade.TradeTimeStamp = DWConverter.FromLongDateTime(message.Timestamp);
                }
                RawTrades.Add(rawTrade);
            }
            SellOrderMargin = DWConverter.FromProtoDecimal(orderFilledMessage.SellOrderMargin);
            Side            = orderFilledMessage.Side;
            Trades          = new List <Trade>();
            foreach (TradeMessage trade in orderFilledMessage.Trades)
            {
                Trade tempTrade = new Trade(trade, SymbolsContainer.GetSymbol(message.MarketId));
                if (trade.TradeTimestamp == 0)
                {
                    tempTrade.TradeTimeStamp = DWConverter.FromLongDateTime(message.Timestamp);
                }
                Trades.Add(tempTrade);
            }
            OpenTime     = DWConverter.FromLongDateTime(orderFilledMessage.OpenTime);
            OrigClientId = DWConverter.FromProtoUuid(orderFilledMessage.OrigClientId);
            OrigQuantity = DWConverter.FromProtoDecimal(orderFilledMessage.OrigQuantity);
        }
Ejemplo n.º 6
0
        private void ReceiveMessage(byte[] ByteMessage)
        {
            Message message;

            try
            {
                message = Message.Parser.ParseFrom(ByteMessage);
                if (!dataMessages.Contains(message.KontentCase))
                {
                    logger.Debug($"Received {message.KontentCase}: {message}");
                }
                else
                {
                    logger.Trace($"Received {message.KontentCase}: {message}");
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, ByteMessage.ToString());
                return;
            }
            Guid clientId = DWConverter.FromProtoUuid(message.ClientId);

            if (message.ErrorCode != 0)
            {
                ErrorCodes code = (ErrorCodes)message.ErrorCode;
                ErrorEvent?.Invoke(clientId, code);
            }
            if (message.KontentCase == MessageType.OrderStatusMsg)
            {
                OrderStatusReceived(message);
            }
            else if (message.KontentCase == MessageType.OrderFilledMsg)
            {
                OrderFilledReceived(message);
            }
            else if (message.KontentCase == MessageType.TraderStatusMsg)
            {
                TraderStatusReceived(message);
            }
            else if (message.KontentCase == MessageType.TraderBalanceMsg)
            {
                TraderBalanceReceived(message);
            }
            else if (message.KontentCase == MessageType.FundingMsg)
            {
                FundingReceived(message);
            }
            else if (message.KontentCase == MessageType.OrderCanceledMsg)
            {
                OrderCanceledReceived(message);
            }
            else if (message.KontentCase == MessageType.OrderBookMsg)
            {
                OrderBookReceived(message);
            }
            else if (message.KontentCase == MessageType.OrderBookUpdatedMsg)
            {
                OrderBookUpdatedReceived(message);
            }
            else if (message.KontentCase == MessageType.ExchangeRateMsg)
            {
                ExchangeRateReceived(message);
            }
            else if (message.KontentCase == MessageType.MarketStateMsg)
            {
                MarketStateReceived(message);
            }
            else if (message.KontentCase == MessageType.MarketStateUpdateMsg)
            {
                MarketStateUpdateReceived(message);
            }
            else if (message.KontentCase == MessageType.LeverageMsg)
            {
                LeverageReceived(message);
            }
        }