예제 #1
0
        public void PlaceOrderTest(string orderId, HttpStatusCode httpStatus, Orders.OrderStatus status, decimal quantity, decimal price, OrderType orderType)
        {
            var response = new
            {
                id        = _brokerId,
                fill_fees = "0.11"
            };

            SetupResponse(JsonConvert.SerializeObject(response), httpStatus);

            bool?hasFilled = null;

            if (orderType == OrderType.Market && httpStatus == HttpStatusCode.OK)
            {
                hasFilled = false;
            }

            ManualResetEvent raised = new ManualResetEvent(false);

            _unit.OrderStatusChanged += (s, e) =>
            {
                if (orderType == OrderType.Market && e.Status == OrderStatus.Filled)
                {
                    hasFilled = true;
                    Assert.AreEqual(0.11, e.OrderFee);
                }
                else
                {
                    Assert.AreEqual(status, e.Status);
                    if (orderId != null)
                    {
                        Assert.AreEqual("BTCUSD", e.Symbol.Value);
                        Assert.That((quantity > 0 && e.Direction == Orders.OrderDirection.Buy) || (quantity < 0 && e.Direction == Orders.OrderDirection.Sell));
                        Assert.IsTrue(orderId == null || _unit.CachedOrderIDs.SelectMany(c => c.Value.BrokerId.Where(b => b == _brokerId)).Any());
                    }
                    raised.Set();
                }
            };

            Order order = null;

            if (orderType == OrderType.Limit)
            {
                order = new Orders.LimitOrder(_symbol, quantity, price, DateTime.UtcNow);
            }
            else if (orderType == OrderType.Market)
            {
                order = new Orders.MarketOrder(_symbol, quantity, DateTime.UtcNow);
            }
            else
            {
                order = new Orders.StopMarketOrder(_symbol, quantity, price, DateTime.UtcNow);
            }

            bool actual = _unit.PlaceOrder(order);

            Assert.IsTrue(actual || (orderId == null && !actual));
            Assert.IsTrue(hasFilled ?? true);
            Assert.IsTrue(raised.WaitOne(1000));
        }
        public static void AddOrder(GDAXBrokerage unit, int id, string brokerId, decimal quantity)
        {
            var order = new Orders.MarketOrder {
                BrokerId = new List <string> {
                    brokerId
                }, Quantity = quantity, Id = id
            };

            unit.CachedOrderIDs.TryAdd(1, order);
            unit.FillSplit.TryAdd(id, new GDAXFill(order));
        }
예제 #3
0
        public static void AddOrder(BitfinexBrokerage unit, int id, string brokerId, int quantity)
        {
            var order = new Orders.MarketOrder {
                BrokerId = new List <string> {
                    brokerId
                }, Quantity = quantity, Id = id, Symbol = GetSecurity().Symbol
            };

            unit.CachedOrderIDs.TryAdd(1, order);
            unit.FillSplit.TryAdd(id, new BitfinexFill(order));
        }
예제 #4
0
        public static void AddOrder(GDAXBrokerage unit, int id, string brokerId, decimal quantity)
        {
            var order = new Orders.MarketOrder {
                BrokerId = new List <string> {
                    brokerId
                }, Symbol = Btcusd, Quantity = quantity, Id = id
            };

            order.PriceCurrency = Currencies.USD;
            unit.CachedOrderIDs.TryAdd(1, order);
            unit.FillSplit.TryAdd(id, new GDAXFill(order));
        }