public SimpleOrder(IDxOrder dxo)
 {
     index = dxo.Index;
     side  = dxo.Side == com.dxfeed.api.data.Side.Buy ? Side.Buy : Side.Sell;
     price = dxo.Price;
     size  = dxo.Size;
 }
Exemplo n.º 2
0
        /// <summary>
        ///     Creates Order event from another object.
        /// </summary>
        /// <param name="order">Other Order object.</param>
        internal PlayedOrder(IDxOrder order)
        {
            this.EventSymbol  = order.EventSymbol;
            this.EventFlags   = order.EventFlags;
            this.Index        = order.Index;
            this.Time         = order.Time;
            this.TimeNanoPart = order.TimeNanoPart;
            this.Sequence     = order.Sequence;
            Action            = order.Action;
            ActionTime        = order.ActionTime;
            OrderId           = order.OrderId;
            AuxOrderId        = order.AuxOrderId;
            this.Price        = order.Price;
            this.Size         = order.Size;
            this.Count        = order.Count;
            TradeId           = order.TradeId;
            TradePrice        = order.TradePrice;
            TradeSize         = order.TradeSize;
            this.Scope        = order.Scope;
            this.Side         = order.Side;
            this.ExchangeCode = order.ExchangeCode;
            this.Source       = order.Source;
            this.MarketMaker  = order.MarketMaker;

            marketMakerCharArray = MarketMaker.ToString().ToCharArray();
            IntPtr marketMakerCharsPtr = Marshal.UnsafeAddrOfPinnedArrayElement(marketMakerCharArray, 0);

            Params = new EventParams(EventFlags, (ulong)Index, 0);
            Data   = new DxTestOrder(EventFlags, Index, Tools.DateToUnixTime(Time), TimeNanoPart, Sequence, Price, (int)Size, Count, Scope, Side, ExchangeCode, Source, marketMakerCharsPtr);
        }
Exemplo n.º 3
0
 private static IDxOrder ZeroOrder(IDxOrder order)
 {
     return(new NativeOrder(order)
     {
         Size = 0,
         Price = double.NaN,
         Time = TimeConverter.ToUtcDateTime(0),
         Sequence = 0,
         ExchangeCode = '\0',
         Count = 0
     });
 }
Exemplo n.º 4
0
 internal static void CompareOrders(IDxOrder playedOrder, IDxOrder receivedOrder)
 {
     Assert.AreEqual(playedOrder.EventSymbol, receivedOrder.EventSymbol);
     Assert.AreEqual(playedOrder.Count, receivedOrder.Count);
     Assert.AreEqual(playedOrder.EventFlags, receivedOrder.EventFlags);
     Assert.AreEqual(playedOrder.ExchangeCode, receivedOrder.ExchangeCode);
     Assert.AreEqual(playedOrder.Index, receivedOrder.Index);
     Assert.AreEqual(playedOrder.Side, receivedOrder.Side);
     Assert.AreEqual(playedOrder.Price, receivedOrder.Price);
     Assert.AreEqual(playedOrder.Scope, receivedOrder.Scope);
     Assert.AreEqual(playedOrder.Sequence, receivedOrder.Sequence);
     Assert.AreEqual(playedOrder.Size, receivedOrder.Size);
     Assert.AreEqual(playedOrder.Source, receivedOrder.Source);
     Assert.AreEqual(playedOrder.Time, receivedOrder.Time);
     Assert.AreEqual(playedOrder.TimeNanoPart, receivedOrder.TimeNanoPart);
     Assert.AreEqual(playedOrder.MarketMaker.ToString(), receivedOrder.MarketMaker.ToString());
 }
Exemplo n.º 5
0
        public void CreateSubscriptionTest()
        {
            var symbol = "SYMA";
            var s      = DXEndpoint.Create().Feed.CreateSubscription <IDxOrder>();

            s.AddSymbols(symbol);
            TestListener eventListener = new TestListener();

            s.AddEventListener(eventListener);

            var playedOrder = new PlayedOrder(symbol, 0, 0x4e54560000000006, 0, 0, 0, 0, 100, 25, Scope.Order, Side.Buy, 'A', OrderSource.NTV, "AAAA");

            EventPlayer <IDxOrder> eventPlayer = new EventPlayer <IDxOrder>(s as DXFeedSubscription <IDxOrder>);

            eventPlayer.PlayEvents(symbol, playedOrder);
            Assert.AreEqual(eventListener.GetEventCount <IDxOrder>(symbol), 1);

            IDxOrder receivedOrder = eventListener.GetLastEvent <IDxOrder>().Event;

            Assert.AreEqual(symbol, receivedOrder.EventSymbol);
            CompareOrders(playedOrder, receivedOrder);

            //try to create subscription on closed endpoint
            DXEndpoint.GetInstance().Close();
            Assert.Catch(typeof(InvalidOperationException), () =>
            {
                DXFeed.GetInstance().CreateSubscription <IDxOrder>();
            });

            //thread-safety case
            DXEndpoint.Create();
            Parallel.For(ParallelFrom, ParallelTo, i =>
            {
                Assert.DoesNotThrow(() =>
                {
                    DXFeed.GetInstance().CreateSubscription <IDxOrder>();
                });
            });
        }
Exemplo n.º 6
0
        public void WaitOrders(params string[] sources)
        {
            List <string> sourceList = new List <string>(sources);
            DateTime      time       = DateTime.Now;
            int           lastIndex  = 0;

            while (true)
            {
                if (IsConnected != null)
                {
                    Assert.IsTrue(IsConnected(), "Connection was lost");
                }
                if (DateTime.Now.Subtract(time).TotalMilliseconds >= eventsTimeout)
                {
                    Assert.Fail("Timeout elapsed! Not received events for next symbols: " + String.Join(", ", sourceList.ToArray()));
                }

                List <ReceivedEvent <IDxOrder> > list = GetList <IDxOrder>();
                rwl.AcquireReaderLock(lockTimeout);
                int size = GetEventCount <IDxOrder>();
                for (int i = lastIndex; i < size; i++)
                {
                    IDxOrder order = list[i].Event;
                    if (sourceList.Contains(order.Source.Name))
                    {
                        sourceList.Remove(order.Source.Name);
                    }
                }
                lastIndex = size;
                rwl.ReleaseReaderLock();

                if (sourceList.Count == 0)
                {
                    break;
                }

                Thread.Sleep(eventsSleepTime);
            }
        }
Exemplo n.º 7
0
 private static bool IsZeroOrder(IDxOrder order)
 {
     return(TimeConverter.ToUnixTime(order.Time) == 0 && double.IsNaN(order.Price) && order.Size == 0);
 }
Exemplo n.º 8
0
 internal NativeOrder(IDxOrder order) : base(order)
 {
     MarketMaker = order.MarketMaker;
 }