public static OpenPositionContract ConvertToContract(this Position position, IOrderReader orderReader)
        {
            var relatedOrders = new List <RelatedOrderInfoContract>();

            foreach (var relatedOrderInfo in position.RelatedOrders)
            {
                if (orderReader.TryGetOrderById(relatedOrderInfo.Id, out var relatedOrder))
                {
                    relatedOrders.Add(new RelatedOrderInfoContract
                    {
                        Id                = relatedOrder.Id,
                        Price             = relatedOrder.Price ?? 0,
                        Type              = relatedOrder.OrderType.ToType <OrderTypeContract>(),
                        Status            = relatedOrder.Status.ToType <OrderStatusContract>(),
                        ModifiedTimestamp = relatedOrder.LastModified,
                        TrailingDistance  = relatedOrder.TrailingDistance
                    });
                }
            }

            return(new OpenPositionContract
            {
                AccountId = position.AccountId,
                AssetPairId = position.AssetPairId,
                CurrentVolume = position.Volume,
                Direction = position.Direction.ToType <PositionDirectionContract>(),
                Id = position.Id,
                OpenPrice = position.OpenPrice,
                OpenFxPrice = position.OpenFxPrice,
                ClosePrice = position.ClosePrice,
                ExpectedOpenPrice = position.ExpectedOpenPrice,
                OpenTradeId = position.OpenTradeId,
                OpenOrderType = position.OpenOrderType.ToType <OrderTypeContract>(),
                OpenOrderVolume = position.OpenOrderVolume,
                PnL = position.GetFpl(),
                UnrealizedPnl = position.GetUnrealisedFpl(),
                ChargedPnl = position.ChargedPnL,
                Margin = position.GetMarginMaintenance(),
                FxRate = position.CloseFxPrice,
                FxAssetPairId = position.FxAssetPairId,
                FxToAssetPairDirection = position.FxToAssetPairDirection.ToType <FxToAssetPairDirectionContract>(),
                RelatedOrders = position.RelatedOrders.Select(o => o.Id).ToList(),
                RelatedOrderInfos = relatedOrders,
                OpenTimestamp = position.OpenDate,
                ModifiedTimestamp = position.LastModified,
                TradeId = position.Id,
                AdditionalInfo = position.AdditionalInfo,
                Status = position.Status.ToType <PositionStatusContract>(),
                ForceOpen = position.ForceOpen,
                TradingConditionId = position.TradingConditionId,
                SwapTotal = position.SwapTotal
            });
        }
        public static OrderContract ConvertToContract(this Order order, IOrderReader orderReader)
        {
            var relatedOrders = new List <Order>();

            foreach (var relatedOrderInfo in order.RelatedOrders)
            {
                if (orderReader.TryGetOrderById(relatedOrderInfo.Id, out var relatedOrder))
                {
                    relatedOrders.Add(relatedOrder);
                }
            }

            return(order.ConvertToContract(relatedOrders));
        }
Exemple #3
0
        public Task OrderHistory(Order order, OrderUpdateType orderUpdateType, string activitiesMetadata = null)
        {
            var relatedOrders = new List <Order>();

            foreach (var relatedOrderInfo in order.RelatedOrders)
            {
                if (_orderReader.TryGetOrderById(relatedOrderInfo.Id, out var relatedOrder))
                {
                    relatedOrders.Add(relatedOrder);
                }
            }

            var historyEvent = new OrderHistoryEvent
            {
                OrderSnapshot      = order.ConvertToContract(relatedOrders),
                Timestamp          = _dateService.Now(),
                Type               = orderUpdateType.ToType <OrderHistoryTypeContract>(),
                ActivitiesMetadata = activitiesMetadata
            };

            return(TryProduceMessageAsync(_settings.RabbitMqQueues.OrderHistory.ExchangeName, historyEvent));
        }