Beispiel #1
0
        private void GetTradeOrderStatus(IOrderLimitProvider provider, string remoteOrderId, AssetPair market = null)
        {
            try
            {
                var context = new RemoteIdContext(UserContext.Current, remoteOrderId);

                if (market != null)
                {
                    context.Market = market;
                }

                var r = AsyncContext.Run(() => provider.GetOrderStatusAsync(context));

                Assert.IsTrue(remoteOrderId.Equals(r.RemoteOrderId, StringComparison.Ordinal), "Remote trade order ids don't match");
                Trace.WriteLine($"Remote trade order id: {r.RemoteOrderId}");

                if (r.IsOpen)
                {
                    Trace.WriteLine("Order is open");
                }
                if (r.IsCancelRequested)
                {
                    Trace.WriteLine("Order is requested to be canceled");
                }
                if (r.IsCanceled)
                {
                    Trace.WriteLine("Order is canceled");
                }
                if (r.IsClosed)
                {
                    Trace.WriteLine("Order is closed");
                }
                if (r.IsFound)
                {
                    Trace.WriteLine("Order is found");
                }

                if (r.Rate.HasValue)
                {
                    Trace.WriteLine($"The rate of order is {r.Rate.Value}");
                }
                if (r.AmountInitial.HasValue)
                {
                    Trace.WriteLine($"Initial amount is {r.AmountInitial.Value}");
                }
                if (r.AmountFilled.HasValue)
                {
                    Trace.WriteLine($"Filled amount is {r.AmountFilled.Value}");
                }
                if (r.AmountRemaining.HasValue)
                {
                    Trace.WriteLine($"Remaining amount is {r.AmountRemaining.Value}");
                }
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }
        }
Beispiel #2
0
        private void PlaceOrderLimitTest(IOrderLimitProvider provider, AssetPair market, bool isBuy, Money quantity, Money rate)
        {
            var context = new PlaceOrderLimitContext(UserContext.Testing, market, isBuy, quantity, rate);

            var r = AsyncContext.Run(() => provider.PlaceOrderLimitAsync(context));

            Assert.True(!String.IsNullOrWhiteSpace(r.RemoteOrderGroupId), "Remote id is empty.");
            OutputWriter.WriteLine($"Remote trade order id: {r.RemoteOrderGroupId}");
        }
Beispiel #3
0
        private void PlaceOrderLimit(IOrderLimitProvider provider, AssetPair market, bool isBuy, decimal quantity, Money rate)
        {
            var context = new PlaceOrderLimitContext(UserContext.Current, market, isBuy, quantity, rate);

            var r = AsyncContext.Run(() => provider.PlaceOrderLimitAsync(context));

            Assert.IsTrue(!String.IsNullOrWhiteSpace(r.RemoteOrderGroupId));
            Trace.WriteLine($"Remote trade order id: {r.RemoteOrderGroupId}");
        }
Beispiel #4
0
        private void GetTradeOrderStatusTest(IOrderLimitProvider provider, string remoteOrderId, AssetPair market = null)
        {
            var context = new RemoteMarketIdContext(UserContext.Testing, remoteOrderId, market);

            var r = AsyncContext.Run(() => provider.GetOrderStatusAsync(context)).TradeOrderStatus;

            Assert.True(remoteOrderId.Equals(r.RemoteOrderId, StringComparison.Ordinal), "Remote trade order ids don't match");

            DisplayOrderStatusInfo(r, market);
        }
Beispiel #5
0
        private void GetMarketFromOrderTest(IOrderLimitProvider provider, string remoteOrderId)
        {
            var context = new RemoteIdContext(UserContext.Testing, remoteOrderId);

            var r = AsyncContext.Run(() => provider.GetMarketFromOrderAsync(context));

            OutputWriter.WriteLine($"Remote trade order id is {remoteOrderId}, market is {r.Market}");

            Assert.True(r.Market != null, "Returned market is null");
            Assert.True(!Equals(r.Market, AssetPair.Empty), "Returned market is AssetPair.Empty");
        }
Beispiel #6
0
        private void GetOrdersHistoryTest(IOrderLimitProvider provider, AssetPair market = null)
        {
            var context = new TradeOrdersContext(UserContext.Testing)
            {
                Market = market
            };

            OutputWriter.WriteLine("Orders history: \n");

            var orders = AsyncContext.Run(() => provider.GetOrdersHistory(context)).Orders.ToArray();

            if (orders.Length == 0)
            {
                OutputWriter.WriteLine("No trade orders returned");
            }
            else
            {
                orders.ForEach(DisplayOrderStatusInfo);
            }
        }
 protected TradeStrategyBase(TradeStrategyContext context)
 {
     Context  = context;
     Id       = ObjectId.NewObjectId();
     Provider = Context.Network.Providers.Where(x => x.IsDirect).FirstProviderOf <IOrderLimitProvider>();
 }